// MustHaveGoRun checks that the current system can run programs with ``go run.'' // If not, MustHaveGoRun calls t.Skip with an explanation. public static void MustHaveGoRun(testing.TB t) { if (!HasGoRun()) { t.Skipf("skipping test: 'go run' not available on %s/%s", runtime.GOOS, runtime.GOARCH); } }
// MustHaveGoBuild checks that the current system can build programs with ``go build'' // and then run them with os.StartProcess or exec.Command. // If not, MustHaveGoBuild calls t.Skip with an explanation. public static void MustHaveGoBuild(testing.TB t) { if (os.Getenv("GO_GCFLAGS") != "") { t.Skipf("skipping test: 'go build' not compatible with setting $GO_GCFLAGS"); } if (!HasGoBuild()) { t.Skipf("skipping test: 'go build' not available on %s/%s", runtime.GOOS, runtime.GOARCH); } }
// GoToolPath reports the path to the Go tool. // It is a convenience wrapper around GoTool. // If the tool is unavailable GoToolPath calls t.Skip. // If the tool should be available and isn't, GoToolPath calls t.Fatal. public static @string GoToolPath(testing.TB t) { MustHaveGoBuild(t); var(path, err) = GoTool(); if (err != null) { t.Fatal(err); } // Add all environment variables that affect the Go command to test metadata. // Cached test results will be invalidate when these variables change. // See golang.org/issue/32285. foreach (var(_, envVar) in strings.Fields(cfg.KnownEnv)) { os.Getenv(envVar); } return(path); }