Skip to content

Commit 03410f6

Browse files
committed
runtime: fix TestFixedGOROOT to properly restore the GOROOT env var after test
Otherwise subsequent tests won't see any modified GOROOT. With this CL I can move my GOROOT, set GOROOT to the new location, and the runtime tests pass. Previously the crash_tests would instead look for the GOROOT baked into the binary, instead of the env var: --- FAIL: TestGcSys (0.01s) crash_test.go:92: building source: exit status 2 go: cannot find GOROOT directory: /home/bradfitz/go --- FAIL: TestGCFairness (0.01s) crash_test.go:92: building source: exit status 2 go: cannot find GOROOT directory: /home/bradfitz/go --- FAIL: TestGdbPython (0.07s) runtime-gdb_test.go:64: building source exit status 2 go: cannot find GOROOT directory: /home/bradfitz/go --- FAIL: TestLargeStringConcat (0.01s) crash_test.go:92: building source: exit status 2 go: cannot find GOROOT directory: /home/bradfitz/go Update #10029 Change-Id: If91be0f04d3acdcf39a9e773a4e7905a446bc477 Reviewed-on: https://go-review.googlesource.com/10685 Reviewed-by: Andrew Gerrand <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]>
1 parent 1e48683 commit 03410f6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/runtime/env_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ func TestFixedGOROOT(t *testing.T) {
1515
t.Skipf("skipping plan9, it is inconsistent by allowing GOROOT to be updated by Setenv")
1616
}
1717

18+
// Restore both the real GOROOT environment variable, and runtime's copies:
19+
if orig, ok := syscall.Getenv("GOROOT"); ok {
20+
defer syscall.Setenv("GOROOT", orig)
21+
} else {
22+
defer syscall.Unsetenv("GOROOT")
23+
}
1824
envs := runtime.Envs()
1925
oldenvs := append([]string{}, envs...)
2026
defer runtime.SetEnvs(oldenvs)

0 commit comments

Comments
 (0)