@@ -509,7 +509,8 @@ func (t *tester) registerTests() {
509
509
heading : "GOOS=ios on darwin/amd64" ,
510
510
fn : func (dt * distTest ) error {
511
511
cmd := t .addCmd (dt , "src" , t .goTest (), t .timeout (300 ), "-run=SystemRoots" , "crypto/x509" )
512
- cmd .Env = append (os .Environ (), "GOOS=ios" , "CGO_ENABLED=1" )
512
+ setEnv (cmd , "GOOS" , "ios" )
513
+ setEnv (cmd , "CGO_ENABLED" , "1" )
513
514
return nil
514
515
},
515
516
})
@@ -529,7 +530,7 @@ func (t *tester) registerTests() {
529
530
cmd := t .addCmd (dt , "src" , t .goTest (), t .timeout (300 ), "runtime" , "-cpu=1,2,4" , "-quick" )
530
531
// We set GOMAXPROCS=2 in addition to -cpu=1,2,4 in order to test runtime bootstrap code,
531
532
// creation of first goroutines and first garbage collections in the parallel setting.
532
- cmd . Env = append ( os . Environ () , "GOMAXPROCS= 2" )
533
+ setEnv ( cmd , "GOMAXPROCS" , " 2" )
533
534
return nil
534
535
},
535
536
})
@@ -550,7 +551,7 @@ func (t *tester) registerTests() {
550
551
return nil
551
552
}
552
553
cmd := exec .Command ("go" , "test" )
553
- cmd . Dir = filepath .Join (os .Getenv ("GOROOT" ), "src/cmd/go/testdata/testterminal18153" )
554
+ setDir ( cmd , filepath .Join (os .Getenv ("GOROOT" ), "src/cmd/go/testdata/testterminal18153" ) )
554
555
cmd .Stdout = os .Stdout
555
556
cmd .Stderr = os .Stderr
556
557
return cmd .Run ()
@@ -587,16 +588,13 @@ func (t *tester) registerTests() {
587
588
return err
588
589
}
589
590
590
- // Run `go test fmt` in the moved GOROOT.
591
+ // Run `go test fmt` in the moved GOROOT, without explicitly setting
592
+ // GOROOT in the environment. The 'go' command should find itself.
591
593
cmd := exec .Command (filepath .Join (moved , "bin" , "go" ), "test" , "fmt" )
592
594
cmd .Stdout = os .Stdout
593
595
cmd .Stderr = os .Stderr
594
- // Don't set GOROOT in the environment.
595
- for _ , e := range os .Environ () {
596
- if ! strings .HasPrefix (e , "GOROOT=" ) && ! strings .HasPrefix (e , "GOCACHE=" ) {
597
- cmd .Env = append (cmd .Env , e )
598
- }
599
- }
596
+ unsetEnv (cmd , "GOROOT" )
597
+ unsetEnv (cmd , "GOCACHE" ) // TODO(bcmills): ...why‽
600
598
err := cmd .Run ()
601
599
602
600
if rerr := os .Rename (moved , goroot ); rerr != nil {
@@ -723,11 +721,9 @@ func (t *tester) registerTests() {
723
721
heading : "../misc/swig/callback" ,
724
722
fn : func (dt * distTest ) error {
725
723
cmd := t .addCmd (dt , "misc/swig/callback" , t .goTest ())
726
- cmd .Env = append (os .Environ (),
727
- "CGO_CFLAGS=-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" ,
728
- "CGO_CXXFLAGS=-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" ,
729
- "CGO_LDFLAGS=-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" ,
730
- )
724
+ setEnv (cmd , "CGO_CFLAGS" , "-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" )
725
+ setEnv (cmd , "CGO_CXXFLAGS" , "-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" )
726
+ setEnv (cmd , "CGO_LDFLAGS" , "-flto -Wno-lto-type-mismatch -Wno-unknown-warning-option" )
731
727
return nil
732
728
},
733
729
},
@@ -879,9 +875,9 @@ func (t *tester) registerSeqTest(name, dirBanner string, cmdline ...interface{})
879
875
func (t * tester ) bgDirCmd (dir , bin string , args ... string ) * exec.Cmd {
880
876
cmd := exec .Command (bin , args ... )
881
877
if filepath .IsAbs (dir ) {
882
- cmd . Dir = dir
878
+ setDir ( cmd , dir )
883
879
} else {
884
- cmd . Dir = filepath .Join (goroot , dir )
880
+ setDir ( cmd , filepath .Join (goroot , dir ) )
885
881
}
886
882
return cmd
887
883
}
@@ -1114,7 +1110,8 @@ func (t *tester) runHostTest(dir, pkg string) error {
1114
1110
defer os .Remove (f .Name ())
1115
1111
1116
1112
cmd := t .dirCmd (dir , t .goTest (), "-c" , "-o" , f .Name (), pkg )
1117
- cmd .Env = append (os .Environ (), "GOARCH=" + gohostarch , "GOOS=" + gohostos )
1113
+ setEnv (cmd , "GOARCH" , gohostarch )
1114
+ setEnv (cmd , "GOOS" , gohostos )
1118
1115
if err := cmd .Run (); err != nil {
1119
1116
return err
1120
1117
}
@@ -1123,15 +1120,15 @@ func (t *tester) runHostTest(dir, pkg string) error {
1123
1120
1124
1121
func (t * tester ) cgoTest (dt * distTest ) error {
1125
1122
cmd := t .addCmd (dt , "misc/cgo/test" , t .goTest ())
1126
- cmd . Env = append ( os . Environ () , "GOFLAGS= -ldflags=-linkmode=auto" )
1123
+ setEnv ( cmd , "GOFLAGS" , " -ldflags=-linkmode=auto" )
1127
1124
1128
1125
// Skip internal linking cases on linux/arm64 to support GCC-9.4 and above.
1129
1126
// See issue #39466.
1130
1127
skipInternalLink := goarch == "arm64" && goos == "linux"
1131
1128
1132
1129
if t .internalLink () && ! skipInternalLink {
1133
1130
cmd := t .addCmd (dt , "misc/cgo/test" , t .goTest (), "-tags=internal" )
1134
- cmd . Env = append ( os . Environ () , "GOFLAGS= -ldflags=-linkmode=internal" )
1131
+ setEnv ( cmd , "GOFLAGS" , " -ldflags=-linkmode=internal" )
1135
1132
}
1136
1133
1137
1134
pair := gohostos + "-" + goarch
@@ -1143,9 +1140,9 @@ func (t *tester) cgoTest(dt *distTest) error {
1143
1140
break
1144
1141
}
1145
1142
cmd := t .addCmd (dt , "misc/cgo/test" , t .goTest ())
1146
- cmd . Env = append ( os . Environ () , "GOFLAGS= -ldflags=-linkmode=external" )
1143
+ setEnv ( cmd , "GOFLAGS" , " -ldflags=-linkmode=external" )
1147
1144
1148
- cmd = t .addCmd (dt , "misc/cgo/test" , t .goTest (), "-ldflags" , "-linkmode=external -s" )
1145
+ t .addCmd (dt , "misc/cgo/test" , t .goTest (), "-ldflags" , "-linkmode=external -s" )
1149
1146
1150
1147
if t .supportedBuildmode ("pie" ) {
1151
1148
t .addCmd (dt , "misc/cgo/test" , t .goTest (), "-buildmode=pie" )
@@ -1163,10 +1160,10 @@ func (t *tester) cgoTest(dt *distTest) error {
1163
1160
"openbsd-386" , "openbsd-amd64" , "openbsd-arm" , "openbsd-arm64" , "openbsd-mips64" :
1164
1161
1165
1162
cmd := t .addCmd (dt , "misc/cgo/test" , t .goTest ())
1166
- cmd . Env = append ( os . Environ () , "GOFLAGS= -ldflags=-linkmode=external" )
1163
+ setEnv ( cmd , "GOFLAGS" , " -ldflags=-linkmode=external" )
1167
1164
// cgo should be able to cope with both -g arguments and colored
1168
1165
// diagnostics.
1169
- cmd . Env = append (cmd . Env , "CGO_CFLAGS= -g0 -fdiagnostics-color" )
1166
+ setEnv (cmd , "CGO_CFLAGS" , " -g0 -fdiagnostics-color" )
1170
1167
1171
1168
t .addCmd (dt , "misc/cgo/testtls" , t .goTest (), "-ldflags" , "-linkmode=auto" )
1172
1169
t .addCmd (dt , "misc/cgo/testtls" , t .goTest (), "-ldflags" , "-linkmode=external" )
@@ -1199,7 +1196,7 @@ func (t *tester) cgoTest(dt *distTest) error {
1199
1196
// than -static in -extldflags, so test both.
1200
1197
// See issue #16651.
1201
1198
cmd := t .addCmd (dt , "misc/cgo/test" , t .goTest (), "-tags=static" )
1202
- cmd . Env = append ( os . Environ () , "CGO_LDFLAGS= -static -pthread" )
1199
+ setEnv ( cmd , "CGO_LDFLAGS" , " -static -pthread" )
1203
1200
}
1204
1201
}
1205
1202
@@ -1438,7 +1435,7 @@ func (t *tester) raceTest(dt *distTest) error {
1438
1435
// We shouldn't need to redo all of misc/cgo/test too.
1439
1436
// The race buildler will take care of this.
1440
1437
// cmd := t.addCmd(dt, "misc/cgo/test", t.goTest(), "-race")
1441
- // cmd.Env = append(os.Environ() , "GOTRACEBACK= 2")
1438
+ // setEnv(cmd , "GOTRACEBACK", " 2")
1442
1439
}
1443
1440
if t .extLink () {
1444
1441
// Test with external linking; see issue 9133.
@@ -1468,7 +1465,8 @@ func (t *tester) testDirTest(dt *distTest, shard, shards int) error {
1468
1465
})
1469
1466
1470
1467
cmd := t .dirCmd ("test" , "go" , "build" , "-o" , runtest .exe , "run.go" )
1471
- cmd .Env = append (os .Environ (), "GOOS=" + gohostos , "GOARCH=" + gohostarch )
1468
+ setEnv (cmd , "GOOS" , gohostos )
1469
+ setEnv (cmd , "GOARCH" , gohostarch )
1472
1470
runtest .err = cmd .Run ()
1473
1471
})
1474
1472
if runtest .err != nil {
@@ -1632,7 +1630,7 @@ func (t *tester) runPrecompiledStdTest(timeout time.Duration) error {
1632
1630
bin := t .prebuiltGoPackageTestBinary ()
1633
1631
fmt .Fprintf (os .Stderr , "# %s: using pre-built %s...\n " , stdMatches [0 ], bin )
1634
1632
cmd := exec .Command (bin , "-test.short=" + short (), "-test.timeout=" + timeout .String ())
1635
- cmd . Dir = filepath .Dir (bin )
1633
+ setDir ( cmd , filepath .Dir (bin ) )
1636
1634
cmd .Stdout = os .Stdout
1637
1635
cmd .Stderr = os .Stderr
1638
1636
if err := cmd .Start (); err != nil {
0 commit comments