Skip to content

Commit d740698

Browse files
committed
fastwalk: fix tests for Windows/MSYS
This commit fixes the tests so that they work when ran under MSYS on Windows (and Git Bash). The issue is that on MSYS we default to using forward slashes so direct path comparisons failed - the fix is to normalize the paths before comparison.
1 parent 6965c86 commit d740698

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fastwalk_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ func testFastWalkConf(t *testing.T, conf *fastwalk.Config, files map[string]stri
135135
}
136136
mu.Lock()
137137
defer mu.Unlock()
138+
// Normalize paths for Windows
139+
path = filepath.FromSlash(path)
140+
tempdir = filepath.FromSlash(tempdir)
138141
if !strings.HasPrefix(path, tempdir) {
139142
t.Errorf("bogus prefix on %q, expect %q", path, tempdir)
140143
}
@@ -457,6 +460,9 @@ func TestFastWalk_WindowsRootPaths(t *testing.T) {
457460
//
458461
// https://github.com/charlievieth/fastwalk/issues/37
459462
t.Run("FullyQualified", func(t *testing.T) {
463+
if _, ok := os.LookupEnv("MSYSTEM"); ok {
464+
t.Skip("test not supported when running under MSYS (or Git Bash)")
465+
}
460466
root := vol + `\`
461467
if sameFile(t, pwd, root) {
462468
t.Skipf("the current working directory (%s) is the disk root: %s", pwd, root)
@@ -561,7 +567,7 @@ func TestFastWalk_WindowsRootPaths(t *testing.T) {
561567
if path == vol {
562568
continue // Clean("C:") => "C:."
563569
}
564-
if s := filepath.Clean(path); s != path {
570+
if s := filepath.Clean(path); s != filepath.FromSlash(path) {
565571
t.Errorf(`filepath.Clean("%s") == "%s"`, path, s)
566572
}
567573
}

0 commit comments

Comments
 (0)