...
Source file
src/runtime/env_test.go
Documentation: runtime
1
2
3
4
5 package runtime_test
6
7 import (
8 "runtime"
9 "syscall"
10 "testing"
11 )
12
13 func TestFixedGOROOT(t *testing.T) {
14
15 if orig, ok := syscall.Getenv("GOROOT"); ok {
16 defer syscall.Setenv("GOROOT", orig)
17 } else {
18 defer syscall.Unsetenv("GOROOT")
19 }
20 envs := runtime.Envs()
21 oldenvs := append([]string{}, envs...)
22 defer runtime.SetEnvs(oldenvs)
23
24
25 want := runtime.GOROOT()
26 runtime.SetEnvs(append(envs[:0], "GOROOT="+want))
27
28 if got := runtime.GOROOT(); got != want {
29 t.Errorf(`initial runtime.GOROOT()=%q, want %q`, got, want)
30 }
31 if err := syscall.Setenv("GOROOT", "/os"); err != nil {
32 t.Fatal(err)
33 }
34 if got := runtime.GOROOT(); got != want {
35 t.Errorf(`after setenv runtime.GOROOT()=%q, want %q`, got, want)
36 }
37 if err := syscall.Unsetenv("GOROOT"); err != nil {
38 t.Fatal(err)
39 }
40 if got := runtime.GOROOT(); got != want {
41 t.Errorf(`after unsetenv runtime.GOROOT()=%q, want %q`, got, want)
42 }
43 }
44
View as plain text