mirror of
https://github.com/golang/go.git
synced 2026-04-02 17:30:01 +09:00
cmd/go: make all script tests parallel
Move the last non-parallel test to verylongtest, and then check that all go command invocations in the tests occur in a parallel context. Note that because TestBuildmodePie starts in a subtest, that the check for invocations in a parallel context wouldn't catch that the parent test didn't call t.Parallel. For #78152 Change-Id: Ie053e56af8efaaea6de9ce6fccbd20f76a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/755140 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Michael Matloob <matloob@google.com> Auto-Submit: Michael Matloob <matloob@golang.org>
This commit is contained in:
@@ -12,6 +12,8 @@ import (
|
||||
)
|
||||
|
||||
func TestChdir(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// We want -C to apply to every go subcommand.
|
||||
// Test that every command either has a -C flag registered
|
||||
// or has CustomFlags set. In the latter case, the command
|
||||
|
||||
@@ -487,11 +487,12 @@ func (tg *testgoData) goTool() string {
|
||||
// returning exit status.
|
||||
func (tg *testgoData) doRun(args []string) error {
|
||||
tg.t.Helper()
|
||||
if tg.inParallel {
|
||||
for _, arg := range args {
|
||||
if strings.HasPrefix(arg, "testdata") || strings.HasPrefix(arg, "./testdata") {
|
||||
tg.t.Fatal("internal testsuite error: parallel run using testdata")
|
||||
}
|
||||
if !tg.inParallel {
|
||||
tg.t.Fatal("all tests using testgoData must run in parallel")
|
||||
}
|
||||
for _, arg := range args {
|
||||
if strings.HasPrefix(arg, "testdata") || strings.HasPrefix(arg, "./testdata") {
|
||||
tg.t.Fatal("internal testsuite error: parallel run using testdata")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1948,6 +1949,7 @@ func TestNeedVersion(t *testing.T) {
|
||||
|
||||
func TestBuildmodePIE(t *testing.T) {
|
||||
tooSlow(t, "links binaries")
|
||||
t.Parallel()
|
||||
|
||||
if !platform.BuildModeSupported(runtime.Compiler, "pie", runtime.GOOS, runtime.GOARCH) {
|
||||
t.Skipf("skipping test because buildmode=pie is not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
|
||||
@@ -1970,6 +1972,7 @@ func TestWindowsDefaultBuildmodIsPIE(t *testing.T) {
|
||||
t.Skip("skipping windows only test")
|
||||
}
|
||||
tooSlow(t, "links binaries")
|
||||
t.Parallel()
|
||||
|
||||
t.Run("non-cgo", func(t *testing.T) {
|
||||
testBuildmodePIE(t, false, false)
|
||||
@@ -2651,24 +2654,3 @@ func TestCoverpkgTestOnly(t *testing.T) {
|
||||
tg.grepStderrNot("no packages being tested depend on matches", "bad match message")
|
||||
tg.grepStdout("coverage: 100", "no coverage")
|
||||
}
|
||||
|
||||
// Regression test for golang.org/issue/34499: version command should not crash
|
||||
// when executed in a deleted directory on Linux.
|
||||
func TestExecInDeletedDir(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "windows", "plan9",
|
||||
"aix", // Fails with "device busy".
|
||||
"solaris", "illumos": // Fails with "invalid argument".
|
||||
t.Skipf("%v does not support removing the current working directory", runtime.GOOS)
|
||||
}
|
||||
tg := testgo(t)
|
||||
defer tg.cleanup()
|
||||
|
||||
tg.makeTempdir()
|
||||
t.Chdir(tg.tempdir)
|
||||
|
||||
tg.check(os.Remove(tg.tempdir))
|
||||
|
||||
// `go version` should not fail
|
||||
tg.run("version")
|
||||
}
|
||||
|
||||
43
src/cmd/go/internal/verylongtest/go_test.go
Normal file
43
src/cmd/go/internal/verylongtest/go_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2026 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package verylongtest
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"internal/testenv"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Regression test for golang.org/issue/34499: version command should not crash
|
||||
// when executed in a deleted directory on Linux.
|
||||
func TestExecInDeletedDir(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "windows", "plan9",
|
||||
"aix", // Fails with "device busy".
|
||||
"solaris", "illumos": // Fails with "invalid argument".
|
||||
t.Skipf("%v does not support removing the current working directory", runtime.GOOS)
|
||||
}
|
||||
gotool := testenv.GoToolPath(t)
|
||||
|
||||
tmpdir := t.TempDir()
|
||||
t.Chdir(tmpdir)
|
||||
|
||||
if err := os.Remove(tmpdir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// `go version` should not fail
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd := exec.Command(gotool, "version")
|
||||
cmd.Env = append(os.Environ(), "GO111MODULE=off") // This behavior doesn't apply with GO111MODULE != off because we need to know the module to check the version.
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatalf("running go version: %v\n[stdout]: %s\n[stderr]: %s", err, stdout.Bytes(), stderr.Bytes())
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,8 @@ var testSum = flag.String("testsum", "", `may be tidy, listm, or listall. If set
|
||||
|
||||
// TestScript runs the tests in testdata/script/*.txt.
|
||||
func TestScript(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testenv.MustHaveGoBuild(t)
|
||||
testenv.SkipIfShortAndSlow(t)
|
||||
|
||||
@@ -99,6 +101,7 @@ func TestScript(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("README", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
checkScriptReadme(t, engine, env)
|
||||
})
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ import (
|
||||
)
|
||||
|
||||
func TestTerminalPassthrough(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Check that if 'go test' is run with a terminal connected to stdin/stdout,
|
||||
// then the go command passes that terminal down to the test binary
|
||||
// invocation (rather than, e.g., putting a pipe in the way).
|
||||
@@ -27,6 +29,7 @@ func TestTerminalPassthrough(t *testing.T) {
|
||||
// terminal, the test can correctly detect that. (cmd/go doesn't guarantee
|
||||
// that it won't add a terminal in the middle, but that would be pretty weird.)
|
||||
t.Run("pipe", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
t.Fatalf("pipe failed: %s", err)
|
||||
@@ -44,6 +47,7 @@ func TestTerminalPassthrough(t *testing.T) {
|
||||
|
||||
// Now test with a read PTY.
|
||||
t.Run("pty", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
r, processTTY, err := testpty.Open()
|
||||
if errors.Is(err, testpty.ErrNotSupported) {
|
||||
t.Skipf("%s", err)
|
||||
|
||||
Reference in New Issue
Block a user