)
var gcflags string = os.Getenv("GO_GCFLAGS")
+var goroot string
func TestMain(m *testing.M) {
flag.Parse()
}
func testMain(m *testing.M) int {
+ cwd, err := os.Getwd()
+ if err != nil {
+ log.Fatal(err)
+ }
+ goroot = filepath.Join(cwd, "../../..")
+
// Copy testdata into GOPATH/src/testplugin, along with a go.mod file
// declaring the same path.
if t != nil {
t.Helper()
}
- run(t, "go", append([]string{op, "-gcflags", gcflags}, args...)...)
+ run(t, filepath.Join(goroot, "bin", "go"), append([]string{op, "-gcflags", gcflags}, args...)...)
}
// escape converts a string to something suitable for a shell command line.
)
var gopathInstallDir, gorootInstallDir string
+var oldGOROOT string
// This is the smallest set of packages we can link into a shared
// library (runtime/cgo is built implicitly).
newargs = append(newargs, "-x", "-ldflags=-v")
}
newargs = append(newargs, args[1:]...)
- c := exec.Command("go", newargs...)
+ c := exec.Command(filepath.Join(oldGOROOT, "bin", "go"), newargs...)
stderr := new(strings.Builder)
c.Stderr = stderr
// TestMain calls testMain so that the latter can use defer (TestMain exits with os.Exit).
func testMain(m *testing.M) (int, error) {
+ cwd, err := os.Getwd()
+ if err != nil {
+ log.Fatal(err)
+ }
+ oldGOROOT = filepath.Join(cwd, "../../..")
+
workDir, err := os.MkdirTemp("", "shared_test")
if err != nil {
return 0, err
// GOROOT/pkg relevant to this test into the given directory.
// It must be run from within the testdata module.
func cloneGOROOTDeps(goroot string) error {
- oldGOROOT := strings.TrimSpace(goCmd(nil, "env", "GOROOT"))
- if oldGOROOT == "" {
- return fmt.Errorf("go env GOROOT returned an empty string")
- }
-
// Before we clone GOROOT, figure out which packages we need to copy over.
listArgs := []string{
"list",