aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/script/scripttest/run.go
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2024-07-29 17:40:10 +0000
committerThan McIntosh <thanm@google.com>2024-07-31 13:21:14 +0000
commitb60f88d81022e4172e44aef2f0bdade87ed6916d (patch)
treea37a6115cb048aea979ad51eb12f03cf6d9116fb /src/cmd/internal/script/scripttest/run.go
parent86bec1ec198f2720c83bd232a72b800b4ea5a9f6 (diff)
downloadgo-b60f88d81022e4172e44aef2f0bdade87ed6916d.tar.xz
cmd/internal/script: new hook for adding in toolchain script conditions
Introduce a new function AddToolChainScriptConditions that augments a default "script.Cond" set with a collection of useful conditions, including godebug/goexperiment, cgo, race support, buildmode, asan, msan, and so on. Having these conditions available makes it easier to write script tests that deal with specific build-flavor corner cases. The functions backing the new conditions are helper functions migrated over from the Go command's script test setup. Updates #68606. Change-Id: I14def1115b54dc47529c983abcd2c5ea9326b9de Reviewed-on: https://go-review.googlesource.com/c/go/+/601715 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/internal/script/scripttest/run.go')
-rw-r--r--src/cmd/internal/script/scripttest/run.go12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/cmd/internal/script/scripttest/run.go b/src/cmd/internal/script/scripttest/run.go
index d2f3ed8ca9..29eb6f88f2 100644
--- a/src/cmd/internal/script/scripttest/run.go
+++ b/src/cmd/internal/script/scripttest/run.go
@@ -71,13 +71,6 @@ func RunToolScriptTest(t *testing.T, repls []ToolReplacement, pattern string) {
cmds[name] = cmd
}
- addcond := func(name string, cond script.Cond) {
- if _, ok := conds[name]; ok {
- panic(fmt.Sprintf("condition %q is already registered", name))
- }
- conds[name] = cond
- }
-
prependToPath := func(env []string, dir string) {
found := false
for k := range env {
@@ -135,7 +128,10 @@ func RunToolScriptTest(t *testing.T, repls []ToolReplacement, pattern string) {
cccmd := script.Program(goEnv("CC"), interrupt, gracePeriod)
addcmd("go", gocmd)
addcmd("cc", cccmd)
- addcond("cgo", script.BoolCondition("host CGO_ENABLED", testenv.HasCGO()))
+
+ // Add various helpful conditions related to builds and toolchain use.
+ goHostOS, goHostArch := goEnv("GOHOSTOS"), goEnv("GOHOSTARCH")
+ AddToolChainScriptConditions(t, conds, goHostOS, goHostArch)
// Environment setup.
env := os.Environ()