From 43f5c8adc984303aca260857f028256bd380bc63 Mon Sep 17 00:00:00 2001 From: William Correia Date: Fri, 27 Aug 2021 22:04:53 -0400 Subject: [PATCH] Add tests for --no-ignore-parent --- tests/tests.rs | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/tests.rs b/tests/tests.rs index 7fe2c70..4642f28 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -497,6 +497,78 @@ fn test_gitignore_and_fdignore() { ); } +/// Ignore parent ignore files (--no-ignore-parent) +#[test] +fn test_no_ignore_parent() { + let dirs = &["inner"]; + let files = &[ + "inner/parent-ignored", + "inner/child-ignored", + "inner/not-ignored", + ]; + let te = TestEnv::new(dirs, files); + + // Ignore 'parent-ignored' in root + fs::File::create(te.test_root().join(".gitignore")) + .unwrap() + .write_all(b"parent-ignored") + .unwrap(); + // Ignore 'child-ignored' in inner + fs::File::create(te.test_root().join("inner/.gitignore")) + .unwrap() + .write_all(b"child-ignored") + .unwrap(); + + te.assert_output_subdirectory("inner", &[], "not-ignored"); + + te.assert_output_subdirectory( + "inner", + &["--no-ignore-parent"], + "parent-ignored + not-ignored", + ); +} + +/// Ignore parent ignore files (--no-ignore-parent) with an inner git repo +#[test] +fn test_no_ignore_parent_inner_git() { + let dirs = &["inner"]; + let files = &[ + "inner/parent-ignored", + "inner/child-ignored", + "inner/not-ignored", + ]; + let te = TestEnv::new(dirs, files); + + // Make the inner folder also appear as a git repo + fs::create_dir_all(te.test_root().join("inner/.git")).unwrap(); + + // Ignore 'parent-ignored' in root + fs::File::create(te.test_root().join(".gitignore")) + .unwrap() + .write_all(b"parent-ignored") + .unwrap(); + // Ignore 'child-ignored' in inner + fs::File::create(te.test_root().join("inner/.gitignore")) + .unwrap() + .write_all(b"child-ignored") + .unwrap(); + + te.assert_output_subdirectory( + "inner", + &[], + "not-ignored + parent-ignored", + ); + + te.assert_output_subdirectory( + "inner", + &["--no-ignore-parent"], + "not-ignored + parent-ignored", + ); +} + /// Precedence of .fdignore files #[test] fn test_custom_ignore_precedence() {