]> git.feebdaed.xyz Git - 0xmirror/go.git/commitdiff
cmd/dist: preserve existing GOEXPERIMENTs when running tests with additional experiments
authorqmuntal <quimmuntal@gmail.com>
Tue, 16 Dec 2025 10:08:35 +0000 (11:08 +0100)
committerQuim Muntal <quimmuntal@gmail.com>
Tue, 16 Dec 2025 16:17:13 +0000 (08:17 -0800)
Some tests require enabling specific Go experiments via the GOEXPERIMENT
, like "jsonv2", "runtimesecret", or "simd".

When running these tests, we should preserve any existing GOEXPERIMENT
settings, so that multiple experiments can be tested together.

I've found this limitation while working in my own Go fork, where in
some situations I pass additional experiments to the tests that alter
the Go runtime and other core packages.

Change-Id: Ib0324cd93282f6993611dea2f0c57d00ab304a33
Reviewed-on: https://go-review.googlesource.com/c/go/+/730360
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/cmd/dist/test.go

index 6d3742525c68080885cdeaa0c222b6a977163ea3..48c3aa5efdb008b17a68043c6b7caaadb633d966 100644 (file)
@@ -748,7 +748,7 @@ func (t *tester) registerTests() {
        if !strings.Contains(goexperiment, "jsonv2") {
                t.registerTest("GOEXPERIMENT=jsonv2 go test encoding/json/...", &goTest{
                        variant: "jsonv2",
-                       env:     []string{"GOEXPERIMENT=jsonv2"},
+                       env:     []string{"GOEXPERIMENT=" + goexperiments("jsonv2")},
                        pkg:     "encoding/json/...",
                })
        }
@@ -757,7 +757,7 @@ func (t *tester) registerTests() {
        if !strings.Contains(goexperiment, "runtimesecret") {
                t.registerTest("GOEXPERIMENT=runtimesecret go test runtime/secret/...", &goTest{
                        variant: "runtimesecret",
-                       env:     []string{"GOEXPERIMENT=runtimesecret"},
+                       env:     []string{"GOEXPERIMENT=" + goexperiments("runtimesecret")},
                        pkg:     "runtime/secret/...",
                })
        }
@@ -766,7 +766,7 @@ func (t *tester) registerTests() {
        if goarch == "amd64" && !strings.Contains(goexperiment, "simd") {
                t.registerTest("GOEXPERIMENT=simd go test simd/archsimd/...", &goTest{
                        variant: "simd",
-                       env:     []string{"GOEXPERIMENT=simd"},
+                       env:     []string{"GOEXPERIMENT=" + goexperiments("simd")},
                        pkg:     "simd/archsimd/...",
                })
        }
@@ -1888,3 +1888,19 @@ func fipsVersions(short bool) []string {
        }
        return versions
 }
+
+// goexperiments returns the GOEXPERIMENT value to use
+// when running a test with the given experiments enabled.
+//
+// It preserves any existing GOEXPERIMENTs.
+func goexperiments(exps ...string) string {
+       if len(exps) == 0 {
+               return goexperiment
+       }
+       existing := goexperiment
+       if existing != "" {
+               existing += ","
+       }
+       return existing + strings.Join(exps, ",")
+
+}