Skip to content

Commit 32ae337

Browse files
committed
testscript: propagate GORACE like we already do with GOCOVERDIR
Do both in a loop to deduplicate code. While here, only set them if they aren't empty; this way we don't unnecessarily pollute Vars with entries such as `GOCOVERDIR=` when they don't do anything useful.
1 parent b6a9d8b commit 32ae337

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

testscript/testscript.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,16 +444,27 @@ func (ts *TestScript) setup() string {
444444
"/=" + string(os.PathSeparator),
445445
":=" + string(os.PathListSeparator),
446446
"$=$",
447-
448-
// If we are collecting coverage profiles for merging into the main one,
449-
// ensure the environment variable is forwarded to sub-processes.
450-
"GOCOVERDIR=" + os.Getenv("GOCOVERDIR"),
451447
},
452448
WorkDir: ts.workdir,
453449
Values: make(map[interface{}]interface{}),
454450
Cd: ts.workdir,
455451
ts: ts,
456452
}
453+
454+
// These env vars affect how a Go program behaves at run-time;
455+
// If the user or `go test` wrapper set them, we should propagate them
456+
// so that sub-process commands run via the test binary see them as well.
457+
for _, name := range []string{
458+
// If we are collecting coverage profiles, e.g. `go test -coverprofile`.
459+
"GOCOVERDIR",
460+
// If the user set GORACE when running a command like `go test -race`,
461+
// such as GORACE=atexit_sleep_ms=10 to avoid the default 1s sleeps.
462+
"GORACE",
463+
} {
464+
if val := os.Getenv(name); val != "" {
465+
env.Vars = append(env.Vars, name+"="+val)
466+
}
467+
}
457468
// Must preserve SYSTEMROOT on Windows: https://github.com/golang/go/issues/25513 et al
458469
if runtime.GOOS == "windows" {
459470
env.Vars = append(env.Vars,

0 commit comments

Comments
 (0)