]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: drop GOEXPERIMENT in script tests
authorAustin Clements <austin@google.com>
Sat, 17 Apr 2021 01:45:02 +0000 (21:45 -0400)
committerDavid Chase <drchase@google.com>
Mon, 19 Apr 2021 02:43:30 +0000 (02:43 +0000)
TestScript sets the GOEXPERIMENT environment variable to the value of
buildcfg.GOEXPERIMENT() with the intent that tests can use this to
inspect the value of buildcfg.GOEXPERIMENT. This has the unfortunate
side-effect of also affecting the experiments enabled for all builds
done by TestScript. For the most part this is harmless, but
GOEXPERIMENT can be GOOS/GOARCH-sensitive, so if a test changes GOOS
or GOARCH, it will continue to use the GOEXPERIMENT from the host
GOOS/GOARCH rather than what makes sense (or is even allowed) in the
test's GOOS/GOARCH. In fact, prior to CL 307819, TestScript set
GOEXPSTRING instead of GOEXPERIMENT because it previously captured
objabi.Expstring(), so the captured value didn't affect the build.

There's only one experiment that actually uses TestScript's
GOEXPERIMENT and there's a much better way to write that test now such
that it doesn't need to read GOEXPERIMENT at all. Hence, this CL
rewrites this test and drops GOEXPERIMENT from TestScript.

This should fix the *-regabi builders.

Change-Id: I3fcbf1f21e1b471ebc0e953c31333645553ea24c
Reviewed-on: https://go-review.googlesource.com/c/go/+/310969
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/go/script_test.go
src/cmd/go/testdata/script/README
src/cmd/go/testdata/script/build_tag_goexperiment.txt

index 87b5971aa71915f146843bf3b82268389e003df1..2274335a75a2de6565993da2a84a47cbaf084a9d 100644 (file)
@@ -13,7 +13,6 @@ import (
        "errors"
        "fmt"
        "go/build"
-       "internal/buildcfg"
        "internal/testenv"
        "io/fs"
        "os"
@@ -165,7 +164,6 @@ func (ts *testScript) setup() {
                "GOCACHE=" + testGOCACHE,
                "GODEBUG=" + os.Getenv("GODEBUG"),
                "GOEXE=" + cfg.ExeSuffix,
-               "GOEXPERIMENT=" + buildcfg.GOEXPERIMENT(),
                "GOOS=" + runtime.GOOS,
                "GOPATH=" + filepath.Join(ts.workdir, "gopath"),
                "GOPROXY=" + proxyURL,
index b4dcb1f5a2e404ef4786c3012fe9a1b5279bdec5..d7e67bb7b60c2566d00b67628d6987decc871b6c 100644 (file)
@@ -29,7 +29,6 @@ Scripts also have access to these other environment variables:
        GOARCH=<target GOARCH>
        GOCACHE=<actual GOCACHE being used outside the test>
        GOEXE=<executable file suffix: .exe on Windows, empty on other systems>
-       GOEXPERIMENT=<value of objabi.GOEXPERIMENT>
        GOOS=<target GOOS>
        GOPATH=$WORK/gopath
        GOPROXY=<local module proxy serving from cmd/go/testdata/mod>
index dfda3d2629d55cd088f6070741c1b3ad406387f7..bee218f4c1fff290b993cf68930a4753ecbce708 100644 (file)
@@ -1,83 +1,20 @@
-# compile_ext will fail if the buildtags that are enabled (or not enabled) for the
-# framepointer and fieldtrack experiments are not consistent with the value of
-# objabi.GOEXPERIMENT.
-
 [short] skip
+# Reset all experiments so fieldtrack is definitely off.
+env GOEXPERIMENT=none
 go run m
-
--- expt_main.go --
-package main
-
-import (
-       "os"
-       "strings"
-)
-
-func main() {
-  fp()
-  ft()
-}
-
-func hasExpEntry(s string) bool {
-       // script_test.go defines GOEXPERIMENT to be the enabled experiments.
-       g := os.Getenv("GOEXPERIMENT")
-       for _, f := range strings.Split(g, ",") {
-               if f == s {
-                       return true
-               }
-       }
-       return false
-}
-
--- fp_off.go --
-// +build !goexperiment.framepointer
-
-package main
-
-import (
-       "fmt"
-       "os"
-)
-
-func fp() {
-       if hasExpEntry("framepointer") {
-               fmt.Println("in !framepointer build, but objabi.GOEXPERIMENT has 'framepointer'")
-               os.Exit(1)
-       }
-}
-
--- fp_on.go --
-// +build goexperiment.framepointer
-
-package main
-
-import (
-       "fmt"
-       "os"
-)
-
-func fp() {
-       if !hasExpEntry("framepointer") {
-               fmt.Println("in framepointer build, but objabi.GOEXPERIMENT does not have 'framepointer', is", os.Getenv("GOEXPERIMENT"))
-               os.Exit(1)
-       }
-}
+stderr 'fieldtrack off'
+# Turn fieldtrack on.
+env GOEXPERIMENT=none,fieldtrack
+go run m
+stderr 'fieldtrack on'
 
 -- ft_off.go --
 // +build !goexperiment.fieldtrack
 
 package main
 
-import (
-       "fmt"
-       "os"
-)
-
-func ft() {
-       if hasExpEntry("fieldtrack") {
-               fmt.Println("in !fieldtrack build, but objabi.GOEXPERIMENT has 'fieldtrack'")
-               os.Exit(1)
-       }
+func main() {
+       println("fieldtrack off")
 }
 
 -- ft_on.go --
@@ -85,16 +22,8 @@ func ft() {
 
 package main
 
-import (
-       "fmt"
-       "os"
-)
-
-func ft() {
-       if !hasExpEntry("fieldtrack") {
-               fmt.Println("in fieldtrack build, but objabi.GOEXPERIMENT does not have 'fieldtrack', is", os.Getenv("GOEXPERIMENT"))
-               os.Exit(1)
-       }
+func main() {
+       println("fieldtrack on")
 }
 
 -- go.mod --