Skip to content

Commit b7002ff

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 b7002ff

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

tests/testsuite/package.rs

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7284,3 +7284,143 @@ 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+
&["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/lib.rs"],
7334+
(),
7335+
);
7336+
}
7337+
7338+
// A failing case from <https://github.com/rust-lang/cargo/issues/15059>
7339+
#[cargo_test]
7340+
fn unpublished_cyclic_dev_dependencies() {
7341+
registry::init();
7342+
let p = project()
7343+
.file(
7344+
"Cargo.toml",
7345+
r#"
7346+
[package]
7347+
name = "foo"
7348+
version = "0.0.1"
7349+
edition = "2015"
7350+
authors = []
7351+
license = "MIT"
7352+
description = "foo"
7353+
documentation = "foo"
7354+
7355+
[dev-dependencies]
7356+
foo = { path = ".", version = "0.0.1" }
7357+
"#,
7358+
)
7359+
.file("src/lib.rs", "")
7360+
.build();
7361+
7362+
p.cargo("package --no-verify")
7363+
.with_status(101)
7364+
.with_stderr_data(str![[r#"
7365+
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
7366+
[UPDATING] `dummy-registry` index
7367+
[ERROR] failed to prepare local package for uploading
7368+
7369+
Caused by:
7370+
no matching package named `foo` found
7371+
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
7372+
required by package `foo v0.0.1 ([ROOT]/foo)`
7373+
7374+
"#]])
7375+
.run();
7376+
}
7377+
7378+
// A failing case from <https://github.com/rust-lang/cargo/issues/15059>
7379+
#[cargo_test]
7380+
fn unpublished_dependency() {
7381+
registry::init();
7382+
let p = project()
7383+
.file(
7384+
"Cargo.toml",
7385+
r#"
7386+
[package]
7387+
name = "foo"
7388+
version = "0.0.1"
7389+
edition = "2015"
7390+
authors = []
7391+
license = "MIT"
7392+
description = "foo"
7393+
documentation = "foo"
7394+
7395+
[dependencies]
7396+
dep = { path = "./dep", version = "0.0.1" }
7397+
"#,
7398+
)
7399+
.file("src/lib.rs", "")
7400+
.file(
7401+
"dep/Cargo.toml",
7402+
r#"
7403+
[package]
7404+
name = "dep"
7405+
version = "0.0.1"
7406+
edition = "2015"
7407+
"#,
7408+
)
7409+
.file("src/lib.rs", "")
7410+
.build();
7411+
7412+
p.cargo("package --no-verify -p foo")
7413+
.with_status(101)
7414+
.with_stderr_data(str![[r#"
7415+
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
7416+
[UPDATING] `dummy-registry` index
7417+
[ERROR] failed to prepare local package for uploading
7418+
7419+
Caused by:
7420+
no matching package named `dep` found
7421+
location searched: `dummy-registry` index (which is replacing registry `crates-io`)
7422+
required by package `foo v0.0.1 ([ROOT]/foo)`
7423+
7424+
"#]])
7425+
.run();
7426+
}

0 commit comments

Comments
 (0)