Skip to content

Commit 2fa4627

Browse files
committed
test(package): fail with unpublished cyclic/transitive deps
After dd698ff, `cargo package --no-verify` at least fails in three different cases: * An unpublished package depending on itself as a dev-dependency (cyclic self-referential dev-dependencies). * Can be resolved by removing the `version` field from the affected dev-dependency. * `-Zpackage-workspace` doesn't help with it. * Existing `cargo package` has `--package <pkg>` specifying certain unpublished packages. * Can be resolved by specifying all unpublished packages in one `cargo` call. * `-Zpackage-workspace` also requires all dependency versions available in the target registry when calling, so doesn't help. * `cargo package --no-verify` has been used as a kind of “plumbing commands” to create tarballs without considering dependency orders. The use cases include: * Preparing tarballs for other package managers. * Integrating into custom develop workflows for unpublished/internal crates. * Constructing custom/private registries. This commit shows the former two cases.
1 parent 2dcb9b0 commit 2fa4627

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

tests/testsuite/package.rs

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7284,3 +7284,148 @@ This might cause the `.crate` file to include incorrect or incomplete files
72847284
],
72857285
);
72867286
}
7287+
7288+
#[cargo_test]
7289+
fn exclude_lockfile() {
7290+
let p = project()
7291+
.file(
7292+
"Cargo.toml",
7293+
r#"
7294+
[package]
7295+
name = "foo"
7296+
version = "0.0.1"
7297+
edition = "2015"
7298+
authors = []
7299+
license = "MIT"
7300+
description = "foo"
7301+
documentation = "foo"
7302+
"#,
7303+
)
7304+
.file("src/lib.rs", "")
7305+
.build();
7306+
7307+
p.cargo("package --list")
7308+
.with_stdout_data(str![[r#"
7309+
Cargo.lock
7310+
Cargo.toml
7311+
Cargo.toml.orig
7312+
src/lib.rs
7313+
7314+
"#]])
7315+
.with_stderr_data("")
7316+
.run();
7317+
7318+
p.cargo("package")
7319+
.with_stderr_data(str![[r#"
7320+
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
7321+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
7322+
[VERIFYING] foo v0.0.1 ([ROOT]/foo)
7323+
[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1)
7324+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
7325+
7326+
"#]])
7327+
.run();
7328+
7329+
let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).unwrap();
7330+
validate_crate_contents(
7331+
f,
7332+
"foo-0.0.1.crate",
7333+
&[
7334+
"Cargo.lock",
7335+
"Cargo.toml",
7336+
"Cargo.toml.orig",
7337+
"src/lib.rs",
7338+
],
7339+
(),
7340+
);
7341+
}
7342+
7343+
// A failing case from <https://github.com/rust-lang/cargo/issues/15059>
7344+
#[cargo_test]
7345+
fn unpublished_cyclic_dev_dependencies() {
7346+
registry::init();
7347+
let p = project()
7348+
.file(
7349+
"Cargo.toml",
7350+
r#"
7351+
[package]
7352+
name = "foo"
7353+
version = "0.0.1"
7354+
edition = "2015"
7355+
authors = []
7356+
license = "MIT"
7357+
description = "foo"
7358+
documentation = "foo"
7359+
7360+
[dev-dependencies]
7361+
foo = { path = ".", version = "0.0.1" }
7362+
"#,
7363+
)
7364+
.file("src/lib.rs", "")
7365+
.build();
7366+
7367+
p.cargo("package --no-verify")
7368+
.with_status(101)
7369+
.with_stderr_data(str![[r#"
7370+
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
7371+
[UPDATING] `dummy-registry` index
7372+
[ERROR] failed to prepare local package for uploading
7373+
7374+
Caused by:
7375+
no matching package named `foo` found
7376+
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
7377+
required by package `foo v0.0.1 ([ROOT]/foo)`
7378+
7379+
"#]])
7380+
.run();
7381+
}
7382+
7383+
// A failing case from <https://github.com/rust-lang/cargo/issues/15059>
7384+
#[cargo_test]
7385+
fn unpublished_dependency() {
7386+
registry::init();
7387+
let p = project()
7388+
.file(
7389+
"Cargo.toml",
7390+
r#"
7391+
[package]
7392+
name = "foo"
7393+
version = "0.0.1"
7394+
edition = "2015"
7395+
authors = []
7396+
license = "MIT"
7397+
description = "foo"
7398+
documentation = "foo"
7399+
7400+
[dependencies]
7401+
dep = { path = "./dep", version = "0.0.1" }
7402+
"#,
7403+
)
7404+
.file("src/lib.rs", "")
7405+
.file(
7406+
"dep/Cargo.toml",
7407+
r#"
7408+
[package]
7409+
name = "dep"
7410+
version = "0.0.1"
7411+
edition = "2015"
7412+
"#,
7413+
)
7414+
.file("src/lib.rs", "")
7415+
.build();
7416+
7417+
p.cargo("package --no-verify -p foo")
7418+
.with_status(101)
7419+
.with_stderr_data(str![[r#"
7420+
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
7421+
[UPDATING] `dummy-registry` index
7422+
[ERROR] failed to prepare local package for uploading
7423+
7424+
Caused by:
7425+
no matching package named `dep` found
7426+
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
7427+
required by package `foo v0.0.1 ([ROOT]/foo)`
7428+
7429+
"#]])
7430+
.run();
7431+
}

0 commit comments

Comments
 (0)