From dddd1dd481c98c85c1e2b05ff51679db4338d6e5 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 12 May 2017 07:11:53 -0700 Subject: [PATCH] cmd/go: fix TestExecutableGOROOT on Windows On Windows the drive letter is sometime "c:" and sometimes "C:". Fixes #20336. Change-Id: I38c86999af9522c51470d60016729d41cfec6b25 Reviewed-on: https://go-review.googlesource.com/43390 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/go/go_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 041773ba91..093119e03e 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -3974,6 +3974,13 @@ func TestExecutableGOROOT(t *testing.T) { return strings.TrimSpace(string(out)) } + // Filenames are case insensitive on Windows. + // There should probably be a path/filepath function for this. + equal := func(a, b string) bool { return a == b } + if runtime.GOOS == "windows" { + equal = strings.EqualFold + } + // macOS uses a symlink for /tmp. resolvedTestGOROOT, err := filepath.EvalSymlinks(testGOROOT) if err != nil { @@ -3982,13 +3989,13 @@ func TestExecutableGOROOT(t *testing.T) { // Missing GOROOT/pkg/tool, the go tool should fall back to // its default path. - if got, want := goroot(newGoTool), resolvedTestGOROOT; got != want { + if got, want := goroot(newGoTool), resolvedTestGOROOT; !equal(got, want) { t.Fatalf("%s env GOROOT = %q, want %q", newGoTool, got, want) } // Now the executable's path looks like a GOROOT. tg.tempDir("newgoroot/pkg/tool") - if got, want := goroot(newGoTool), tg.path("newgoroot"); got != want { + if got, want := goroot(newGoTool), tg.path("newgoroot"); !equal(got, want) { t.Fatalf("%s env GOROOT = %q with pkg/tool, want %q", newGoTool, got, want) } @@ -4003,7 +4010,7 @@ func TestExecutableGOROOT(t *testing.T) { t.Fatalf("could not eval newgoroot symlinks: %v", err) } - if got, want := goroot(symGoTool), resolvedNewGOROOT; got != want { + if got, want := goroot(symGoTool), resolvedNewGOROOT; !equal(got, want) { t.Fatalf("%s env GOROOT = %q, want %q", symGoTool, got, want) } } -- 2.50.0