reboot_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.
  4. // Package reboot_test verifies that the current GOROOT can be used to bootstrap
  5. // itself.
  6. package reboot_test
  7. import (
  8. "os"
  9. "os/exec"
  10. "path/filepath"
  11. "runtime"
  12. "testing"
  13. "time"
  14. )
  15. func TestRepeatBootstrap(t *testing.T) {
  16. if testing.Short() {
  17. t.Skipf("skipping test that rebuilds the entire toolchain")
  18. }
  19. goroot := t.TempDir()
  20. gorootSrc := filepath.Join(goroot, "src")
  21. overlayStart := time.Now()
  22. if err := overlayDir(gorootSrc, filepath.Join(runtime.GOROOT(), "src")); err != nil {
  23. t.Fatal(err)
  24. }
  25. t.Logf("GOROOT/src overlay set up in %s", time.Since(overlayStart))
  26. if err := os.WriteFile(filepath.Join(goroot, "VERSION"), []byte(runtime.Version()), 0666); err != nil {
  27. t.Fatal(err)
  28. }
  29. var makeScript string
  30. switch runtime.GOOS {
  31. case "windows":
  32. makeScript = "make.bat"
  33. case "plan9":
  34. makeScript = "make.rc"
  35. default:
  36. makeScript = "make.bash"
  37. }
  38. cmd := exec.Command(filepath.Join(runtime.GOROOT(), "src", makeScript))
  39. cmd.Dir = gorootSrc
  40. cmd.Env = append(os.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+runtime.GOROOT())
  41. cmd.Stderr = os.Stderr
  42. cmd.Stdout = os.Stdout
  43. if err := cmd.Run(); err != nil {
  44. t.Fatal(err)
  45. }
  46. }