// license that can be found in the LICENSE file.
//go:build explicit
-// +build explicit
-
-// This test verifies that GOEXPERIMENT settings built
-// into the toolchain influence tool ids in the Go command.
-// This test requires bootstrapping the toolchain twice, so it's very expensive.
-// It must be run explicitly with -tags=explicit.
-// Verifies golang.org/issue/33091.
package bootstrap_test
import (
"bytes"
+ "errors"
+ "internal/testenv"
"os"
"os/exec"
"path/filepath"
"testing"
)
+// TestExperimentToolID verifies that GOEXPERIMENT settings built
+// into the toolchain influence tool ids in the Go command.
+// This test requires bootstrapping the toolchain twice, so it's very expensive.
+// It must be run explicitly with -tags=explicit.
+// Verifies go.dev/issue/33091.
func TestExperimentToolID(t *testing.T) {
- // Set up GOROOT
- goroot, err := os.MkdirTemp("", "experiment-goroot")
- if err != nil {
- t.Fatal(err)
+ if testing.Short() {
+ t.Skip("skipping test that rebuilds the entire toolchain twice")
+ }
+ switch runtime.GOOS {
+ case "android", "ios", "js", "wasip1":
+ t.Skipf("skipping because the toolchain does not have to bootstrap on GOOS=%s", runtime.GOOS)
}
- defer os.RemoveAll(goroot)
+ realGoroot := testenv.GOROOT(t)
+
+ // Set up GOROOT.
+ goroot := t.TempDir()
gorootSrc := filepath.Join(goroot, "src")
- if err := overlayDir(gorootSrc, filepath.Join(runtime.GOROOT(), "src")); err != nil {
+ if err := overlayDir(gorootSrc, filepath.Join(realGoroot, "src")); err != nil {
+ t.Fatal(err)
+ }
+ gorootLib := filepath.Join(goroot, "lib")
+ if err := overlayDir(gorootLib, filepath.Join(realGoroot, "lib")); err != nil {
t.Fatal(err)
}
-
if err := os.WriteFile(filepath.Join(goroot, "VERSION"), []byte("go1.999"), 0666); err != nil {
t.Fatal(err)
}
- env := append(os.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+runtime.GOROOT())
+ env := append(os.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+realGoroot)
// Use a clean cache.
- gocache, err := os.MkdirTemp("", "experiment-gocache")
- if err != nil {
- t.Fatal(err)
- }
- defer os.RemoveAll(gocache)
+ gocache := t.TempDir()
env = append(env, "GOCACHE="+gocache)
// Build the toolchain without GOEXPERIMENT.
default:
makeScript = "make.bash"
}
- makeScriptPath := filepath.Join(runtime.GOROOT(), "src", makeScript)
+ makeScriptPath := filepath.Join(realGoroot, "src", makeScript)
runCmd(t, gorootSrc, env, makeScriptPath)
// Verify compiler version string.
goCmdPath := filepath.Join(goroot, "bin", "go")
- if runtime.GOOS == "windows" {
- goCmdPath += ".exe"
- }
gotVersion := bytes.TrimSpace(runCmd(t, gorootSrc, env, goCmdPath, "tool", "compile", "-V=full"))
wantVersion := []byte(`compile version go1.999`)
if !bytes.Equal(gotVersion, wantVersion) {
- t.Errorf("compile version without experiment: got %q, want %q", gotVersion, wantVersion)
+ t.Errorf("compile version without experiment is unexpected:\ngot %q\nwant %q", gotVersion, wantVersion)
}
// Build a package in a mode not handled by the make script.
// Verify compiler version string.
gotVersion = bytes.TrimSpace(runCmd(t, gorootSrc, env, goCmdPath, "tool", "compile", "-V=full"))
- wantVersion = []byte(`compile version go1.999 X:fieldtrack,framepointer`)
+ wantVersion = []byte(`compile version go1.999 X:fieldtrack`)
if !bytes.Equal(gotVersion, wantVersion) {
- t.Errorf("compile version with experiment: got %q, want %q", gotVersion, wantVersion)
+ t.Errorf("compile version with experiment is unexpected:\ngot %q\nwant %q", gotVersion, wantVersion)
}
// Build the same package. We should not get a cache conflict.
cmd.Env = env
out, err := cmd.Output()
if err != nil {
- t.Fatal(err)
+ if ee := (*exec.ExitError)(nil); errors.As(err, &ee) {
+ out = append(out, ee.Stderr...)
+ }
+ t.Fatalf("%s failed:\n%s\n%s", cmd, out, err)
}
return out
}