All the users of HasSrc call t.Skip anyway, so let's move it to testenv.
Fix go/build to use MustHaveSource rather than MustHaveGoBuild where
appropriate.
Change-Id: I052bf96fd5a5780c1930da5b3a52b7a8dbebea46
Reviewed-on: https://go-review.googlesource.com/c/go/+/612057
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Tim King <taking@google.com>
if testenv.Builder() == "" {
t.Skip("skipping test on non-builder")
}
- if !testenv.HasSrc() {
- t.Skip("skipping; no GOROOT available")
- }
+ testenv.MustHaveSource(t)
goroot, err := filepath.EvalSymlinks(runtime.GOROOT())
if err != nil {
// Want to get a "cannot find package" error when directory for package does not exist.
// There should be valid partial information in the returned non-nil *Package.
func TestImportDirNotExist(t *testing.T) {
- testenv.MustHaveGoBuild(t) // really must just have source
+ testenv.MustHaveGoBuild(t) // Need 'go list' internally.
ctxt := Default
emptyDir := t.TempDir()
}
func TestImportVendor(t *testing.T) {
- testenv.MustHaveGoBuild(t) // really must just have source
+ testenv.MustHaveSource(t)
t.Setenv("GO111MODULE", "off")
}
func BenchmarkImportVendor(b *testing.B) {
- testenv.MustHaveGoBuild(b) // really must just have source
+ testenv.MustHaveSource(b)
b.Setenv("GO111MODULE", "off")
}
func TestImportVendorFailure(t *testing.T) {
- testenv.MustHaveGoBuild(t) // really must just have source
+ testenv.MustHaveSource(t)
t.Setenv("GO111MODULE", "off")
}
func TestImportVendorParentFailure(t *testing.T) {
- testenv.MustHaveGoBuild(t) // really must just have source
+ testenv.MustHaveSource(t)
t.Setenv("GO111MODULE", "off")
"io/fs"
"os"
"path/filepath"
- "runtime"
"slices"
"strings"
"testing"
}
func TestDependencies(t *testing.T) {
- if !testenv.HasSrc() {
- // Tests run in a limited file system and we do not
- // provide access to every source file.
- t.Skipf("skipping on %s/%s, missing full GOROOT", runtime.GOOS, runtime.GOARCH)
- }
+ testenv.MustHaveSource(t)
ctxt := Default
all, err := listStdPkgs(ctxt.GOROOT)
// TestStdlibLowercase tests that all standard library package names are
// lowercase. See Issue 40065.
func TestStdlibLowercase(t *testing.T) {
- if !testenv.HasSrc() {
- t.Skipf("skipping on %s/%s, missing full GOROOT", runtime.GOOS, runtime.GOARCH)
- }
+ testenv.MustHaveSource(t)
ctxt := Default
all, err := listStdPkgs(ctxt.GOROOT)
}
func TestImportStdLib(t *testing.T) {
- if !testenv.HasSrc() {
- t.Skip("no source code available")
- }
+ testenv.MustHaveSource(t)
if testing.Short() && testenv.Builder() == "" {
t.Skip("skipping in -short mode")
}
func TestImportedTypes(t *testing.T) {
- if !testenv.HasSrc() {
- t.Skip("no source code available")
- }
+ testenv.MustHaveSource(t)
for _, test := range importedObjectTests {
i := strings.LastIndex(test.name, ".")
}
func TestReimport(t *testing.T) {
- if !testenv.HasSrc() {
- t.Skip("no source code available")
- }
+ testenv.MustHaveSource(t)
// Reimporting a partially imported (incomplete) package is not supported (see issue #19337).
// Make sure we recognize the situation and report an error.
}
func TestIssue20855(t *testing.T) {
- if !testenv.HasSrc() {
- t.Skip("no source code available")
- }
+ testenv.MustHaveSource(t)
pkg, err := importer.ImportFrom("go/internal/srcimporter/testdata/issue20855", ".", 0)
if err == nil || !strings.Contains(err.Error(), "missing function body") {
}
func testImportPath(t *testing.T, pkgPath string) {
- if !testenv.HasSrc() {
- t.Skip("no source code available")
- }
+ testenv.MustHaveSource(t)
pkgName := path.Base(pkgPath)
return exec.LookPath("go")
})
-// HasSrc reports whether the entire source tree is available under GOROOT.
-func HasSrc() bool {
+// MustHaveSource checks that the entire source tree is available under GOROOT.
+// If not, it calls t.Skip with an explanation.
+func MustHaveSource(t testing.TB) {
switch runtime.GOOS {
case "ios":
- return false
+ t.Helper()
+ t.Skip("skipping test: no source tree on " + runtime.GOOS)
}
- return true
}
// HasExternalNetwork reports whether the current system can use
// strings and bytes package functions. HTTP is mostly ASCII based, and doing
// Unicode-aware case folding or space stripping can introduce vulnerabilities.
func TestNoUnicodeStrings(t *testing.T) {
- if !testenv.HasSrc() {
- t.Skip("source code not available")
- }
+ testenv.MustHaveSource(t)
re := regexp.MustCompile(`(strings|bytes).([A-Za-z]+)`)
if err := fs.WalkDir(os.DirFS("."), ".", func(path string, d fs.DirEntry, err error) error {