cargo/tests/publish.rs

497 lines
14 KiB
Rust
Raw Normal View History

extern crate cargotest;
extern crate flate2;
extern crate hamcrest;
extern crate tar;
use std::io::prelude::*;
use std::fs::File;
use std::io::SeekFrom;
2014-09-09 14:23:09 +00:00
use cargotest::support::git::repo;
use cargotest::support::paths;
use cargotest::support::{project, execs, publish};
use flate2::read::GzDecoder;
use hamcrest::assert_that;
2014-09-09 14:23:09 +00:00
use tar::Archive;
#[test]
fn simple() {
publish::setup();
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
"#)
.file("src/main.rs", "fn main() {}");
assert_that(p.cargo_process("publish").arg("--no-verify")
.arg("--index").arg(publish::registry().to_string()),
execs().with_status(0).with_stderr(&format!("\
[UPDATING] registry `{reg}`
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ({dir})
[UPLOADING] foo v0.0.1 ({dir})
",
dir = p.url(),
reg = publish::registry())));
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = ((sz[0] as u32) << 0) |
((sz[1] as u32) << 8) |
((sz[2] as u32) << 16) |
((sz[3] as u32) << 24);
f.seek(SeekFrom::Current(sz as i64 + 4)).unwrap();
// Verify the tarball
let mut rdr = GzDecoder::new(f).unwrap();
2017-09-24 14:26:37 +00:00
assert_eq!(rdr.header().filename().unwrap(), b"foo-0.0.1.crate");
let mut contents = Vec::new();
rdr.read_to_end(&mut contents).unwrap();
let mut ar = Archive::new(&contents[..]);
for file in ar.entries().unwrap() {
let file = file.unwrap();
let fname = file.header().path_bytes();
let fname = &*fname;
assert!(fname == b"foo-0.0.1/Cargo.toml" ||
fname == b"foo-0.0.1/Cargo.toml.orig" ||
fname == b"foo-0.0.1/src/main.rs",
"unexpected filename: {:?}", file.header().path());
}
}
// TODO: Deprecated
// remove once it has been decided --host can be removed
#[test]
fn simple_with_host() {
publish::setup();
2014-09-09 14:23:09 +00:00
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
2014-09-09 14:23:09 +00:00
"#)
.file("src/main.rs", "fn main() {}");
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
assert_that(p.cargo_process("publish").arg("--no-verify")
.arg("--host").arg(publish::registry().to_string()),
2016-05-14 21:44:18 +00:00
execs().with_status(0).with_stderr(&format!("\
[WARNING] The flag '--host' is no longer valid.
Previous versions of Cargo accepted this flag, but it is being
deprecated. The flag is being renamed to 'index', as the flag
wants the location of the index to which to publish. Please
use '--index' instead.
This will soon become a hard error, so it's either recommended
to update to a fixed version or contact the upstream maintainer
about this warning.
[UPDATING] registry `{reg}`
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ({dir})
[UPLOADING] foo v0.0.1 ({dir})
",
dir = p.url(),
reg = publish::registry())));
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = ((sz[0] as u32) << 0) |
((sz[1] as u32) << 8) |
((sz[2] as u32) << 16) |
((sz[3] as u32) << 24);
f.seek(SeekFrom::Current(sz as i64 + 4)).unwrap();
// Verify the tarball
let mut rdr = GzDecoder::new(f).unwrap();
assert_eq!(rdr.header().filename().unwrap(), "foo-0.0.1.crate".as_bytes());
let mut contents = Vec::new();
rdr.read_to_end(&mut contents).unwrap();
let mut ar = Archive::new(&contents[..]);
for file in ar.entries().unwrap() {
let file = file.unwrap();
let fname = file.header().path_bytes();
let fname = &*fname;
assert!(fname == b"foo-0.0.1/Cargo.toml" ||
fname == b"foo-0.0.1/Cargo.toml.orig" ||
fname == b"foo-0.0.1/src/main.rs",
"unexpected filename: {:?}", file.header().path());
}
}
// TODO: Deprecated
// remove once it has been decided --host can be removed
#[test]
fn simple_with_index_and_host() {
publish::setup();
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
"#)
.file("src/main.rs", "fn main() {}");
assert_that(p.cargo_process("publish").arg("--no-verify")
.arg("--index").arg(publish::registry().to_string())
.arg("--host").arg(publish::registry().to_string()),
execs().with_status(0).with_stderr(&format!("\
[WARNING] The flag '--host' is no longer valid.
Previous versions of Cargo accepted this flag, but it is being
deprecated. The flag is being renamed to 'index', as the flag
wants the location of the index to which to publish. Please
use '--index' instead.
This will soon become a hard error, so it's either recommended
to update to a fixed version or contact the upstream maintainer
about this warning.
[UPDATING] registry `{reg}`
2016-05-20 14:00:15 +00:00
[WARNING] manifest has no documentation, [..]
See [..]
[PACKAGING] foo v0.0.1 ({dir})
[UPLOADING] foo v0.0.1 ({dir})
2014-09-09 14:23:09 +00:00
",
dir = p.url(),
reg = publish::registry())));
2014-09-09 14:23:09 +00:00
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
// Skip the metadata payload and the size of the tarball
let mut sz = [0; 4];
assert_eq!(f.read(&mut sz).unwrap(), 4);
let sz = ((sz[0] as u32) << 0) |
((sz[1] as u32) << 8) |
((sz[2] as u32) << 16) |
((sz[3] as u32) << 24);
f.seek(SeekFrom::Current(sz as i64 + 4)).unwrap();
// Verify the tarball
let mut rdr = GzDecoder::new(f).unwrap();
2015-03-22 23:58:11 +00:00
assert_eq!(rdr.header().filename().unwrap(), "foo-0.0.1.crate".as_bytes());
let mut contents = Vec::new();
rdr.read_to_end(&mut contents).unwrap();
let mut ar = Archive::new(&contents[..]);
for file in ar.entries().unwrap() {
2014-09-09 14:23:09 +00:00
let file = file.unwrap();
let fname = file.header().path_bytes();
let fname = &*fname;
2014-11-19 06:29:19 +00:00
assert!(fname == b"foo-0.0.1/Cargo.toml" ||
Rewrite Cargo.toml when packaging crates This commit is an implementation of rewriting TOML manifests when we publish them to the registry. The rationale for doing this is to provide a guarantee that downloaded tarballs from crates.io can be built with `cargo build` (literally). This in turn eases a number of other possible consumers of crates from crates.io * Vendored sources can now be more easily modified/checked as cargo build should work and they're standalone crates that suffice for `path` dependencies * Tools like cargobomb/crater no longer need to edit the manifest and can instead perform regression testing on the literal tarballs they download * Other systems such as packaging Rust code may be able to take advantage of this, but this is a less clear benefit. Overall I'm hesitatnt about this, unfortunately. This is a silent translation happening on *publish*, a rare operation, that's difficult to inspect before it flies up to crates.io. I wrote a script to run this transformation over all crates.io crates and found a surprisingly large number of discrepancies. The transformation basically just downloaded all crates at all versions, regenerated the manifest, and then tested if the two manifests were (in memory) the same. Unfortunately historical Cargo had a critical bug which I think made this exercise not too useful. Cargo used to *not* recreate tarballs if one already existed, which I believe led to situations such as: 1. `cargo publish` 2. Cargo generates an error about a dependency. This could be that there's a `version` not present in a `path` dependency, there could be a `git` dependency, etc. 3. Errors are fixed. 4. `cargo publish` 5. Publish is successful In step 4 above historical Cargo *would not recreate the tarball*. This means that the contents of the index (what was published) aren't guaranteed to match with the tarball's `Cargo.toml`. When building from crates.io this is ok as the index is the source of truth for dependency information, but it means that *any* transformation to rewrite Cargo.toml is impossible to verify against all crates on crates.io (due to historical bugs like these). I strove to read as many errors as possible regardless, attempting to suss out bugs in the implementation here. To further guard against surprises I've updated the verification step of packaging to work "normally" in these sense that it's not rewriting dependencies itself or changing summaries. I'm hoping that this serves as a good last-ditch effort that what we're about to publish will indeed build as expected when uploaded to crates.io Overall I'm probably 70% confident in this change. I think it's necessary to make progress, but I think there are going to be very painful bugs that arise from this feature. I'm open to ideas to help weed out these bugs ahead of time! I've done what I can but I fear it may not be entirely enough. Closes #4027
2017-05-11 05:09:44 +00:00
fname == b"foo-0.0.1/Cargo.toml.orig" ||
2014-11-19 06:29:19 +00:00
fname == b"foo-0.0.1/src/main.rs",
"unexpected filename: {:?}", file.header().path());
2014-09-09 14:23:09 +00:00
}
}
#[test]
fn git_deps() {
publish::setup();
2014-09-09 14:23:09 +00:00
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
2014-09-09 14:23:09 +00:00
[dependencies.foo]
git = "git://path/to/nowhere"
"#)
.file("src/main.rs", "fn main() {}");
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
assert_that(p.cargo_process("publish").arg("-v").arg("--no-verify")
.arg("--index").arg(publish::registry().to_string()),
2016-05-12 17:06:36 +00:00
execs().with_status(101).with_stderr("\
2016-05-20 14:00:15 +00:00
[UPDATING] registry [..]
[ERROR] crates cannot be published to crates.io with dependencies sourced from \
a repository\neither publish `foo` as its own crate on crates.io and \
specify a crates.io version as a dependency or pull it into this \
repository and specify it with a path and version\n\
(crate `foo` has repository path `git://path/to/nowhere`)\
2016-05-12 17:06:36 +00:00
"));
}
#[test]
fn path_dependency_no_version() {
publish::setup();
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
[dependencies.bar]
path = "bar"
"#)
.file("src/main.rs", "fn main() {}")
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.0.1"
authors = []
"#)
.file("bar/src/lib.rs", "");
2014-09-09 14:23:09 +00:00
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
assert_that(p.cargo_process("publish")
.arg("--index").arg(publish::registry().to_string()),
2016-05-12 17:06:36 +00:00
execs().with_status(101).with_stderr("\
2016-05-20 14:00:15 +00:00
[UPDATING] registry [..]
[ERROR] all path dependencies must have a version specified when publishing.
dependency `bar` does not specify a version
2016-05-12 17:06:36 +00:00
"));
}
#[test]
fn unpublishable_crate() {
publish::setup();
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
publish = false
"#)
.file("src/main.rs", "fn main() {}");
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
assert_that(p.cargo_process("publish")
.arg("--index").arg(publish::registry().to_string()),
2016-05-12 17:06:36 +00:00
execs().with_status(101).with_stderr("\
[ERROR] some crates cannot be published.
`foo` is marked as unpublishable
2016-05-12 17:06:36 +00:00
"));
}
#[test]
fn dont_publish_dirty() {
publish::setup();
let p = project("foo")
.file("bar", "");
p.build();
repo(&paths::root().join("foo"))
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
documentation = "foo"
homepage = "foo"
repository = "foo"
"#)
.file("src/main.rs", "fn main() {}")
.build();
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
assert_that(p.cargo("publish")
.arg("--index").arg(publish::registry().to_string()),
execs().with_status(101).with_stderr("\
[UPDATING] registry `[..]`
error: 1 files in the working directory contain changes that were not yet \
committed into git:
bar
to proceed despite this, pass the `--allow-dirty` flag
"));
}
#[test]
fn publish_clean() {
publish::setup();
let p = project("foo");
p.build();
repo(&paths::root().join("foo"))
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
documentation = "foo"
homepage = "foo"
repository = "foo"
"#)
.file("src/main.rs", "fn main() {}")
.build();
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
assert_that(p.cargo("publish")
.arg("--index").arg(publish::registry().to_string()),
execs().with_status(0));
}
#[test]
fn publish_in_sub_repo() {
publish::setup();
let p = project("foo")
.file("baz", "");
p.build();
repo(&paths::root().join("foo"))
.file("bar/Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
documentation = "foo"
homepage = "foo"
repository = "foo"
"#)
.file("bar/src/main.rs", "fn main() {}")
.build();
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
assert_that(p.cargo("publish").cwd(p.root().join("bar"))
.arg("--index").arg(publish::registry().to_string()),
execs().with_status(0));
}
#[test]
fn publish_when_ignored() {
publish::setup();
let p = project("foo")
.file("baz", "");
p.build();
repo(&paths::root().join("foo"))
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
documentation = "foo"
homepage = "foo"
repository = "foo"
"#)
.file("src/main.rs", "fn main() {}")
.file(".gitignore", "baz")
.build();
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
assert_that(p.cargo("publish")
.arg("--index").arg(publish::registry().to_string()),
execs().with_status(0));
}
#[test]
fn ignore_when_crate_ignored() {
publish::setup();
let p = project("foo")
.file("bar/baz", "");
p.build();
repo(&paths::root().join("foo"))
.file(".gitignore", "bar")
.nocommit_file("bar/Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
documentation = "foo"
homepage = "foo"
repository = "foo"
"#)
.nocommit_file("bar/src/main.rs", "fn main() {}");
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
assert_that(p.cargo("publish").cwd(p.root().join("bar"))
.arg("--index").arg(publish::registry().to_string()),
execs().with_status(0));
}
#[test]
fn new_crate_rejected() {
publish::setup();
let p = project("foo")
.file("baz", "");
p.build();
repo(&paths::root().join("foo"))
.nocommit_file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
documentation = "foo"
homepage = "foo"
repository = "foo"
"#)
.nocommit_file("src/main.rs", "fn main() {}");
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
assert_that(p.cargo("publish")
.arg("--index").arg(publish::registry().to_string()),
execs().with_status(101));
}
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
#[test]
fn dry_run() {
publish::setup();
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.0.1"
authors = []
license = "MIT"
description = "foo"
"#)
.file("src/main.rs", "fn main() {}");
Implement source redirection This commit implements a scheme for .cargo/config files where sources can be redirected to other sources. The purpose of this will be to override crates.io for a few use cases: * Replace it with a mirror site that is sync'd to crates.io * Replace it with a "directory source" or some other local source This major feature of this redirection, however, is that none of it is encoded into the lock file. If one source is redirected to another then it is assumed that packages from both are exactly the same (e.g. `foo v0.0.1` is the same in both location). The lock file simply encodes the canonical soure (e.g. crates.io) rather than the replacement source. In the end this means that Cargo.lock files can be generated from any replacement source and shipped to other locations without the lockfile oscillating about where packages came from. Eventually this support will be extended to `Cargo.toml` itself (which will be encoded into the lock file), but that support is not implemented today. The syntax for what was implemented today looks like: # .cargo/config [source.my-awesome-registry] registry = 'https://example.com/path/to/index' [source.crates-io] replace-with = 'my-awesome-registry' Each source will have a canonical name and will be configured with the various keys underneath it (today just 'registry' and 'directory' will be accepted). The global `crates-io` source represents crates from the standard registry, and this can be replaced with other mirror sources. All tests have been modified to use this new infrastructure instead of the old `registry.index` configuration. This configuration is now also deprecated and will emit an unconditional warning about how it will no longer be used in the future. Finally, all subcommands now use this "source map" except for `cargo publish`, which will always publish to the default registry (in this case crates.io).
2016-02-03 18:54:07 +00:00
assert_that(p.cargo_process("publish").arg("--dry-run")
.arg("--index").arg(publish::registry().to_string()),
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
execs().with_status(0).with_stderr(&format!("\
2016-07-05 17:28:51 +00:00
[UPDATING] registry `[..]`
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
[WARNING] manifest has no documentation, [..]
See [..]
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
[PACKAGING] foo v0.0.1 ({dir})
[VERIFYING] foo v0.0.1 ({dir})
[COMPILING] foo v0.0.1 [..]
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
[UPLOADING] foo v0.0.1 ({dir})
[WARNING] aborting upload due to dry run
",
2016-07-05 17:28:51 +00:00
dir = p.url())));
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
// Ensure the API request wasn't actually made
assert!(!publish::upload_path().join("api/v1/crates/new").exists());
Add --dry-run option to publish sub-command Squashed commit of the following: commit deed1d7b99c1cd142f7782d3b3b782d949e1f71f Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:35:01 2016 +1000 Remove --dry-run and --no-verify mutual exclusion commit 8a91fcf2a1aa3ba682fee67bb5b3e7c2c2cce8ef Merge: 0c0d057 970535d Author: Wesley Moore <wes@wezm.net> Date: Fri Jul 15 13:30:38 2016 +1000 Merge remote-tracking branch 'upstream/master' into publish_dry_run commit 0c0d0572533599b3c0e42797a6014edf480f1dc2 Author: Wesley Moore <wes@wezm.net> Date: Tue Jul 12 08:03:15 2016 +1000 Improve grammar in --dry-run option commit a17c1bf6f41f016cafdcb8cfc58ccbe34d54fbb8 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:17:41 2016 +1000 Add test for passing no-verify and dry-run to publish commit 284810cca5df3268596f18700c0247de2f621c98 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 14:51:38 2016 +1000 Add test for publish --dry-run commit 8514e47fbce61c20b227815887a377c25d17d004 Merge: 2b061c5 ef07b81 Author: Wesley Moore <wes@wezm.net> Date: Mon Jul 11 08:27:10 2016 +1000 Merge branch 'publish_dry_run' of github.com:JustAPerson/cargo into publish_dry_run commit ef07b81617df855328c34365b28049cd9742946c Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 23:11:51 2015 -0500 Improve publish `--dry-run` Catch a few more errors by aborting midway through transmit(). commit 0686fb0bf92a09bcbd41e15e23ff03a0763c5d08 Author: Jason Priest <jpriest128@gmail.com> Date: Tue Jun 9 14:38:58 2015 -0500 Teach publish the `--dry-run` flag Closes #1332
2016-07-17 23:43:57 +00:00
}