@@ -522,7 +522,8 @@ func (t *tester) registerTests() {
522
522
heading : "GOOS=ios on darwin/amd64" ,
523
523
fn : func (dt * distTest ) error {
524
524
cmd := t .addCmd (dt , "src" , t .goTest (), t .timeout (300 ), "-run=SystemRoots" , "crypto/x509" )
525
- cmd .Env = append (os .Environ (), "GOOS=ios" , "CGO_ENABLED=1" )
525
+ setEnv (cmd , "GOOS" , "ios" )
526
+ setEnv (cmd , "CGO_ENABLED" , "1" )
526
527
return nil
527
528
},
528
529
})
@@ -542,7 +543,7 @@ func (t *tester) registerTests() {
542
543
cmd := t .addCmd (dt , "src" , t .goTest (), t .timeout (300 ), "runtime" , "-cpu=1,2,4" , "-quick" )
543
544
// We set GOMAXPROCS=2 in addition to -cpu=1,2,4 in order to test runtime bootstrap code,
544
545
// creation of first goroutines and first garbage collections in the parallel setting.
545
- cmd . Env = append ( os . Environ () , "GOMAXPROCS= 2" )
546
+ setEnv ( cmd , "GOMAXPROCS" , " 2" )
546
547
return nil
547
548
},
548
549
})
@@ -563,7 +564,7 @@ func (t *tester) registerTests() {
563
564
return nil
564
565
}
565
566
cmd := exec .Command ("go" , "test" )
566
- cmd . Dir = filepath .Join (os .Getenv ("GOROOT" ), "src/cmd/go/testdata/testterminal18153" )
567
+ setDir ( cmd , filepath .Join (os .Getenv ("GOROOT" ), "src/cmd/go/testdata/testterminal18153" ) )
567
568
cmd .Stdout = os .Stdout
568
569
cmd .Stderr = os .Stderr
569
570
return cmd .Run ()
@@ -600,16 +601,13 @@ func (t *tester) registerTests() {
600
601
return err
601
602
}
602
603
603
- // Run `go test fmt` in the moved GOROOT.
604
+ // Run `go test fmt` in the moved GOROOT, without explicitly setting
605
+ // GOROOT in the environment. The 'go' command should find itself.
604
606
cmd := exec .Command (filepath .Join (moved , "bin" , "go" ), "test" , "fmt" )
605
607
cmd .Stdout = os .Stdout
606
608
cmd .Stderr = os .Stderr
607
- // Don't set GOROOT in the environment.
608
- for _ , e := range os .Environ () {
609
- if ! strings .HasPrefix (e , "GOROOT=" ) && ! strings .HasPrefix (e , "GOCACHE=" ) {
610
- cmd .Env = append (cmd .Env , e )
611
- }
612
- }
609
+ unsetEnv (cmd , "GOROOT" )
610
+ unsetEnv (cmd , "GOCACHE" ) // TODO(bcmills): ...why‽
613
611
err := cmd .Run ()
614
612
615
613
if rerr := os .Rename (moved , goroot ); rerr != nil {
@@ -736,11 +734,9 @@ func (t *tester) registerTests() {
736
734
heading : "../misc/swig/callback" ,
737
735
fn : func (dt * distTest ) error {
738
736
cmd := t .addCmd (dt , "misc/swig/callback" , t .goTest ())
739
- cmd .Env = append (os .Environ (),
740
- "CGO_CFLAGS=-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" ,
741
- "CGO_CXXFLAGS=-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" ,
742
- "CGO_LDFLAGS=-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" ,
743
- )
737
+ setEnv (cmd , "CGO_CFLAGS" , "-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" )
738
+ setEnv (cmd , "CGO_CXXFLAGS" , "-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" )
739
+ setEnv (cmd , "CGO_LDFLAGS" , "-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" )
744
740
return nil
745
741
},
746
742
},
@@ -892,9 +888,9 @@ func (t *tester) registerSeqTest(name, dirBanner string, cmdline ...interface{})
892
888
func (t * tester ) bgDirCmd (dir , bin string , args ... string ) * exec.Cmd {
893
889
cmd := exec .Command (bin , args ... )
894
890
if filepath .IsAbs (dir ) {
895
- cmd . Dir = dir
891
+ setDir ( cmd , dir )
896
892
} else {
897
- cmd . Dir = filepath .Join (goroot , dir )
893
+ setDir ( cmd , filepath .Join (goroot , dir ) )
898
894
}
899
895
return cmd
900
896
}
@@ -1132,7 +1128,8 @@ func (t *tester) runHostTest(dir, pkg string) error {
1132
1128
defer os .Remove (f .Name ())
1133
1129
1134
1130
cmd := t .dirCmd (dir , t .goTest (), "-c" , "-o" , f .Name (), pkg )
1135
- cmd .Env = append (os .Environ (), "GOARCH=" + gohostarch , "GOOS=" + gohostos )
1131
+ setEnv (cmd , "GOARCH" , gohostarch )
1132
+ setEnv (cmd , "GOOS" , gohostos )
1136
1133
if err := cmd .Run (); err != nil {
1137
1134
return err
1138
1135
}
@@ -1141,15 +1138,15 @@ func (t *tester) runHostTest(dir, pkg string) error {
1141
1138
1142
1139
func (t * tester ) cgoTest (dt * distTest ) error {
1143
1140
cmd := t .addCmd (dt , "misc/cgo/test" , t .goTest ())
1144
- cmd . Env = append ( os . Environ () , "GOFLAGS= -ldflags=-linkmode=auto" )
1141
+ setEnv ( cmd , "GOFLAGS" , " -ldflags=-linkmode=auto" )
1145
1142
1146
1143
// Skip internal linking cases on linux/arm64 to support GCC-9.4 and above.
1147
1144
// See issue #39466.
1148
1145
skipInternalLink := goarch == "arm64" && goos == "linux"
1149
1146
1150
1147
if t .internalLink () && ! skipInternalLink {
1151
1148
cmd := t .addCmd (dt , "misc/cgo/test" , t .goTest (), "-tags=internal" )
1152
- cmd . Env = append ( os . Environ () , "GOFLAGS= -ldflags=-linkmode=internal" )
1149
+ setEnv ( cmd , "GOFLAGS" , " -ldflags=-linkmode=internal" )
1153
1150
}
1154
1151
1155
1152
pair := gohostos + "-" + goarch
@@ -1161,9 +1158,9 @@ func (t *tester) cgoTest(dt *distTest) error {
1161
1158
break
1162
1159
}
1163
1160
cmd := t .addCmd (dt , "misc/cgo/test" , t .goTest ())
1164
- cmd . Env = append ( os . Environ () , "GOFLAGS= -ldflags=-linkmode=external" )
1161
+ setEnv ( cmd , "GOFLAGS" , " -ldflags=-linkmode=external" )
1165
1162
1166
- cmd = t .addCmd (dt , "misc/cgo/test" , t .goTest (), "-ldflags" , "-linkmode=external -s" )
1163
+ t .addCmd (dt , "misc/cgo/test" , t .goTest (), "-ldflags" , "-linkmode=external -s" )
1167
1164
1168
1165
if t .supportedBuildmode ("pie" ) {
1169
1166
t .addCmd (dt , "misc/cgo/test" , t .goTest (), "-buildmode=pie" )
@@ -1181,10 +1178,10 @@ func (t *tester) cgoTest(dt *distTest) error {
1181
1178
"openbsd-386" , "openbsd-amd64" , "openbsd-arm" , "openbsd-arm64" , "openbsd-mips64" :
1182
1179
1183
1180
cmd := t .addCmd (dt , "misc/cgo/test" , t .goTest ())
1184
- cmd . Env = append ( os . Environ () , "GOFLAGS= -ldflags=-linkmode=external" )
1181
+ setEnv ( cmd , "GOFLAGS" , " -ldflags=-linkmode=external" )
1185
1182
// cgo should be able to cope with both -g arguments and colored
1186
1183
// diagnostics.
1187
- cmd . Env = append (cmd . Env , "CGO_CFLAGS= -g0 -fdiagnostics-color" )
1184
+ setEnv (cmd , "CGO_CFLAGS" , " -g0 -fdiagnostics-color" )
1188
1185
1189
1186
t .addCmd (dt , "misc/cgo/testtls" , t .goTest (), "-ldflags" , "-linkmode=auto" )
1190
1187
t .addCmd (dt , "misc/cgo/testtls" , t .goTest (), "-ldflags" , "-linkmode=external" )
@@ -1217,7 +1214,7 @@ func (t *tester) cgoTest(dt *distTest) error {
1217
1214
// than -static in -extldflags, so test both.
1218
1215
// See issue #16651.
1219
1216
cmd := t .addCmd (dt , "misc/cgo/test" , t .goTest (), "-tags=static" )
1220
- cmd . Env = append ( os . Environ () , "CGO_LDFLAGS= -static -pthread" )
1217
+ setEnv ( cmd , "CGO_LDFLAGS" , " -static -pthread" )
1221
1218
}
1222
1219
}
1223
1220
@@ -1456,7 +1453,7 @@ func (t *tester) raceTest(dt *distTest) error {
1456
1453
// We shouldn't need to redo all of misc/cgo/test too.
1457
1454
// The race buildler will take care of this.
1458
1455
// cmd := t.addCmd(dt, "misc/cgo/test", t.goTest(), "-race")
1459
- // cmd.Env = append(os.Environ() , "GOTRACEBACK= 2")
1456
+ // setEnv(cmd , "GOTRACEBACK", " 2")
1460
1457
}
1461
1458
if t .extLink () {
1462
1459
// Test with external linking; see issue 9133.
@@ -1486,7 +1483,8 @@ func (t *tester) testDirTest(dt *distTest, shard, shards int) error {
1486
1483
})
1487
1484
1488
1485
cmd := t .dirCmd ("test" , "go" , "build" , "-o" , runtest .exe , "run.go" )
1489
- cmd .Env = append (os .Environ (), "GOOS=" + gohostos , "GOARCH=" + gohostarch )
1486
+ setEnv (cmd , "GOOS" , gohostos )
1487
+ setEnv (cmd , "GOARCH" , gohostarch )
1490
1488
runtest .err = cmd .Run ()
1491
1489
})
1492
1490
if runtest .err != nil {
@@ -1650,7 +1648,7 @@ func (t *tester) runPrecompiledStdTest(timeout time.Duration) error {
1650
1648
bin := t .prebuiltGoPackageTestBinary ()
1651
1649
fmt .Fprintf (os .Stderr , "# %s: using pre-built %s...\n " , stdMatches [0 ], bin )
1652
1650
cmd := exec .Command (bin , "-test.short=" + short (), "-test.timeout=" + timeout .String ())
1653
- cmd . Dir = filepath .Dir (bin )
1651
+ setDir ( cmd , filepath .Dir (bin ) )
1654
1652
cmd .Stdout = os .Stdout
1655
1653
cmd .Stderr = os .Stderr
1656
1654
if err := cmd .Start (); err != nil {
0 commit comments