From 242690335edd36a6280a2c2e39dbccec2b9dc30a Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 11 Apr 2024 11:36:49 -0700 Subject: [PATCH] test: deal with lockfile checksums dynamically When generating local registries in the testsuite, the specific package checksums may vary from the original simply due to different `zlib` versions. For example, Fedora 40 is now using `zlib-ng-compat`. We can account for this dynamically by either formatting the checksum in the expected output string, or using `generate-lockfile` on projects and their expected output. --- crates/cargo-test-support/src/lib.rs | 17 ++++-- tests/testsuite/alt_registry.rs | 8 ++- .../cargo_add/locked_unchanged/in/Cargo.lock | 16 ----- .../cargo_add/locked_unchanged/mod.rs | 2 + .../cargo_add/lockfile_updated/in/Cargo.lock | 17 ------ .../cargo_add/lockfile_updated/mod.rs | 6 +- .../cargo_add/lockfile_updated/out/Cargo.lock | 23 -------- .../cargo_add/lockfile_updated/out/src/lib.rs | 0 .../update_lock_file/in/Cargo.lock | 58 ------------------- .../cargo_remove/update_lock_file/mod.rs | 6 +- .../update_lock_file/out/Cargo.lock | 51 ---------------- 11 files changed, 30 insertions(+), 174 deletions(-) delete mode 100644 tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock delete mode 100644 tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock delete mode 100644 tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock create mode 100644 tests/testsuite/cargo_add/lockfile_updated/out/src/lib.rs delete mode 100644 tests/testsuite/cargo_remove/update_lock_file/in/Cargo.lock delete mode 100644 tests/testsuite/cargo_remove/update_lock_file/out/Cargo.lock diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index a02f8293380..c563d404d81 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -311,14 +311,23 @@ impl ProjectBuilder { } impl Project { - /// Copy the test project from a fixed state - pub fn from_template(template_path: impl AsRef) -> Self { + fn new(template_path: &std::path::Path, name: &str) -> Self { let root = paths::root(); - let project_root = root.join("case"); - snapbox::path::copy_template(template_path.as_ref(), &project_root).unwrap(); + let project_root = root.join(name); + snapbox::path::copy_template(template_path, &project_root).unwrap(); Self { root: project_root } } + /// Copy the test project from a fixed state + pub fn from_template(template_path: impl AsRef) -> Self { + Self::new(template_path.as_ref(), "case") + } + + /// Copy the test project from expected output + pub fn from_expected(template_path: impl AsRef) -> Self { + Self::new(template_path.as_ref(), "expected") + } + /// Root of the project, ex: `/path/to/cargo/target/cit/t0/foo` pub fn root(&self) -> PathBuf { self.root.clone() diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index e122199baa4..e15165aa0ac 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -1456,7 +1456,7 @@ fn sparse_lockfile() { .http_index() .alternative() .build(); - Package::new("foo", "0.1.0").alternative(true).publish(); + let cksum = Package::new("foo", "0.1.0").alternative(true).publish(); let p = project() .file( @@ -1478,7 +1478,8 @@ fn sparse_lockfile() { p.cargo("generate-lockfile").run(); assert_match_exact( &p.read_lockfile(), - r#"# This file is automatically @generated by Cargo. + &format!( + r#"# This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 @@ -1493,7 +1494,8 @@ dependencies = [ name = "foo" version = "0.1.0" source = "sparse+http://[..]/" -checksum = "f6a200a9339fef960979d94d5c99cbbfd899b6f5a396a55d9775089119050203""#, +checksum = "{cksum}""#, + ), ); } diff --git a/tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock b/tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock deleted file mode 100644 index 011b335926e..00000000000 --- a/tests/testsuite/cargo_add/locked_unchanged/in/Cargo.lock +++ /dev/null @@ -1,16 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "cargo-list-test-fixture" -version = "0.0.0" -dependencies = [ - "my-package", -] - -[[package]] -name = "my-package" -version = "99999.0.0+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62c45acf9e11d2f97f5b318143219c0b4102eafef1c22a4b545b47104691d915" diff --git a/tests/testsuite/cargo_add/locked_unchanged/mod.rs b/tests/testsuite/cargo_add/locked_unchanged/mod.rs index 932c008bb38..72f16da5cb6 100644 --- a/tests/testsuite/cargo_add/locked_unchanged/mod.rs +++ b/tests/testsuite/cargo_add/locked_unchanged/mod.rs @@ -24,6 +24,8 @@ fn case() { let project_root = project.root(); let cwd = &project_root; + project.cargo("generate-lockfile").run(); + snapbox::cmd::Command::cargo_ui() .arg("add") .arg_line("my-package --locked") diff --git a/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock b/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock deleted file mode 100644 index d9bcc988d3f..00000000000 --- a/tests/testsuite/cargo_add/lockfile_updated/in/Cargo.lock +++ /dev/null @@ -1,17 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "cargo-list-test-fixture" -version = "0.0.0" -dependencies = [ - "my-package", - "unrelateed-crate", -] - -[[package]] -name = "unrelateed-crate" -version = "0.2.0+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266de4849a570b5dfda5e8e082a2aff885e9d2d4965dae8f8b6c8535e1ec731f" diff --git a/tests/testsuite/cargo_add/lockfile_updated/mod.rs b/tests/testsuite/cargo_add/lockfile_updated/mod.rs index 151f49b38f1..c04d6c615f2 100644 --- a/tests/testsuite/cargo_add/lockfile_updated/mod.rs +++ b/tests/testsuite/cargo_add/lockfile_updated/mod.rs @@ -26,6 +26,8 @@ fn case() { let project_root = project.root(); let cwd = &project_root; + project.cargo("generate-lockfile").run(); + snapbox::cmd::Command::cargo_ui() .arg("add") .arg_line("my-package") @@ -35,5 +37,7 @@ fn case() { .stdout_matches(str![""]) .stderr_matches(file!["stderr.term.svg"]); - assert_ui().subset_matches(current_dir!().join("out"), &project_root); + let expected = Project::from_expected(current_dir!().join("out")); + expected.cargo("generate-lockfile").run(); + assert_ui().subset_matches(&expected.root(), &project_root); } diff --git a/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock b/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock deleted file mode 100644 index 4b5fb465f10..00000000000 --- a/tests/testsuite/cargo_add/lockfile_updated/out/Cargo.lock +++ /dev/null @@ -1,23 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "cargo-list-test-fixture" -version = "0.0.0" -dependencies = [ - "my-package", - "unrelateed-crate", -] - -[[package]] -name = "my-package" -version = "99999.0.0+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62c45acf9e11d2f97f5b318143219c0b4102eafef1c22a4b545b47104691d915" - -[[package]] -name = "unrelateed-crate" -version = "0.2.0+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266de4849a570b5dfda5e8e082a2aff885e9d2d4965dae8f8b6c8535e1ec731f" diff --git a/tests/testsuite/cargo_add/lockfile_updated/out/src/lib.rs b/tests/testsuite/cargo_add/lockfile_updated/out/src/lib.rs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/testsuite/cargo_remove/update_lock_file/in/Cargo.lock b/tests/testsuite/cargo_remove/update_lock_file/in/Cargo.lock deleted file mode 100644 index 2302220f2fb..00000000000 --- a/tests/testsuite/cargo_remove/update_lock_file/in/Cargo.lock +++ /dev/null @@ -1,58 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "cargo-remove-test-fixture" -version = "0.1.0" -dependencies = [ - "clippy", - "docopt", - "regex", - "rustc-serialize", - "semver", - "serde", - "toml", -] - -[[package]] -name = "clippy" -version = "0.4.1+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47ced0eda54e9ddc6063f0e1d0164493cd16c84c6b6a0329a536967c44e205f7" - -[[package]] -name = "docopt" -version = "0.6.2+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b600540c4fafb27bf6e6961f0f1e6f547c9d6126ce581ab3a92f878c8e2c9a2c" - -[[package]] -name = "regex" -version = "0.1.1+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84949cb53285a6c481d0133065a7b669871acfd9e20f273f4ce1283c309775d5" - -[[package]] -name = "rustc-serialize" -version = "0.4.1+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31162e7d23a085553c42dee375787b451a481275473f7779c4a63bcc267a24fd" - -[[package]] -name = "semver" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "106bee742e3199d9e59f4269e458dfc825c1b4648c483b1c2b7a45cd2610a308" - -[[package]] -name = "serde" -version = "1.0.90" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be7d269f612a60e3c2c4a4a120e2d878a3f3298a5285eda6e95453905a107d9a" - -[[package]] -name = "toml" -version = "0.1.1+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0f6c7804525ce0a968ef270e55a516cf4bdcf1fea0b09d130e0aa34a66745b3" diff --git a/tests/testsuite/cargo_remove/update_lock_file/mod.rs b/tests/testsuite/cargo_remove/update_lock_file/mod.rs index bbc0a62fb6c..093b3da64d4 100644 --- a/tests/testsuite/cargo_remove/update_lock_file/mod.rs +++ b/tests/testsuite/cargo_remove/update_lock_file/mod.rs @@ -24,6 +24,8 @@ fn case() { let project_root = project.root(); let cwd = &project_root; + project.cargo("generate-lockfile").run(); + snapbox::cmd::Command::cargo_ui() .arg("remove") .args(["rustc-serialize"]) @@ -33,5 +35,7 @@ fn case() { .stdout_matches(str![""]) .stderr_matches(file!["stderr.term.svg"]); - assert_ui().subset_matches(current_dir!().join("out"), &project_root); + let expected = Project::from_expected(current_dir!().join("out")); + expected.cargo("generate-lockfile").run(); + assert_ui().subset_matches(&expected.root(), &project_root); } diff --git a/tests/testsuite/cargo_remove/update_lock_file/out/Cargo.lock b/tests/testsuite/cargo_remove/update_lock_file/out/Cargo.lock deleted file mode 100644 index 0946cee4771..00000000000 --- a/tests/testsuite/cargo_remove/update_lock_file/out/Cargo.lock +++ /dev/null @@ -1,51 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "cargo-remove-test-fixture" -version = "0.1.0" -dependencies = [ - "clippy", - "docopt", - "regex", - "semver", - "serde", - "toml", -] - -[[package]] -name = "clippy" -version = "0.4.1+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47ced0eda54e9ddc6063f0e1d0164493cd16c84c6b6a0329a536967c44e205f7" - -[[package]] -name = "docopt" -version = "0.6.2+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b600540c4fafb27bf6e6961f0f1e6f547c9d6126ce581ab3a92f878c8e2c9a2c" - -[[package]] -name = "regex" -version = "0.1.1+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84949cb53285a6c481d0133065a7b669871acfd9e20f273f4ce1283c309775d5" - -[[package]] -name = "semver" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "106bee742e3199d9e59f4269e458dfc825c1b4648c483b1c2b7a45cd2610a308" - -[[package]] -name = "serde" -version = "1.0.90" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be7d269f612a60e3c2c4a4a120e2d878a3f3298a5285eda6e95453905a107d9a" - -[[package]] -name = "toml" -version = "0.1.1+my-package" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0f6c7804525ce0a968ef270e55a516cf4bdcf1fea0b09d130e0aa34a66745b3"