Skip to content

Commit

Permalink
testscript: propagate GORACE like we already do with GOCOVERDIR
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mvdan committed Sep 26, 2023
1 parent b6a9d8b commit 32ae337
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions testscript/testscript.go
Expand Up @@ -444,16 +444,27 @@ func (ts *TestScript) setup() string {
"/=" + string(os.PathSeparator),
":=" + string(os.PathListSeparator),
"$=$",

// If we are collecting coverage profiles for merging into the main one,
// ensure the environment variable is forwarded to sub-processes.
"GOCOVERDIR=" + os.Getenv("GOCOVERDIR"),
},
WorkDir: ts.workdir,
Values: make(map[interface{}]interface{}),
Cd: ts.workdir,
ts: ts,
}

// These env vars affect how a Go program behaves at run-time;
// If the user or `go test` wrapper set them, we should propagate them
// so that sub-process commands run via the test binary see them as well.
for _, name := range []string{
// If we are collecting coverage profiles, e.g. `go test -coverprofile`.
"GOCOVERDIR",
// If the user set GORACE when running a command like `go test -race`,
// such as GORACE=atexit_sleep_ms=10 to avoid the default 1s sleeps.
"GORACE",
} {
if val := os.Getenv(name); val != "" {
env.Vars = append(env.Vars, name+"="+val)
}
}
// Must preserve SYSTEMROOT on Windows: https://github.com/golang/go/issues/25513 et al
if runtime.GOOS == "windows" {
env.Vars = append(env.Vars,
Expand Down

0 comments on commit 32ae337

Please sign in to comment.