]> Cypherpunks repositories - gostls13.git/commitdiff
internal/testenv: add MustHaveSource, rm HasSrc
authorKir Kolyshkin <kolyshkin@gmail.com>
Mon, 9 Sep 2024 18:04:13 +0000 (11:04 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 13 Sep 2024 16:56:48 +0000 (16:56 +0000)
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>

src/compress/gzip/issue14937_test.go
src/go/build/build_test.go
src/go/build/deps_test.go
src/go/internal/srcimporter/srcimporter_test.go
src/internal/testenv/testenv.go
src/net/http/http_test.go

index fe0b264f8a8a44a7e9a53e741537e83f90bda082..e8f39ed080c95b9cfbc0e0d70c766b91cabbd3c1 100644 (file)
@@ -30,9 +30,7 @@ func TestGZIPFilesHaveZeroMTimes(t *testing.T) {
        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 {
index cb2941d097dff838f8103f21e4756d0fc75bd0ac..605fa365dc49877bbe0a52ea296e69e1dd662340 100644 (file)
@@ -496,7 +496,7 @@ func TestShellSafety(t *testing.T) {
 // 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()
@@ -550,7 +550,7 @@ func TestImportDirNotExist(t *testing.T) {
 }
 
 func TestImportVendor(t *testing.T) {
-       testenv.MustHaveGoBuild(t) // really must just have source
+       testenv.MustHaveSource(t)
 
        t.Setenv("GO111MODULE", "off")
 
@@ -571,7 +571,7 @@ func TestImportVendor(t *testing.T) {
 }
 
 func BenchmarkImportVendor(b *testing.B) {
-       testenv.MustHaveGoBuild(b) // really must just have source
+       testenv.MustHaveSource(b)
 
        b.Setenv("GO111MODULE", "off")
 
@@ -592,7 +592,7 @@ func BenchmarkImportVendor(b *testing.B) {
 }
 
 func TestImportVendorFailure(t *testing.T) {
-       testenv.MustHaveGoBuild(t) // really must just have source
+       testenv.MustHaveSource(t)
 
        t.Setenv("GO111MODULE", "off")
 
@@ -614,7 +614,7 @@ func TestImportVendorFailure(t *testing.T) {
 }
 
 func TestImportVendorParentFailure(t *testing.T) {
-       testenv.MustHaveGoBuild(t) // really must just have source
+       testenv.MustHaveSource(t)
 
        t.Setenv("GO111MODULE", "off")
 
index b6d956596c036d38900d3dc6dc5f285cfd2ffad0..40034263cc284a3891233e0683062ed90583866d 100644 (file)
@@ -16,7 +16,6 @@ import (
        "io/fs"
        "os"
        "path/filepath"
-       "runtime"
        "slices"
        "strings"
        "testing"
@@ -751,11 +750,7 @@ func listStdPkgs(goroot string) ([]string, error) {
 }
 
 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)
@@ -859,9 +854,7 @@ func depsPolicy(t *testing.T) *dag.Graph {
 // 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)
index 61ae0c14532791397296692908c007d60bbcec32..87dfdc75bb2bbf3cef9ad37a3061b40491c50010 100644 (file)
@@ -83,9 +83,7 @@ func walkDir(t *testing.T, path string, endTime time.Time) (int, bool) {
 }
 
 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")
@@ -109,9 +107,7 @@ var importedObjectTests = []struct {
 }
 
 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, ".")
@@ -179,9 +175,7 @@ func verifyInterfaceMethodRecvs(t *testing.T, named *types.Named, level int) {
 }
 
 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.
@@ -195,9 +189,7 @@ func TestReimport(t *testing.T) {
 }
 
 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") {
@@ -209,9 +201,7 @@ func TestIssue20855(t *testing.T) {
 }
 
 func testImportPath(t *testing.T, pkgPath string) {
-       if !testenv.HasSrc() {
-               t.Skip("no source code available")
-       }
+       testenv.MustHaveSource(t)
 
        pkgName := path.Base(pkgPath)
 
index e07e71a9b251751c71da11dc5c8afe58aae048f1..9aecfaa69505a50120b85d8af599491dae3595b1 100644 (file)
@@ -268,13 +268,14 @@ var goTool = sync.OnceValues(func() (string, error) {
        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
index df9812fc94747c1a8b6d40f6e1dd89044ba873d1..777634bbb25e0c9e489a0b8702a06a719165cb43 100644 (file)
@@ -151,9 +151,7 @@ var forbiddenStringsFunctions = map[string]bool{
 // 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 {