1
0
mirror of https://github.com/golang/go synced 2024-09-29 13:24:28 -06:00

cmd/go: drop GOEXPERIMENT in script tests

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>
This commit is contained in:
Austin Clements 2021-04-16 21:45:02 -04:00 committed by David Chase
parent 4efd581383
commit c914e6160d
3 changed files with 11 additions and 85 deletions

View 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,

View 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>

View 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 --