@@ -426,7 +426,7 @@ func (t *tester) registerTests() {
426
426
cmd := t .addCmd (dt , "src" , "go" , "test" , "-short" , t .timeout (300 ), t .tags (), "runtime" , "-cpu=1,2,4" )
427
427
// We set GOMAXPROCS=2 in addition to -cpu=1,2,4 in order to test runtime bootstrap code,
428
428
// creation of first goroutines and first garbage collections in the parallel setting.
429
- cmd .Env = mergeEnvLists ([] string { "GOMAXPROCS=2" }, os .Environ ())
429
+ cmd .Env = append ( os .Environ (), "GOMAXPROCS=2" )
430
430
return nil
431
431
},
432
432
})
@@ -807,18 +807,17 @@ func (t *tester) registerHostTest(name, heading, dir, pkg string) {
807
807
}
808
808
809
809
func (t * tester ) runHostTest (dir , pkg string ) error {
810
- env := mergeEnvLists ([]string {"GOARCH=" + t .gohostarch , "GOOS=" + t .gohostos }, os .Environ ())
811
810
defer os .Remove (filepath .Join (t .goroot , dir , "test.test" ))
812
811
cmd := t .dirCmd (dir , "go" , "test" , t .tags (), "-c" , "-o" , "test.test" , pkg )
813
- cmd .Env = env
812
+ cmd .Env = append ( os . Environ (), "GOARCH=" + t . gohostarch , "GOOS=" + t . gohostos )
814
813
if err := cmd .Run (); err != nil {
815
814
return err
816
815
}
817
816
return t .dirCmd (dir , "./test.test" ).Run ()
818
817
}
819
818
820
819
func (t * tester ) cgoTest (dt * distTest ) error {
821
- env := mergeEnvLists ([] string { "GOTRACEBACK=2" }, os .Environ ())
820
+ env := append ( os .Environ (), "GOTRACEBACK=2" )
822
821
823
822
cmd := t .addCmd (dt , "misc/cgo/test" , "go" , "test" , t .tags (), "-ldflags" , "-linkmode=auto" , t .runFlag ("" ))
824
823
cmd .Env = env
@@ -1053,12 +1052,12 @@ func (t *tester) cgoTestSO(dt *distTest, testpath string) error {
1053
1052
if t .goos == "darwin" {
1054
1053
s = "DYLD_LIBRARY_PATH"
1055
1054
}
1056
- cmd .Env = mergeEnvLists ([] string { s + "=." }, os . Environ () )
1055
+ cmd .Env = append ( os . Environ (), s + "=." )
1057
1056
1058
1057
// On FreeBSD 64-bit architectures, the 32-bit linker looks for
1059
1058
// different environment variables.
1060
1059
if t .goos == "freebsd" && t .gohostarch == "386" {
1061
- cmd .Env = mergeEnvLists ([] string { "LD_32_LIBRARY_PATH=." }, cmd . Env )
1060
+ cmd .Env = append ( cmd . Env , "LD_32_LIBRARY_PATH=." )
1062
1061
}
1063
1062
}
1064
1063
return cmd .Run ()
@@ -1097,9 +1096,8 @@ func (t *tester) raceTest(dt *distTest) error {
1097
1096
// TODO(iant): Figure out how to catch this.
1098
1097
// t.addCmd(dt, "src", "go", "test", "-race", "-run=TestParallelTest", "cmd/go")
1099
1098
if t .cgoEnabled {
1100
- env := mergeEnvLists ([]string {"GOTRACEBACK=2" }, os .Environ ())
1101
1099
cmd := t .addCmd (dt , "misc/cgo/test" , "go" , "test" , "-race" , "-short" , t .runFlag ("" ))
1102
- cmd .Env = env
1100
+ cmd .Env = append ( os . Environ (), "GOTRACEBACK=2" )
1103
1101
}
1104
1102
if t .extLink () {
1105
1103
// Test with external linking; see issue 9133.
@@ -1118,7 +1116,7 @@ func (t *tester) testDirTest(dt *distTest, shard, shards int) error {
1118
1116
runtest .Do (func () {
1119
1117
const exe = "runtest.exe" // named exe for Windows, but harmless elsewhere
1120
1118
cmd := t .dirCmd ("test" , "go" , "build" , "-o" , exe , "run.go" )
1121
- cmd .Env = mergeEnvLists ([] string { "GOOS=" + t .gohostos , "GOARCH=" + t .gohostarch , "GOMAXPROCS=" }, os . Environ () )
1119
+ cmd .Env = append ( os . Environ (), "GOOS=" + t .gohostos , "GOARCH=" + t .gohostarch , "GOMAXPROCS=" )
1122
1120
runtest .exe = filepath .Join (cmd .Dir , exe )
1123
1121
if err := cmd .Run (); err != nil {
1124
1122
runtest .err = err
@@ -1141,24 +1139,6 @@ func (t *tester) testDirTest(dt *distTest, shard, shards int) error {
1141
1139
return nil
1142
1140
}
1143
1141
1144
- // mergeEnvLists merges the two environment lists such that
1145
- // variables with the same name in "in" replace those in "out".
1146
- // out may be mutated.
1147
- func mergeEnvLists (in , out []string ) []string {
1148
- NextVar:
1149
- for _ , inkv := range in {
1150
- k := strings .SplitAfterN (inkv , "=" , 2 )[0 ]
1151
- for i , outkv := range out {
1152
- if strings .HasPrefix (outkv , k ) {
1153
- out [i ] = inkv
1154
- continue NextVar
1155
- }
1156
- }
1157
- out = append (out , inkv )
1158
- }
1159
- return out
1160
- }
1161
-
1162
1142
// cgoPackages is the standard packages that use cgo.
1163
1143
var cgoPackages = []string {
1164
1144
"crypto/x509" ,
0 commit comments