diff options
| author | Bryan C. Mills <bcmills@google.com> | 2023-05-02 09:37:00 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-05-03 14:35:45 +0000 |
| commit | 968ebb205e02ff4a1d63575a2af54e885b0ab4fc (patch) | |
| tree | 514ff3dcd4446b4002243821646890a747f15fa2 /src/cmd/api/api_test.go | |
| parent | 5e349aca4e3990500c960f7cc24334b54bd0d49a (diff) | |
| download | go-968ebb205e02ff4a1d63575a2af54e885b0ab4fc.tar.xz | |
cmd/api: move support checks into individual tests
This makes 'go test -list cmd/api' work, and fixes an infinite
recursion via testenv.HasExec that would otherwise occur.
As of CL 488076, testenv.HasExec tries to re-exec the test
executable using -list to suppress running the tests, which
produces a fork bomb if TestMain itself calls HasExec.
For this test, it turns out that the HasExec check is redundant
anyway: if we can exec 'go build', we can certainly exec programs in
general too.
Change-Id: I165f98315c181098c8be8b7525b9dfa3f98e14f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/491656
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/api/api_test.go')
| -rw-r--r-- | src/cmd/api/api_test.go | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/src/cmd/api/api_test.go b/src/cmd/api/api_test.go index 142cbb4339..8b1b7c3ce8 100644 --- a/src/cmd/api/api_test.go +++ b/src/cmd/api/api_test.go @@ -20,33 +20,12 @@ import ( var flagCheck = flag.Bool("check", false, "run API checks") func TestMain(m *testing.M) { - if !testenv.HasExec() { - os.Stdout.WriteString("skipping test: platform cannot exec") - os.Exit(0) - } - if !testenv.HasGoBuild() { - os.Stdout.WriteString("skipping test: platform cannot 'go build' to import std packages") - os.Exit(0) - } - flag.Parse() for _, c := range contexts { c.Compiler = build.Default.Compiler } build.Default.GOROOT = testenv.GOROOT(nil) - // Warm up the import cache in parallel. - var wg sync.WaitGroup - for _, context := range contexts { - context := context - wg.Add(1) - go func() { - defer wg.Done() - _ = NewWalker(context, filepath.Join(testenv.GOROOT(nil), "src")) - }() - } - wg.Wait() - os.Exit(m.Run()) } @@ -59,6 +38,9 @@ func TestGolden(t *testing.T) { // slow, not worth repeating in -check t.Skip("skipping with -check set") } + + testenv.MustHaveGoBuild(t) + td, err := os.Open("testdata/src/pkg") if err != nil { t.Fatal(err) @@ -232,6 +214,20 @@ func TestIssue21181(t *testing.T) { // slow, not worth repeating in -check t.Skip("skipping with -check set") } + testenv.MustHaveGoBuild(t) + + // Warm up the import cache in parallel. + var wg sync.WaitGroup + for _, context := range contexts { + context := context + wg.Add(1) + go func() { + defer wg.Done() + _ = NewWalker(context, filepath.Join(testenv.GOROOT(nil), "src")) + }() + } + wg.Wait() + for _, context := range contexts { w := NewWalker(context, "testdata/src/issue21181") pkg, err := w.import_("p") @@ -248,6 +244,7 @@ func TestIssue29837(t *testing.T) { // slow, not worth repeating in -check t.Skip("skipping with -check set") } + testenv.MustHaveGoBuild(t) for _, context := range contexts { w := NewWalker(context, "testdata/src/issue29837") _, err := w.ImportFrom("p", "", 0) @@ -262,6 +259,7 @@ func TestIssue41358(t *testing.T) { // slow, not worth repeating in -check t.Skip("skipping with -check set") } + testenv.MustHaveGoBuild(t) context := new(build.Context) *context = build.Default context.Dir = filepath.Join(testenv.GOROOT(t), "src") @@ -278,5 +276,6 @@ func TestCheck(t *testing.T) { if !*flagCheck { t.Skip("-check not specified") } + testenv.MustHaveGoBuild(t) Check(t) } |
