| | |
| | |
| | |
| |
|
| | |
| |
|
| | package bootstrap_test |
| |
|
| | import ( |
| | "bytes" |
| | "errors" |
| | "internal/testenv" |
| | "os" |
| | "os/exec" |
| | "path/filepath" |
| | "runtime" |
| | "testing" |
| | ) |
| |
|
| | |
| | |
| | |
| | |
| | |
| | func TestExperimentToolID(t *testing.T) { |
| | 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) |
| | } |
| |
|
| | realGoroot := testenv.GOROOT(t) |
| |
|
| | |
| | goroot := t.TempDir() |
| | gorootSrc := filepath.Join(goroot, "src") |
| | 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="+realGoroot) |
| |
|
| | |
| | gocache := t.TempDir() |
| | env = append(env, "GOCACHE="+gocache) |
| |
|
| | |
| | var makeScript string |
| | switch runtime.GOOS { |
| | case "windows": |
| | makeScript = "make.bat" |
| | case "plan9": |
| | makeScript = "make.rc" |
| | default: |
| | makeScript = "make.bash" |
| | } |
| | makeScriptPath := filepath.Join(realGoroot, "src", makeScript) |
| | runCmd(t, gorootSrc, env, makeScriptPath) |
| |
|
| | |
| | goCmdPath := filepath.Join(goroot, "bin", "go") |
| | 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 is unexpected:\ngot %q\nwant %q", gotVersion, wantVersion) |
| | } |
| |
|
| | |
| | runCmd(t, gorootSrc, env, goCmdPath, "build", "-race", "archive/tar") |
| |
|
| | |
| | env = append(env, "GOEXPERIMENT=fieldtrack") |
| | runCmd(t, gorootSrc, env, makeScriptPath) |
| |
|
| | |
| | gotVersion = bytes.TrimSpace(runCmd(t, gorootSrc, env, goCmdPath, "tool", "compile", "-V=full")) |
| | wantVersion = []byte(`compile version go1.999 X:fieldtrack`) |
| | if !bytes.Equal(gotVersion, wantVersion) { |
| | t.Errorf("compile version with experiment is unexpected:\ngot %q\nwant %q", gotVersion, wantVersion) |
| | } |
| |
|
| | |
| | runCmd(t, gorootSrc, env, goCmdPath, "build", "-race", "archive/tar") |
| | } |
| |
|
| | func runCmd(t *testing.T, dir string, env []string, path string, args ...string) []byte { |
| | cmd := exec.Command(path, args...) |
| | cmd.Dir = dir |
| | cmd.Env = env |
| | out, err := cmd.Output() |
| | if err != nil { |
| | if ee, ok := errors.AsType[*exec.ExitError](err); ok { |
| | out = append(out, ee.Stderr...) |
| | } |
| | t.Fatalf("%s failed:\n%s\n%s", cmd, out, err) |
| | } |
| | return out |
| | } |
| |
|