From: qmuntal Date: Tue, 16 Dec 2025 10:08:35 +0000 (+0100) Subject: cmd/dist: preserve existing GOEXPERIMENTs when running tests with additional experiments X-Git-Tag: go1.26rc2~7^2~72 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a4b5b92055d24da007ae13c4586aa0a229fa337b;p=gostls13.git cmd/dist: preserve existing GOEXPERIMENTs when running tests with additional experiments 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 Reviewed-by: Cherry Mui Reviewed-by: Michael Knyszek --- diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 6d3742525c..48c3aa5efd 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -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, ",") + +}