Source file misc/reboot/reboot_test.go

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

View as plain text