internal/testenv: make MustHaveSource detect missing source

Change-Id: I1adcbd84d81bb7d0f099ce729ec386b46a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/780480
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Filippo Valsorda 2026-05-20 17:16:02 +02:00 committed by Gopher Robot
parent e0a8616941
commit 60f0ced65b

View file

@ -275,12 +275,28 @@ var goTool = sync.OnceValues(func() (string, error) {
// MustHaveSource checks that the entire source tree is available under GOROOT.
// If not, it calls t.Skip with an explanation.
//
// This is needed when reading files from GOROOT that are not in ./testdata.
func MustHaveSource(t testing.TB) {
t.Helper()
switch runtime.GOOS {
case "ios":
t.Helper()
t.Skip("skipping test: no source tree on " + runtime.GOOS)
}
if Builder() != "" {
// The builders have the source tree available, and if they don't the
// tests should error out.
return
}
// If not running on the builders, the test binary might have been copied to
// a target machine where the source tree isn't available.
goroot, err := findGOROOT()
if err != nil {
t.Skipf("skipping test: cannot locate GOROOT: %v", err)
}
if _, err := os.Stat(filepath.Join(goroot, "src", "go.mod")); err != nil {
t.Skipf("skipping test: GOROOT/src not available: %v", err)
}
}
// HasExternalNetwork reports whether the current system can use