-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support exclude patterns on Windows (#1228)
- Loading branch information
Showing
3 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package source | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_crossPlatformExclusions(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
root string | ||
path string | ||
exclude string | ||
match bool | ||
}{ | ||
{ | ||
desc: "windows doublestar", | ||
root: "C:\\User\\stuff", | ||
path: "C:\\User\\stuff\\thing.txt", | ||
exclude: "**/*.txt", | ||
match: true, | ||
}, | ||
{ | ||
desc: "windows relative", | ||
root: "C:\\User\\stuff", | ||
path: "C:\\User\\stuff\\thing.txt", | ||
exclude: "./*.txt", | ||
match: true, | ||
}, | ||
{ | ||
desc: "windows one level", | ||
root: "C:\\User\\stuff", | ||
path: "C:\\User\\stuff\\thing.txt", | ||
exclude: "*/*.txt", | ||
match: false, | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
t.Run(test.desc, func(t *testing.T) { | ||
fns, err := getDirectoryExclusionFunctions(test.root, []string{test.exclude}) | ||
require.NoError(t, err) | ||
|
||
for _, f := range fns { | ||
result := f(test.path, nil) | ||
require.Equal(t, test.match, result) | ||
} | ||
}) | ||
} | ||
} |