From f7a0473de028ebef486dacbd298931521038b8a3 Mon Sep 17 00:00:00 2001 From: Tor Hovland <55164+torhovland@users.noreply.github.com> Date: Fri, 24 May 2024 12:43:41 +0200 Subject: [PATCH] test: Verify that the vcs_info file gets packaged when allowing dirty. --- tests/testsuite/package.rs | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index fcca13388448..0a0922c99c3c 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -1171,6 +1171,74 @@ src/lib.rs .run(); } +#[cargo_test] +fn issue_13695_dirty_vcs_info() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + edition = "2015" + description = "foo" + license = "foo" + documentation = "foo" + "#, + ) + .file("src/lib.rs", "") + .build(); + + let repo = git::init(&p.root()); + // Initial commit, with no files added. + git::commit(&repo); + + // Fail because worktree is dirty. + p.cargo("package") + .with_status(101) + .with_stderr_contains( + "[ERROR] 2 files in the working directory contain changes that were not yet committed into git:", + ) + .run(); + + // Listing fails too. + p.cargo("package --list") + .with_status(101) + .with_stderr_contains( + "[ERROR] 2 files in the working directory contain changes that were not yet committed into git:", + ) + .run(); + + // Allowing a dirty worktree results in the vcs file being included. + p.cargo("package --allow-dirty").run(); + + let f = File::open(&p.root().join("target/package/foo-0.1.0.crate")).unwrap(); + validate_crate_contents( + f, + "foo-0.1.0.crate", + &[ + ".cargo_vcs_info.json", + "Cargo.toml", + "Cargo.toml.orig", + "src/lib.rs", + ], + &[], + ); + + // Listing provides a consistent result. + p.cargo("package --list --allow-dirty") + .with_stderr("") + .with_stdout( + "\ +.cargo_vcs_info.json +Cargo.toml +Cargo.toml.orig +src/lib.rs +", + ) + .run(); +} + #[cargo_test] fn generated_manifest() { let registry = registry::alt_init();