Commit acc56909 authored by Ian Lance Taylor's avatar Ian Lance Taylor

cmd/go: fix TestExecutableGOROOT if GOROOT is a symlink

Fixes #20365.

Change-Id: If1a4866193cff3bc836d8bbf18b6a1f5deb9808d
Reviewed-on: https://go-review.googlesource.com/43550
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarAlessandro Arzilli <alessandro.arzilli@gmail.com>
parent 0fd7de49
...@@ -3969,9 +3969,13 @@ func TestExecutableGOROOT(t *testing.T) { ...@@ -3969,9 +3969,13 @@ func TestExecutableGOROOT(t *testing.T) {
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
t.Fatalf("copied go tool failed %v: %s", err, out) t.Fatalf("copied go tool failed %v: %s", err, out)
return ""
} }
return strings.TrimSpace(string(out)) root := strings.TrimSpace(string(out))
resolved, err := filepath.EvalSymlinks(root)
if err != nil {
t.Fatalf("EvalSymlinks(%q) failed: %v", root, err)
}
return resolved
} }
// Filenames are case insensitive on Windows. // Filenames are case insensitive on Windows.
...@@ -3995,7 +3999,11 @@ func TestExecutableGOROOT(t *testing.T) { ...@@ -3995,7 +3999,11 @@ func TestExecutableGOROOT(t *testing.T) {
// Now the executable's path looks like a GOROOT. // Now the executable's path looks like a GOROOT.
tg.tempDir("newgoroot/pkg/tool") tg.tempDir("newgoroot/pkg/tool")
if got, want := goroot(newGoTool), tg.path("newgoroot"); !equal(got, want) { resolvedNewGOROOT, err := filepath.EvalSymlinks(tg.path("newgoroot"))
if err != nil {
t.Fatalf("could not eval newgoroot symlinks: %v", err)
}
if got, want := goroot(newGoTool), resolvedNewGOROOT; !equal(got, want) {
t.Fatalf("%s env GOROOT = %q with pkg/tool, want %q", newGoTool, got, want) t.Fatalf("%s env GOROOT = %q with pkg/tool, want %q", newGoTool, got, want)
} }
...@@ -4005,11 +4013,6 @@ func TestExecutableGOROOT(t *testing.T) { ...@@ -4005,11 +4013,6 @@ func TestExecutableGOROOT(t *testing.T) {
symGoTool := tg.path("notgoroot/bin/go" + exeSuffix) symGoTool := tg.path("notgoroot/bin/go" + exeSuffix)
tg.must(os.Symlink(newGoTool, symGoTool)) tg.must(os.Symlink(newGoTool, symGoTool))
resolvedNewGOROOT, err := filepath.EvalSymlinks(tg.path("newgoroot"))
if err != nil {
t.Fatalf("could not eval newgoroot symlinks: %v", err)
}
if got, want := goroot(symGoTool), resolvedNewGOROOT; !equal(got, want) { if got, want := goroot(symGoTool), resolvedNewGOROOT; !equal(got, want) {
t.Fatalf("%s env GOROOT = %q, want %q", symGoTool, got, want) t.Fatalf("%s env GOROOT = %q, want %q", symGoTool, got, want)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment