1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package reboot_test verifies that the current GOROOT can be used to bootstrap
21 func TestRepeatBootstrap(t *testing.T) {
23 t.Skipf("skipping test that rebuilds the entire toolchain")
26 realGoroot, err := filepath.Abs(filepath.Join("..", ".."))
31 // To ensure that bootstrapping doesn't unexpectedly depend
32 // on the Go repo's git metadata, add a fake (unreadable) git
33 // directory above the simulated GOROOT.
34 // This mimics the configuration one much have when
35 // building from distro-packaged source code
36 // (see https://go.dev/issue/54852).
38 dotGit := filepath.Join(parent, ".git")
39 if err := os.Mkdir(dotGit, 000); err != nil {
43 overlayStart := time.Now()
45 goroot := filepath.Join(parent, "goroot")
47 gorootSrc := filepath.Join(goroot, "src")
48 if err := overlayDir(gorootSrc, filepath.Join(realGoroot, "src")); err != nil {
52 gorootLib := filepath.Join(goroot, "lib")
53 if err := overlayDir(gorootLib, filepath.Join(realGoroot, "lib")); err != nil {
57 t.Logf("GOROOT overlay set up in %s", time.Since(overlayStart))
59 if err := os.WriteFile(filepath.Join(goroot, "VERSION"), []byte(runtime.Version()), 0666); err != nil {
66 makeScript = "make.bat"
68 makeScript = "make.rc"
70 makeScript = "make.bash"
73 var stdout strings.Builder
74 cmd := exec.Command(filepath.Join(goroot, "src", makeScript))
76 cmd.Env = append(cmd.Environ(), "GOROOT=", "GOROOT_FINAL=", "GOROOT_BOOTSTRAP="+realGoroot)
77 cmd.Stderr = os.Stderr
78 cmd.Stdout = io.MultiWriter(os.Stdout, &stdout)
79 if err := cmd.Run(); err != nil {
83 // Test that go.dev/issue/42563 hasn't regressed.
84 t.Run("PATH reminder", func(t *testing.T) {
86 switch gorootBin := filepath.Join(goroot, "bin"); runtime.GOOS {
88 want = fmt.Sprintf("*** You need to add %s to your PATH.", gorootBin)
90 want = fmt.Sprintf("*** You need to bind %s before /bin.", gorootBin)
92 if got := stdout.String(); !strings.Contains(got, want) {
93 t.Errorf("reminder %q is missing from %s stdout:\n%s", want, makeScript, got)