mirror of https://github.com/rust-lang/cargo
Adding feature tests to `publish` and `package`
This commit is contained in:
parent
256fc39492
commit
142bafb7e6
|
@ -1298,3 +1298,67 @@ To proceed despite this, pass the `--no-verify` flag.",
|
|||
|
||||
p.cargo("package --no-verify").run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn package_with_select_features() {
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["alternative-registries"]
|
||||
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
license = "MIT"
|
||||
description = "foo"
|
||||
|
||||
[features]
|
||||
required = []
|
||||
optional = []
|
||||
"#,
|
||||
).file(
|
||||
"src/main.rs",
|
||||
"#[cfg(not(feature = \"required\"))]
|
||||
compile_error!(\"This crate requires `required` feature!\");
|
||||
fn main() {}",
|
||||
).build();
|
||||
|
||||
p.cargo("package --features required")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_status(0)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn package_with_all_features() {
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["alternative-registries"]
|
||||
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
license = "MIT"
|
||||
description = "foo"
|
||||
|
||||
[features]
|
||||
required = []
|
||||
optional = []
|
||||
"#,
|
||||
).file(
|
||||
"src/main.rs",
|
||||
"#[cfg(not(feature = \"required\"))]
|
||||
compile_error!(\"This crate requires `required` feature!\");
|
||||
fn main() {}",
|
||||
).build();
|
||||
|
||||
p.cargo("package --all-features")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_status(0)
|
||||
.run();
|
||||
}
|
||||
|
|
|
@ -23,8 +23,7 @@ fn simple() {
|
|||
license = "MIT"
|
||||
description = "foo"
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --no-verify --index")
|
||||
|
@ -38,8 +37,7 @@ See [..]
|
|||
[UPLOADING] foo v0.0.1 ([CWD])
|
||||
",
|
||||
reg = publish::registry_path().to_str().unwrap()
|
||||
))
|
||||
.run();
|
||||
)).run();
|
||||
|
||||
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
||||
// Skip the metadata payload and the size of the tarball
|
||||
|
@ -98,8 +96,7 @@ fn old_token_location() {
|
|||
license = "MIT"
|
||||
description = "foo"
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --no-verify --index")
|
||||
|
@ -113,8 +110,7 @@ See [..]
|
|||
[UPLOADING] foo v0.0.1 ([CWD])
|
||||
",
|
||||
reg = publish::registry_path().to_str().unwrap()
|
||||
))
|
||||
.run();
|
||||
)).run();
|
||||
|
||||
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
||||
// Skip the metadata payload and the size of the tarball
|
||||
|
@ -166,8 +162,7 @@ fn simple_with_host() {
|
|||
license = "MIT"
|
||||
description = "foo"
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --no-verify --host")
|
||||
|
@ -190,8 +185,7 @@ See [..]
|
|||
[UPLOADING] foo v0.0.1 ([CWD])
|
||||
",
|
||||
reg = publish::registry_path().to_str().unwrap()
|
||||
))
|
||||
.run();
|
||||
)).run();
|
||||
|
||||
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
||||
// Skip the metadata payload and the size of the tarball
|
||||
|
@ -243,8 +237,7 @@ fn simple_with_index_and_host() {
|
|||
license = "MIT"
|
||||
description = "foo"
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --no-verify --index")
|
||||
|
@ -269,8 +262,7 @@ See [..]
|
|||
[UPLOADING] foo v0.0.1 ([CWD])
|
||||
",
|
||||
reg = publish::registry_path().to_str().unwrap()
|
||||
))
|
||||
.run();
|
||||
)).run();
|
||||
|
||||
let mut f = File::open(&publish::upload_path().join("api/v1/crates/new")).unwrap();
|
||||
// Skip the metadata payload and the size of the tarball
|
||||
|
@ -323,8 +315,7 @@ fn git_deps() {
|
|||
[dependencies.foo]
|
||||
git = "git://path/to/nowhere"
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish -v --no-verify --index")
|
||||
|
@ -339,8 +330,7 @@ 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`)\
|
||||
",
|
||||
)
|
||||
.run();
|
||||
).run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -361,8 +351,7 @@ fn path_dependency_no_version() {
|
|||
[dependencies.bar]
|
||||
path = "bar"
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.file("bar/Cargo.toml", &basic_manifest("bar", "0.0.1"))
|
||||
.file("bar/src/lib.rs", "")
|
||||
.build();
|
||||
|
@ -376,8 +365,7 @@ fn path_dependency_no_version() {
|
|||
[ERROR] all path dependencies must have a version specified when publishing.
|
||||
dependency `bar` does not specify a version
|
||||
",
|
||||
)
|
||||
.run();
|
||||
).run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -396,8 +384,7 @@ fn unpublishable_crate() {
|
|||
description = "foo"
|
||||
publish = false
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --index")
|
||||
|
@ -408,8 +395,7 @@ fn unpublishable_crate() {
|
|||
[ERROR] some crates cannot be published.
|
||||
`foo` is marked as unpublishable
|
||||
",
|
||||
)
|
||||
.run();
|
||||
).run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -431,8 +417,7 @@ fn dont_publish_dirty() {
|
|||
homepage = "foo"
|
||||
repository = "foo"
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --index")
|
||||
|
@ -448,8 +433,7 @@ bar
|
|||
|
||||
to proceed despite this, pass the `--allow-dirty` flag
|
||||
",
|
||||
)
|
||||
.run();
|
||||
).run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -472,8 +456,7 @@ fn publish_clean() {
|
|||
homepage = "foo"
|
||||
repository = "foo"
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --index")
|
||||
|
@ -501,8 +484,7 @@ fn publish_in_sub_repo() {
|
|||
homepage = "foo"
|
||||
repository = "foo"
|
||||
"#,
|
||||
)
|
||||
.file("bar/src/main.rs", "fn main() {}")
|
||||
).file("bar/src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish")
|
||||
|
@ -532,8 +514,7 @@ fn publish_when_ignored() {
|
|||
homepage = "foo"
|
||||
repository = "foo"
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.file(".gitignore", "baz")
|
||||
.build();
|
||||
|
||||
|
@ -563,8 +544,7 @@ fn ignore_when_crate_ignored() {
|
|||
homepage = "foo"
|
||||
repository = "foo"
|
||||
"#,
|
||||
)
|
||||
.nocommit_file("bar/src/main.rs", "fn main() {}");
|
||||
).nocommit_file("bar/src/main.rs", "fn main() {}");
|
||||
p.cargo("publish")
|
||||
.cwd(p.root().join("bar"))
|
||||
.arg("--index")
|
||||
|
@ -592,8 +572,7 @@ fn new_crate_rejected() {
|
|||
homepage = "foo"
|
||||
repository = "foo"
|
||||
"#,
|
||||
)
|
||||
.nocommit_file("src/main.rs", "fn main() {}");
|
||||
).nocommit_file("src/main.rs", "fn main() {}");
|
||||
p.cargo("publish --index")
|
||||
.arg(publish::registry().to_string())
|
||||
.with_status(101)
|
||||
|
@ -615,8 +594,7 @@ fn dry_run() {
|
|||
license = "MIT"
|
||||
description = "foo"
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --dry-run --index")
|
||||
|
@ -633,8 +611,7 @@ See [..]
|
|||
[UPLOADING] foo v0.0.1 ([CWD])
|
||||
[WARNING] aborting upload due to dry run
|
||||
",
|
||||
)
|
||||
.run();
|
||||
).run();
|
||||
|
||||
// Ensure the API request wasn't actually made
|
||||
assert!(!publish::upload_path().join("api/v1/crates/new").exists());
|
||||
|
@ -658,8 +635,7 @@ fn block_publish_feature_not_enabled() {
|
|||
"test"
|
||||
]
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --registry alternative -Zunstable-options")
|
||||
|
@ -677,8 +653,7 @@ Caused by:
|
|||
|
||||
consider adding `cargo-features = [\"alternative-registries\"]` to the manifest
|
||||
",
|
||||
)
|
||||
.run();
|
||||
).run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -701,8 +676,7 @@ fn registry_not_in_publish_list() {
|
|||
"test"
|
||||
]
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish")
|
||||
|
@ -716,8 +690,7 @@ fn registry_not_in_publish_list() {
|
|||
[ERROR] some crates cannot be published.
|
||||
`foo` is marked as unpublishable
|
||||
",
|
||||
)
|
||||
.run();
|
||||
).run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -738,8 +711,7 @@ fn publish_empty_list() {
|
|||
description = "foo"
|
||||
publish = []
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --registry alternative -Zunstable-options")
|
||||
|
@ -750,8 +722,7 @@ fn publish_empty_list() {
|
|||
[ERROR] some crates cannot be published.
|
||||
`foo` is marked as unpublishable
|
||||
",
|
||||
)
|
||||
.run();
|
||||
).run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -776,8 +747,7 @@ fn publish_allowed_registry() {
|
|||
homepage = "foo"
|
||||
publish = ["alternative"]
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --registry alternative -Zunstable-options")
|
||||
|
@ -803,8 +773,7 @@ fn block_publish_no_registry() {
|
|||
description = "foo"
|
||||
publish = []
|
||||
"#,
|
||||
)
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
).file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("publish --registry alternative -Zunstable-options")
|
||||
|
@ -815,6 +784,85 @@ fn block_publish_no_registry() {
|
|||
[ERROR] some crates cannot be published.
|
||||
`foo` is marked as unpublishable
|
||||
",
|
||||
)
|
||||
.run();
|
||||
).run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn publish_with_select_features() {
|
||||
publish::setup();
|
||||
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["alternative-registries"]
|
||||
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
license = "MIT"
|
||||
description = "foo"
|
||||
publish = []
|
||||
|
||||
[features]
|
||||
required = []
|
||||
optional = []
|
||||
"#,
|
||||
).file(
|
||||
"src/main.rs",
|
||||
"#[cfg(not(required))]
|
||||
compile_error!(\"This crate requires `required` feature!\");
|
||||
fn main() {}",
|
||||
).build();
|
||||
|
||||
p.cargo("publish --registry alternative -Zunstable-options --features required")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
[ERROR] some crates cannot be published.
|
||||
`foo` is marked as unpublishable
|
||||
",
|
||||
).run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn publish_with_all_features() {
|
||||
publish::setup();
|
||||
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["alternative-registries"]
|
||||
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
authors = []
|
||||
license = "MIT"
|
||||
description = "foo"
|
||||
publish = []
|
||||
|
||||
[features]
|
||||
required = []
|
||||
optional = []
|
||||
"#,
|
||||
).file(
|
||||
"src/main.rs",
|
||||
"#[cfg(not(required))]
|
||||
compile_error!(\"This crate requires `required` feature!\");
|
||||
fn main() {}",
|
||||
).build();
|
||||
|
||||
p.cargo("publish --registry alternative -Zunstable-options --all-features")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"\
|
||||
[ERROR] some crates cannot be published.
|
||||
`foo` is marked as unpublishable
|
||||
",
|
||||
).run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue