1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:46:47 -07:00

path/filepath: support multiple TestAbs runs on Windows

TestAbs modifies the absTests global variable on Windows, which makes
the test to fail if it is run more than once, i.e. executing
"go test -run ^TestAbs$ -count 2 path/filepath".

This CL fixes the issue by clipping the absTests slices before
appending more elements to it.

Change-Id: I8f1144b2f10b8fa1b847e6639c0bda7baafc2dac
Reviewed-on: https://go-review.googlesource.com/c/go/+/566396
Reviewed-by: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
qmuntal 2024-02-23 13:38:27 +01:00 committed by Quim Muntal
parent 08d9397170
commit 7db8b9e518

View File

@ -1403,6 +1403,9 @@ func TestAbs(t *testing.T) {
} }
} }
// Make sure the global absTests slice is not
// modified by multiple invocations of TestAbs.
tests := absTests
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
vol := filepath.VolumeName(root) vol := filepath.VolumeName(root)
var extra []string var extra []string
@ -1413,7 +1416,7 @@ func TestAbs(t *testing.T) {
path = vol + path path = vol + path
extra = append(extra, path) extra = append(extra, path)
} }
absTests = append(absTests, extra...) tests = append(slices.Clip(tests), extra...)
} }
err = os.Chdir(absTestDirs[0]) err = os.Chdir(absTestDirs[0])
@ -1421,7 +1424,7 @@ func TestAbs(t *testing.T) {
t.Fatal("chdir failed: ", err) t.Fatal("chdir failed: ", err)
} }
for _, path := range absTests { for _, path := range tests {
path = strings.ReplaceAll(path, "$", root) path = strings.ReplaceAll(path, "$", root)
info, err := os.Stat(path) info, err := os.Stat(path)
if err != nil { if err != nil {