Merge pull request #43047 from aaronlehmann/pattern-matcher-parent-results-fix

Fix missing parent info case in MatchesUsingParentResults
This commit is contained in:
Sebastiaan van Stijn 2021-12-01 21:15:19 +01:00 committed by GitHub
commit 17b9e4ec92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View file

@ -251,7 +251,7 @@ func (pm *PatternMatcher) MatchesUsingParentResults(file string, parentMatchInfo
// If the zero value of MatchInfo was passed in, we don't have
// any information about the parent dir's match results, and we
// apply the same logic as MatchesOrParentMatches.
if len(parentMatched) == 0 {
if !match && len(parentMatched) == 0 {
if parentPath := filepath.Dir(file); parentPath != "." {
parentPathDirs := strings.Split(parentPath, string(os.PathSeparator))
// Check to see if the pattern matches one of our parent dirs.

View file

@ -465,6 +465,30 @@ func TestMatches(t *testing.T) {
check(pm, test.text, test.pass, desc)
}
})
t.Run("MatchesUsingParentResultsNoContext", func(t *testing.T) {
check := func(pm *PatternMatcher, text string, pass bool, desc string) {
res, _, _ := pm.MatchesUsingParentResults(text, MatchInfo{})
assert.Check(t, is.Equal(pass, res), desc)
}
for _, test := range tests {
desc := fmt.Sprintf("pattern=%q text=%q", test.pattern, test.text)
pm, err := NewPatternMatcher([]string{test.pattern})
assert.NilError(t, err, desc)
check(pm, test.text, test.pass, desc)
}
for _, test := range multiPatternTests {
desc := fmt.Sprintf("pattern=%q text=%q", test.patterns, test.text)
pm, err := NewPatternMatcher(test.patterns)
assert.NilError(t, err, desc)
check(pm, test.text, test.pass, desc)
}
})
}
func TestCleanPatterns(t *testing.T) {