From 2033cb00d61c108e6671b5bc2f79244c8a5e379f Mon Sep 17 00:00:00 2001 From: Kael Zhang Date: Wed, 18 Dec 2024 23:25:38 +0800 Subject: [PATCH] #77: test: adds test cases for c/* test: better test error output --- test/fixtures/cases.js | 21 +++++++++++++++++++++ test/git-check-ignore.js | 1 + test/ignore.js | 9 ++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/test/fixtures/cases.js b/test/fixtures/cases.js index bcf2150..a2f438e 100644 --- a/test/fixtures/cases.js +++ b/test/fixtures/cases.js @@ -22,6 +22,27 @@ const cases = [ // } // ], ///////////////////////////////////////////////////////////////////// + [ + '#77: ignore the content of directory c, but not the directory c itself', + [ + 'c/', + '!c', + 'c/*' + ], + { + 'c': 0, + 'c/': 1 + } + ], + [ + '#77: issue for "directory ending with / not always correctly ignored"', + [ + 'c/*' + ], + { + 'c/': 1 + } + ], [ '#108: gitignore rules with BOM', [ diff --git a/test/git-check-ignore.js b/test/git-check-ignore.js index 6aa483b..79a28a3 100644 --- a/test/git-check-ignore.js +++ b/test/git-check-ignore.js @@ -110,6 +110,7 @@ const getNativeGitIgnoreResults = (rules, paths) => { .filter(p => { let out = spawn('git', [ 'check-ignore', + '--no-index', // `spawn` will escape the special cases for us p ], { diff --git a/test/ignore.js b/test/ignore.js index fcf1db4..b1ca01b 100755 --- a/test/ignore.js +++ b/test/ignore.js @@ -54,7 +54,14 @@ cases(({ const ig = ignore().addPattern(patterns) Object.keys(paths_object).forEach(path => { - t.equal(ig.ignores(path), !!paths_object[path], `path: "${path}"`) + const should_ignore = !!paths_object[path] + const not = should_ignore ? '' : 'not ' + + t.equal( + ig.ignores(path), + should_ignore, + `path: "${path}" should ${not}be ignored` + ) }) t.end() })