aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2022-04-25 10:09:47 -0400
committerThan McIntosh <thanm@google.com>2022-09-28 11:49:00 +0000
commit06e8022ed43ea83d0d7d76366f4930903220bc25 (patch)
treea235c4138ac572f879b0814011d6230f9639b918 /src
parent5f18e4632897769f2abf80332c39b526697d1a1c (diff)
downloadgo-06e8022ed43ea83d0d7d76366f4930903220bc25.tar.xz
cmd/go: add hook to check for GOEXPERIMENT in script tests
Add a new hook to allow script tests to check whether a specific GOEXPERIMENT is enabled. Updates #51430. Change-Id: Icdf39f845ff2c8b10c634d49e9c27bc90e7984f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/402174 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go/script_test.go28
-rw-r--r--src/cmd/go/testdata/script/README1
-rw-r--r--src/cmd/go/testdata/script/check_goexperiment.txt10
3 files changed, 39 insertions, 0 deletions
diff --git a/src/cmd/go/script_test.go b/src/cmd/go/script_test.go
index 006c4346c7..4f519aa0ee 100644
--- a/src/cmd/go/script_test.go
+++ b/src/cmd/go/script_test.go
@@ -14,6 +14,7 @@ import (
"flag"
"fmt"
"go/build"
+ "internal/buildcfg"
"internal/testenv"
"internal/txtar"
"io/fs"
@@ -246,6 +247,24 @@ func goVersion() (string, error) {
var execCache par.Cache
+func goExperimentIsValid(expname string) bool {
+ for _, exp := range buildcfg.Experiment.All() {
+ if expname == exp || expname == "no"+exp || "no"+expname == exp {
+ return true
+ }
+ }
+ return false
+}
+
+func goExperimentIsEnabled(expname string) bool {
+ for _, exp := range buildcfg.Experiment.Enabled() {
+ if exp == expname {
+ return true
+ }
+ }
+ return false
+}
+
// run runs the test script.
func (ts *testScript) run() {
// Truncate log at end of last phase marker,
@@ -444,6 +463,15 @@ Script:
ok = sys.BuildModeSupported(runtime.Compiler, value, runtime.GOOS, runtime.GOARCH)
break
}
+ if strings.HasPrefix(cond.tag, "GOEXPERIMENT:") {
+ rawval := strings.TrimPrefix(cond.tag, "GOEXPERIMENT:")
+ value := strings.TrimSpace(rawval)
+ if !goExperimentIsValid(value) {
+ ts.fatalf("unknown/unrecognized GOEXPERIMENT %q", value)
+ }
+ ok = goExperimentIsEnabled(value)
+ break
+ }
if !imports.KnownArch[cond.tag] && !imports.KnownOS[cond.tag] && cond.tag != "gc" && cond.tag != "gccgo" {
ts.fatalf("unknown condition %q", cond.tag)
}
diff --git a/src/cmd/go/testdata/script/README b/src/cmd/go/testdata/script/README
index e52917684f..6acef31018 100644
--- a/src/cmd/go/testdata/script/README
+++ b/src/cmd/go/testdata/script/README
@@ -99,6 +99,7 @@ should only run when the condition is satisfied. The available conditions are:
- [buildmode:value] for whether -buildmode=value is supported
- [trimpath] for whether the 'go' binary was built with -trimpath
- [mismatched-goroot] for whether the test's GOROOT_FINAL does not match the real GOROOT
+ - [GOEXPERIMENT:expname] for whether the GOEXPERIMENT 'expname' is enabled
A condition can be negated: [!short] means to run the rest of the line
when testing.Short() is false. Multiple conditions may be given for a single
diff --git a/src/cmd/go/testdata/script/check_goexperiment.txt b/src/cmd/go/testdata/script/check_goexperiment.txt
new file mode 100644
index 0000000000..3434cb9d6d
--- /dev/null
+++ b/src/cmd/go/testdata/script/check_goexperiment.txt
@@ -0,0 +1,10 @@
+# Test that [GOEXPERIMENT:x] is accepted.
+# Here fieldtrack is picked arbitrarily.
+
+[GOEXPERIMENT:nofieldtrack] env
+
+[GOEXPERIMENT:fieldtrack] env
+
+#[GOEXPERIMENT:crashme] env
+
+