1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 func TestFixedGOROOT(t
*testing
.T
) {
14 if runtime
.GOOS
== "plan9" {
15 t
.Skipf("skipping plan9, it is inconsistent by allowing GOROOT to be updated by Setenv")
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
)
22 defer syscall
.Unsetenv("GOROOT")
24 envs
:= runtime
.Envs()
25 oldenvs
:= append([]string{}, envs
...)
26 defer runtime
.SetEnvs(oldenvs
)
28 // attempt to reuse existing envs backing array.
29 want
:= runtime
.GOROOT()
30 runtime
.SetEnvs(append(envs
[:0], "GOROOT="+want
))
32 if got
:= runtime
.GOROOT(); got
!= want
{
33 t
.Errorf(`initial runtime.GOROOT()=%q, want %q`, got
, want
)
35 if err
:= syscall
.Setenv("GOROOT", "/os"); err
!= nil {
38 if got
:= runtime
.GOROOT(); got
!= want
{
39 t
.Errorf(`after setenv runtime.GOROOT()=%q, want %q`, got
, want
)
41 if err
:= syscall
.Unsetenv("GOROOT"); err
!= nil {
44 if got
:= runtime
.GOROOT(); got
!= want
{
45 t
.Errorf(`after unsetenv runtime.GOROOT()=%q, want %q`, got
, want
)