From 79cc65fa5ad5f84a5df9542a2a1d689975e5f75e Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 5 Nov 2021 14:57:40 -0700 Subject: [PATCH] Add tests for ignoring symlinks --- tests/testsuite/package.rs | 78 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/testsuite/package.rs b/tests/testsuite/package.rs index 071b6fdd9d2..fb917d5f3a8 100644 --- a/tests/testsuite/package.rs +++ b/tests/testsuite/package.rs @@ -806,6 +806,84 @@ Caused by: .run(); } +#[cargo_test] +#[cfg(not(windows))] // https://github.com/libgit2/libgit2/issues/6250 +/// Test that /dir and /dir/ matches symlinks to directories. +fn gitignore_symlink_dir() { + if !symlink_supported() { + return; + } + + let (p, _repo) = git::new_repo("foo", |p| { + p.file("src/main.rs", r#"fn main() { println!("hello"); }"#) + .symlink_dir("src", "src1") + .symlink_dir("src", "src2") + .symlink_dir("src", "src3") + .symlink_dir("src", "src4") + .file(".gitignore", "/src1\n/src2/\nsrc3\nsrc4/") + }); + + p.cargo("package -l --no-metadata") + .with_stderr("") + .with_stdout( + "\ +.cargo_vcs_info.json +.gitignore +Cargo.lock +Cargo.toml +Cargo.toml.orig +src/main.rs +", + ) + .run(); +} + +#[cargo_test] +#[cfg(not(windows))] // https://github.com/libgit2/libgit2/issues/6250 +/// Test that /dir and /dir/ matches symlinks to directories in dirty working directory. +fn gitignore_symlink_dir_dirty() { + if !symlink_supported() { + return; + } + + let (p, _repo) = git::new_repo("foo", |p| { + p.file("src/main.rs", r#"fn main() { println!("hello"); }"#) + .file(".gitignore", "/src1\n/src2/\nsrc3\nsrc4/") + }); + + p.symlink("src", "src1"); + p.symlink("src", "src2"); + p.symlink("src", "src3"); + p.symlink("src", "src4"); + + p.cargo("package -l --no-metadata") + .with_stderr("") + .with_stdout( + "\ +.cargo_vcs_info.json +.gitignore +Cargo.lock +Cargo.toml +Cargo.toml.orig +src/main.rs +", + ) + .run(); + + p.cargo("package -l --no-metadata --allow-dirty") + .with_stderr("") + .with_stdout( + "\ +.gitignore +Cargo.lock +Cargo.toml +Cargo.toml.orig +src/main.rs +", + ) + .run(); +} + #[cargo_test] /// Tests if a symlink to a directory is properly included. ///