Skip to content

Commit 95e961b

Browse files
committed
Add a test showing the changed checksum.
1 parent 4ac865d commit 95e961b

File tree

2 files changed

+151
-0
lines changed

2 files changed

+151
-0
lines changed

tests/testsuite/package.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8082,3 +8082,80 @@ fn unpublished_dependency() {
80828082
(),
80838083
);
80848084
}
8085+
8086+
// This is a companion to `publish::checksum_changed`, but because this one
8087+
// is packaging without dry-run, it should fail.
8088+
#[cargo_test]
8089+
fn checksum_changed() {
8090+
let registry = registry::RegistryBuilder::new()
8091+
.http_api()
8092+
.http_index()
8093+
.build();
8094+
8095+
Package::new("dep", "1.0.0").publish();
8096+
Package::new("transitive", "1.0.0")
8097+
.dep("dep", "1.0.0")
8098+
.publish();
8099+
8100+
let p = project()
8101+
.file(
8102+
"Cargo.toml",
8103+
r#"
8104+
[workspace]
8105+
members = ["dep"]
8106+
8107+
[package]
8108+
name = "foo"
8109+
version = "0.0.1"
8110+
edition = "2015"
8111+
authors = []
8112+
license = "MIT"
8113+
description = "foo"
8114+
documentation = "foo"
8115+
8116+
[dependencies]
8117+
dep = { path = "./dep", version = "1.0.0" }
8118+
transitive = "1.0.0"
8119+
"#,
8120+
)
8121+
.file("src/lib.rs", "")
8122+
.file(
8123+
"dep/Cargo.toml",
8124+
r#"
8125+
[package]
8126+
name = "dep"
8127+
version = "1.0.0"
8128+
edition = "2015"
8129+
"#,
8130+
)
8131+
.file("dep/src/lib.rs", "")
8132+
.build();
8133+
8134+
p.cargo("check").run();
8135+
8136+
p.cargo("package --workspace -Zpackage-workspace")
8137+
.masquerade_as_nightly_cargo(&["package-workspace"])
8138+
.replace_crates_io(registry.index_url())
8139+
.with_status(101)
8140+
.with_stderr_data(str![[r#"
8141+
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
8142+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
8143+
[PACKAGING] dep v1.0.0 ([ROOT]/foo/dep)
8144+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
8145+
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
8146+
[ERROR] failed to prepare local package for uploading
8147+
8148+
Caused by:
8149+
checksum for `dep v1.0.0` changed between lock files
8150+
8151+
this could be indicative of a few possible errors:
8152+
8153+
* the lock file is corrupt
8154+
* a replacement source in use (e.g., a mirror) returned a different checksum
8155+
* the source itself may be corrupt in one way or another
8156+
8157+
unable to verify that `dep v1.0.0` is the same as when the lockfile was generated
8158+
8159+
"#]])
8160+
.run();
8161+
}

tests/testsuite/publish.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4378,3 +4378,77 @@ fn all_unpublishable_packages() {
43784378
"#]])
43794379
.run();
43804380
}
4381+
4382+
#[cargo_test]
4383+
fn checksum_changed() {
4384+
let registry = RegistryBuilder::new().http_api().http_index().build();
4385+
4386+
Package::new("dep", "1.0.0").publish();
4387+
Package::new("transitive", "1.0.0")
4388+
.dep("dep", "1.0.0")
4389+
.publish();
4390+
4391+
let p = project()
4392+
.file(
4393+
"Cargo.toml",
4394+
r#"
4395+
[workspace]
4396+
members = ["dep"]
4397+
4398+
[package]
4399+
name = "foo"
4400+
version = "0.0.1"
4401+
edition = "2015"
4402+
authors = []
4403+
license = "MIT"
4404+
description = "foo"
4405+
documentation = "foo"
4406+
4407+
[dependencies]
4408+
dep = { path = "./dep", version = "1.0.0" }
4409+
transitive = "1.0.0"
4410+
"#,
4411+
)
4412+
.file("src/lib.rs", "")
4413+
.file(
4414+
"dep/Cargo.toml",
4415+
r#"
4416+
[package]
4417+
name = "dep"
4418+
version = "1.0.0"
4419+
edition = "2015"
4420+
"#,
4421+
)
4422+
.file("dep/src/lib.rs", "")
4423+
.build();
4424+
4425+
p.cargo("check").run();
4426+
4427+
p.cargo("publish --dry-run --workspace -Zpackage-workspace")
4428+
.masquerade_as_nightly_cargo(&["package-workspace"])
4429+
.replace_crates_io(registry.index_url())
4430+
.with_status(101)
4431+
.with_stderr_data(str![[r#"
4432+
[UPDATING] crates.io index
4433+
[WARNING] crate dep@1.0.0 already exists on crates.io index
4434+
[WARNING] manifest has no description, license, license-file, documentation, homepage or repository.
4435+
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
4436+
[PACKAGING] dep v1.0.0 ([ROOT]/foo/dep)
4437+
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
4438+
[PACKAGING] foo v0.0.1 ([ROOT]/foo)
4439+
[ERROR] failed to prepare local package for uploading
4440+
4441+
Caused by:
4442+
checksum for `dep v1.0.0` changed between lock files
4443+
4444+
this could be indicative of a few possible errors:
4445+
4446+
* the lock file is corrupt
4447+
* a replacement source in use (e.g., a mirror) returned a different checksum
4448+
* the source itself may be corrupt in one way or another
4449+
4450+
unable to verify that `dep v1.0.0` is the same as when the lockfile was generated
4451+
4452+
"#]])
4453+
.run();
4454+
}

0 commit comments

Comments
 (0)