1
0
mirror of https://github.com/golang/go synced 2024-10-01 03:18:33 -06:00

all: use ^TestName$ regular pattern for invoking a single test

Use ^ and $ in the -run flag regular expression value when the intention
is to invoke a single named test. This removes the reliance on there not
being another similarly named test to achieve the intended result.

In particular, package syscall has tests named TestUnshareMountNameSpace
and TestUnshareMountNameSpaceChroot that both trigger themselves setting
GO_WANT_HELPER_PROCESS=1 to run alternate code in a helper process. As a
consequence of overlap in their test names, the former was inadvertently
triggering one too many helpers.

Spotted while reviewing CL 525196. Apply the same change in other places
to make it easier for code readers to see that said tests aren't running
extraneous tests. The unlikely cases of -run=TestSomething intentionally
being used to run all tests that have the TestSomething substring in the
name can be better written as -run=^.*TestSomething.*$ or with a comment
so it is clear it wasn't an oversight.

Change-Id: Iba208aba3998acdbf8c6708e5d23ab88938bfc1e
Reviewed-on: https://go-review.googlesource.com/c/go/+/524948
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Kirill Kolyshkin <kolyshkin@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Dmitri Shuralyov 2023-09-03 14:23:02 -04:00 committed by Gopher Robot
parent cffdfe8d2c
commit 0dfb22ed70
31 changed files with 57 additions and 57 deletions

View File

@ -85,7 +85,7 @@ func test18146(t *testing.T) {
}
}()
args := append(append([]string(nil), os.Args[1:]...), "-test.run=Test18146")
args := append(append([]string(nil), os.Args[1:]...), "-test.run=^Test18146$")
for n := attempts; n > 0; n-- {
cmd := exec.Command(os.Args[0], args...)
cmd.Env = append(os.Environ(), "test18146=exec")

View File

@ -169,7 +169,7 @@ func TestCode(t *testing.T) {
continue
}
t.Run(fmt.Sprintf("%s%s", test.name[4:], flag), func(t *testing.T) {
out, err := testenv.Command(t, filepath.Join(tmpdir, "code.test"), "-test.run="+test.name).CombinedOutput()
out, err := testenv.Command(t, filepath.Join(tmpdir, "code.test"), "-test.run=^"+test.name+"$").CombinedOutput()
if err != nil || string(out) != "PASS\n" {
t.Errorf("Failed:\n%s\n", out)
}

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Code generated by 'go test cmd/go -v -run=TestDocsUpToDate -fixdocs'; DO NOT EDIT.
// Code generated by 'go test cmd/go -v -run=^TestDocsUpToDate$ -fixdocs'; DO NOT EDIT.
// Edit the documentation in other files and then execute 'go generate cmd/go' to generate this one.
// Go is a tool for managing Go source code.

View File

@ -26,7 +26,7 @@ func Help(w io.Writer, args []string) {
fmt.Fprintln(w, "// Use of this source code is governed by a BSD-style")
fmt.Fprintln(w, "// license that can be found in the LICENSE file.")
fmt.Fprintln(w)
fmt.Fprintln(w, "// Code generated by 'go test cmd/go -v -run=TestDocsUpToDate -fixdocs'; DO NOT EDIT.")
fmt.Fprintln(w, "// Code generated by 'go test cmd/go -v -run=^TestDocsUpToDate$ -fixdocs'; DO NOT EDIT.")
fmt.Fprintln(w, "// Edit the documentation in other files and then execute 'go generate cmd/go' to generate this one.")
fmt.Fprintln(w)
buf := new(strings.Builder)

View File

@ -238,7 +238,7 @@ func TestSpuriousEDEADLK(t *testing.T) {
t.Fatal(err)
}
cmd := testenv.Command(t, os.Args[0], "-test.run="+t.Name())
cmd := testenv.Command(t, os.Args[0], "-test.run=^"+t.Name()+"$")
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", dirVar, dir))
qDone := make(chan struct{})

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate go test cmd/go -v -run=TestDocsUpToDate -fixdocs
//go:generate go test cmd/go -v -run=^TestDocsUpToDate$ -fixdocs
package main

View File

@ -701,7 +701,7 @@ func TestExitCode(t *testing.T) {
}
for _, test := range tests {
cmd := exec.Command(os.Args[0], "-test.run=TestExitCode")
cmd := exec.Command(os.Args[0], "-test.run=^TestExitCode$")
cmd.Env = append(
os.Environ(),
"GO_CHILD_FLAG="+test.flag,

View File

@ -30,7 +30,7 @@ func runDebugOptionsTest(t *testing.T, test string, options string) {
env := "GODEBUG=" + options
cmd := exec.Command(os.Args[0], "-test.run="+test)
cmd := exec.Command(os.Args[0], "-test.run=^"+test+"$")
cmd.Env = append(cmd.Env, env)
output, err := cmd.CombinedOutput()

View File

@ -72,7 +72,7 @@ func TestMetrics(t *testing.T) {
func TestCmdBisect(t *testing.T) {
testenv.MustHaveGoBuild(t)
out, err := exec.Command("go", "run", "cmd/vendor/golang.org/x/tools/cmd/bisect", "GODEBUG=buggy=1#PATTERN", os.Args[0], "-test.run=BisectTestCase").CombinedOutput()
out, err := exec.Command("go", "run", "cmd/vendor/golang.org/x/tools/cmd/bisect", "GODEBUG=buggy=1#PATTERN", os.Args[0], "-test.run=^TestBisectTestCase$").CombinedOutput()
if err != nil {
t.Fatalf("exec bisect: %v\n%s", err, out)
}
@ -101,7 +101,7 @@ func TestCmdBisect(t *testing.T) {
// This test does nothing by itself, but you can run
//
// bisect 'GODEBUG=buggy=1#PATTERN' go test -run=BisectTestCase
// bisect 'GODEBUG=buggy=1#PATTERN' go test -run='^TestBisectTestCase$'
//
// to see that the GODEBUG bisect support is working.
// TestCmdBisect above does exactly that.

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:generate go test . -run=TestGenerated -fix
//go:generate go test . -run=^TestGenerated$ -fix
package platform

View File

@ -29,7 +29,7 @@ func TestRunAtLowIntegrity(t *testing.T) {
return
}
cmd := exec.Command(os.Args[0], "-test.run=TestRunAtLowIntegrity", "--")
cmd := exec.Command(os.Args[0], "-test.run=^TestRunAtLowIntegrity$", "--")
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
token, err := getIntegrityLevelToken(sidWilLow)

View File

@ -15,7 +15,7 @@
// Calculates lower and upper thresholds for when basicSqr
// is faster than standard multiplication.
// Usage: go test -run=TestCalibrate -v -calibrate
// Usage: go test -run='^TestCalibrate$' -v -calibrate
package big

View File

@ -31,7 +31,7 @@ func TestHostingOurselves(t *testing.T) {
h := &Handler{
Path: os.Args[0],
Root: "/test.go",
Args: []string{"-test.run=TestBeChildCGIProcess"},
Args: []string{"-test.run=^TestBeChildCGIProcess$"},
}
expectedMap := map[string]string{
"test": "Hello CGI-in-CGI",
@ -98,7 +98,7 @@ func TestKillChildAfterCopyError(t *testing.T) {
h := &Handler{
Path: os.Args[0],
Root: "/test.go",
Args: []string{"-test.run=TestBeChildCGIProcess"},
Args: []string{"-test.run=^TestBeChildCGIProcess$"},
}
req, _ := http.NewRequest("GET", "http://example.com/test.cgi?write-forever=1", nil)
rec := httptest.NewRecorder()
@ -120,7 +120,7 @@ func TestChildOnlyHeaders(t *testing.T) {
h := &Handler{
Path: os.Args[0],
Root: "/test.go",
Args: []string{"-test.run=TestBeChildCGIProcess"},
Args: []string{"-test.run=^TestBeChildCGIProcess$"},
}
expectedMap := map[string]string{
"_body": "",
@ -139,7 +139,7 @@ func TestNilRequestBody(t *testing.T) {
h := &Handler{
Path: os.Args[0],
Root: "/test.go",
Args: []string{"-test.run=TestBeChildCGIProcess"},
Args: []string{"-test.run=^TestBeChildCGIProcess$"},
}
expectedMap := map[string]string{
"nil-request-body": "false",
@ -154,7 +154,7 @@ func TestChildContentType(t *testing.T) {
h := &Handler{
Path: os.Args[0],
Root: "/test.go",
Args: []string{"-test.run=TestBeChildCGIProcess"},
Args: []string{"-test.run=^TestBeChildCGIProcess$"},
}
var tests = []struct {
name string
@ -202,7 +202,7 @@ func want500Test(t *testing.T, path string) {
h := &Handler{
Path: os.Args[0],
Root: "/test.go",
Args: []string{"-test.run=TestBeChildCGIProcess"},
Args: []string{"-test.run=^TestBeChildCGIProcess$"},
}
expectedMap := map[string]string{
"_body": "",

View File

@ -1280,7 +1280,7 @@ func TestLinuxSendfile(t *testing.T) {
defer os.Remove(filepath)
var buf strings.Builder
child := testenv.Command(t, "strace", "-f", "-q", os.Args[0], "-test.run=TestLinuxSendfileChild")
child := testenv.Command(t, "strace", "-f", "-q", os.Args[0], "-test.run=^TestLinuxSendfileChild$")
child.ExtraFiles = append(child.ExtraFiles, lnf)
child.Env = append([]string{"GO_WANT_HELPER_PROCESS=1"}, os.Environ()...)
child.Stdout = &buf

View File

@ -77,7 +77,7 @@ func newLocalListener() net.Listener {
// When debugging a particular http server-based test,
// this flag lets you run
//
// go test -run=BrokenTest -httptest.serve=127.0.0.1:8000
// go test -run='^BrokenTest$' -httptest.serve=127.0.0.1:8000
//
// to start the broken server so you can interact with it manually.
// We only register this flag if it looks like the caller knows about it

View File

@ -4992,7 +4992,7 @@ func benchmarkClientServerParallel(b *testing.B, parallelism int, mode testMode)
// For use like:
//
// $ go test -c
// $ ./http.test -test.run=XX -test.bench=BenchmarkServer -test.benchtime=15s -test.cpuprofile=http.prof
// $ ./http.test -test.run=XX -test.bench='^BenchmarkServer$' -test.benchtime=15s -test.cpuprofile=http.prof
// $ go tool pprof http.test http.prof
// (pprof) web
func BenchmarkServer(b *testing.B) {
@ -5031,7 +5031,7 @@ func BenchmarkServer(b *testing.B) {
defer ts.Close()
b.StartTimer()
cmd := testenv.Command(b, os.Args[0], "-test.run=XXXX", "-test.bench=BenchmarkServer$")
cmd := testenv.Command(b, os.Args[0], "-test.run=XXXX", "-test.bench=^BenchmarkServer$")
cmd.Env = append([]string{
fmt.Sprintf("TEST_BENCH_CLIENT_N=%d", b.N),
fmt.Sprintf("TEST_BENCH_SERVER_URL=%s", ts.URL),
@ -5086,7 +5086,7 @@ func BenchmarkClient(b *testing.B) {
// Start server process.
ctx, cancel := context.WithCancel(context.Background())
cmd := testenv.CommandContext(b, ctx, os.Args[0], "-test.run=XXXX", "-test.bench=BenchmarkClient$")
cmd := testenv.CommandContext(b, ctx, os.Args[0], "-test.run=XXXX", "-test.bench=^BenchmarkClient$")
cmd.Env = append(cmd.Environ(), "TEST_BENCH_SERVER=yes")
cmd.Stderr = os.Stderr
stdout, err := cmd.StdoutPipe()

View File

@ -2609,7 +2609,7 @@ func TestGetppid(t *testing.T) {
testenv.MustHaveExec(t)
t.Parallel()
cmd := testenv.Command(t, Args[0], "-test.run=TestGetppid")
cmd := testenv.Command(t, Args[0], "-test.run=^TestGetppid$")
cmd.Env = append(Environ(), "GO_WANT_HELPER_PROCESS=1")
// verify that Getppid() from the forked process reports our process id

View File

@ -1228,7 +1228,7 @@ func TestRootDirAsTemp(t *testing.T) {
t.Skip(err)
}
cmd := testenv.Command(t, exe, "-test.run=TestRootDirAsTemp")
cmd := testenv.Command(t, exe, "-test.run=^TestRootDirAsTemp$")
cmd.Env = cmd.Environ()
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
cmd.Env = append(cmd.Env, "TMP="+newtmp)

View File

@ -263,7 +263,7 @@ func TestReadNonblockingFd(t *testing.T) {
}
defer r.Close()
defer w.Close()
cmd := testenv.Command(t, os.Args[0], "-test.run="+t.Name())
cmd := testenv.Command(t, os.Args[0], "-test.run=^"+t.Name()+"$")
cmd.Env = append(cmd.Environ(), "GO_WANT_READ_NONBLOCKING_FD=1")
cmd.Stdin = r
output, err := cmd.CombinedOutput()

View File

@ -489,7 +489,7 @@ func TestRemoveAllNoFcntl(t *testing.T) {
}
}
cmd := testenv.Command(t, "/bin/strace", "-f", "-e", "fcntl", me, "-test.run=TestRemoveAllNoFcntl")
cmd := testenv.Command(t, "/bin/strace", "-f", "-e", "fcntl", me, "-test.run=^TestRemoveAllNoFcntl$")
cmd = testenv.CleanCmdEnv(cmd)
cmd.Env = append(cmd.Env, env+"="+subdir)
out, err := cmd.CombinedOutput()

View File

@ -130,7 +130,7 @@ func TestTerminalSignal(t *testing.T) {
var (
ctx = context.Background()
cmdArgs = []string{"-test.run=TestTerminalSignal"}
cmdArgs = []string{"-test.run=^TestTerminalSignal$"}
)
if deadline, ok := t.Deadline(); ok {
d := time.Until(deadline)
@ -250,7 +250,7 @@ func runSessionLeader(t *testing.T, pause time.Duration) {
var (
ctx = context.Background()
cmdArgs = []string{"-test.run=TestTerminalSignal"}
cmdArgs = []string{"-test.run=^TestTerminalSignal$"}
)
if deadline, ok := t.Deadline(); ok {
d := time.Until(deadline)

View File

@ -304,7 +304,7 @@ func TestDetectNohup(t *testing.T) {
// We have no intention of reading from c.
c := make(chan os.Signal, 1)
Notify(c, syscall.SIGHUP)
if out, err := testenv.Command(t, os.Args[0], "-test.run=TestDetectNohup", "-check_sighup_ignored").CombinedOutput(); err == nil {
if out, err := testenv.Command(t, os.Args[0], "-test.run=^TestDetectNohup$", "-check_sighup_ignored").CombinedOutput(); err == nil {
t.Errorf("ran test with -check_sighup_ignored and it succeeded: expected failure.\nOutput:\n%s", out)
}
Stop(c)
@ -315,7 +315,7 @@ func TestDetectNohup(t *testing.T) {
}
Ignore(syscall.SIGHUP)
os.Remove("nohup.out")
out, err := testenv.Command(t, "/usr/bin/nohup", os.Args[0], "-test.run=TestDetectNohup", "-check_sighup_ignored").CombinedOutput()
out, err := testenv.Command(t, "/usr/bin/nohup", os.Args[0], "-test.run=^TestDetectNohup$", "-check_sighup_ignored").CombinedOutput()
data, _ := os.ReadFile("nohup.out")
os.Remove("nohup.out")
@ -440,7 +440,7 @@ func TestNohup(t *testing.T) {
args := []string{
"-test.v",
"-test.run=TestStop",
"-test.run=^TestStop$",
"-send_uncaught_sighup=" + strconv.Itoa(i),
"-die_from_sighup",
}
@ -491,7 +491,7 @@ func TestNohup(t *testing.T) {
args := []string{
os.Args[0],
"-test.v",
"-test.run=TestStop",
"-test.run=^TestStop$",
"-send_uncaught_sighup=" + strconv.Itoa(i),
}
if subTimeout != 0 {
@ -546,7 +546,7 @@ func TestAtomicStop(t *testing.T) {
if deadline, ok := t.Deadline(); ok {
timeout = time.Until(deadline).String()
}
cmd := testenv.Command(t, os.Args[0], "-test.run=TestAtomicStop", "-test.timeout="+timeout)
cmd := testenv.Command(t, os.Args[0], "-test.run=^TestAtomicStop$", "-test.timeout="+timeout)
cmd.Env = append(os.Environ(), "GO_TEST_ATOMIC_STOP=1")
out, err := cmd.CombinedOutput()
if err == nil {
@ -742,7 +742,7 @@ func TestNotifyContextNotifications(t *testing.T) {
args := []string{
"-test.v",
"-test.run=TestNotifyContextNotifications$",
"-test.run=^TestNotifyContextNotifications$",
"-check_notify_ctx",
fmt.Sprintf("-ctx_notify_times=%d", tc.n),
}

View File

@ -40,7 +40,7 @@ func TestFinalizerRegisterABI(t *testing.T) {
// Actually run the test in a subprocess because we don't want
// finalizers from other tests interfering.
if os.Getenv("TEST_FINALIZER_REGABI") != "1" {
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestFinalizerRegisterABI", "-test.v"))
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=^TestFinalizerRegisterABI$", "-test.v"))
cmd.Env = append(cmd.Env, "TEST_FINALIZER_REGABI=1")
out, err := cmd.CombinedOutput()
if !strings.Contains(string(out), "PASS\n") || err != nil {

View File

@ -777,7 +777,7 @@ func init() {
func TestRuntimePanic(t *testing.T) {
testenv.MustHaveExec(t)
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestRuntimePanic"))
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=^TestRuntimePanic$"))
cmd.Env = append(cmd.Env, "GO_TEST_RUNTIME_PANIC=1")
out, err := cmd.CombinedOutput()
t.Logf("%s", out)
@ -798,7 +798,7 @@ func TestG0StackOverflow(t *testing.T) {
}
if os.Getenv("TEST_G0_STACK_OVERFLOW") != "1" {
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestG0StackOverflow", "-test.v"))
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=^TestG0StackOverflow$", "-test.v"))
cmd.Env = append(cmd.Env, "TEST_G0_STACK_OVERFLOW=1")
out, err := cmd.CombinedOutput()
// Don't check err since it's expected to crash.

View File

@ -268,7 +268,7 @@ func TestArenaCollision(t *testing.T) {
// Test that mheap.sysAlloc handles collisions with other
// memory mappings.
if os.Getenv("TEST_ARENA_COLLISION") != "1" {
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestArenaCollision", "-test.v"))
cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=^TestArenaCollision$", "-test.v"))
cmd.Env = append(cmd.Env, "TEST_ARENA_COLLISION=1")
out, err := cmd.CombinedOutput()
if race.Enabled {

View File

@ -47,8 +47,8 @@ func TestUsingVDSO(t *testing.T) {
t.Skipf("skipping because Executable failed: %v", err)
}
t.Logf("GO_WANT_HELPER_PROCESS=1 %s -f -e clock_gettime %s -test.run=TestUsingVDSO", strace, exe)
cmd := testenv.Command(t, strace, "-f", "-e", "clock_gettime", exe, "-test.run=TestUsingVDSO")
t.Logf("GO_WANT_HELPER_PROCESS=1 %s -f -e clock_gettime %s -test.run=^TestUsingVDSO$", strace, exe)
cmd := testenv.Command(t, strace, "-f", "-e", "clock_gettime", exe, "-test.run=^TestUsingVDSO$")
cmd = testenv.CleanCmdEnv(cmd)
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
out, err := cmd.CombinedOutput()

View File

@ -242,7 +242,7 @@ func TestUnshareMountNameSpace(t *testing.T) {
syscall.Unmount(d, syscall.MNT_FORCE)
}
})
cmd := testenv.Command(t, exe, "-test.run=TestUnshareMountNameSpace", d)
cmd := testenv.Command(t, exe, "-test.run=^TestUnshareMountNameSpace$", d)
cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1")
cmd.SysProcAttr = &syscall.SysProcAttr{Unshareflags: syscall.CLONE_NEWNS}
@ -305,7 +305,7 @@ func TestUnshareMountNameSpaceChroot(t *testing.T) {
t.Fatalf("%v: %v\n%s", cmd, err, o)
}
cmd = testenv.Command(t, "/syscall.test", "-test.run=TestUnshareMountNameSpaceChroot", "/")
cmd = testenv.Command(t, "/syscall.test", "-test.run=^TestUnshareMountNameSpaceChroot$", "/")
cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1")
cmd.SysProcAttr = &syscall.SysProcAttr{Chroot: d, Unshareflags: syscall.CLONE_NEWNS}
@ -356,7 +356,7 @@ func TestUnshareUidGidMapping(t *testing.T) {
t.Fatal(err)
}
cmd := testenv.Command(t, exe, "-test.run=TestUnshareUidGidMapping")
cmd := testenv.Command(t, exe, "-test.run=^TestUnshareUidGidMapping$")
cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1")
cmd.SysProcAttr = &syscall.SysProcAttr{
Unshareflags: syscall.CLONE_NEWNS | syscall.CLONE_NEWUSER,
@ -453,7 +453,7 @@ func TestUseCgroupFD(t *testing.T) {
fd, suffix := prepareCgroupFD(t)
cmd := testenv.Command(t, exe, "-test.run=TestUseCgroupFD")
cmd := testenv.Command(t, exe, "-test.run=^TestUseCgroupFD$")
cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1")
cmd.SysProcAttr = &syscall.SysProcAttr{
UseCgroupFD: true,
@ -494,7 +494,7 @@ func TestCloneTimeNamespace(t *testing.T) {
t.Fatal(err)
}
cmd := testenv.Command(t, exe, "-test.run=TestCloneTimeNamespace")
cmd := testenv.Command(t, exe, "-test.run=^TestCloneTimeNamespace$")
cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1")
cmd.SysProcAttr = &syscall.SysProcAttr{
Cloneflags: syscall.CLONE_NEWTIME,
@ -632,7 +632,7 @@ func testAmbientCaps(t *testing.T, userns bool) {
t.Fatal(err)
}
cmd := testenv.Command(t, f.Name(), "-test.run="+t.Name())
cmd := testenv.Command(t, f.Name(), "-test.run=^"+t.Name()+"$")
cmd.Env = append(cmd.Environ(), "GO_WANT_HELPER_PROCESS=1")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

View File

@ -310,7 +310,7 @@ func TestInvalidExec(t *testing.T) {
// TestExec is for issue #41702.
func TestExec(t *testing.T) {
testenv.MustHaveExec(t)
cmd := exec.Command(os.Args[0], "-test.run=TestExecHelper")
cmd := exec.Command(os.Args[0], "-test.run=^TestExecHelper$")
cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=2")
o, err := cmd.CombinedOutput()
if err != nil {
@ -343,7 +343,7 @@ func TestExecHelper(t *testing.T) {
time.Sleep(10 * time.Millisecond)
argv := []string{os.Args[0], "-test.run=TestExecHelper"}
argv := []string{os.Args[0], "-test.run=^TestExecHelper$"}
syscall.Exec(os.Args[0], argv, os.Environ())
t.Error("syscall.Exec returned")
@ -366,7 +366,7 @@ func TestRlimitRestored(t *testing.T) {
executable = os.Args[0]
}
cmd := testenv.Command(t, executable, "-test.run=TestRlimitRestored")
cmd := testenv.Command(t, executable, "-test.run=^TestRlimitRestored$")
cmd = testenv.CleanCmdEnv(cmd)
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")

View File

@ -73,7 +73,7 @@ func TestChangingProcessParent(t *testing.T) {
// run parent process
parent := exec.Command(os.Args[0], "-test.run=TestChangingProcessParent")
parent := exec.Command(os.Args[0], "-test.run=^TestChangingProcessParent$")
parent.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=parent")
err := parent.Start()
if err != nil {
@ -96,7 +96,7 @@ func TestChangingProcessParent(t *testing.T) {
}
defer syscall.CloseHandle(ph)
child := exec.Command(os.Args[0], "-test.run=TestChangingProcessParent")
child := exec.Command(os.Args[0], "-test.run=^TestChangingProcessParent$")
child.Env = append(os.Environ(),
"GO_WANT_HELPER_PROCESS=child",
"GO_WANT_HELPER_PROCESS_FILE="+childDumpPath)

View File

@ -32,7 +32,7 @@ func TestFlag(t *testing.T) {
if err != nil {
exe = os.Args[0]
}
cmd := exec.Command(exe, "-test.run=TestFlag", "-test_flag_arg="+flag)
cmd := exec.Command(exe, "-test.run=^TestFlag$", "-test_flag_arg="+flag)
if flag != "" {
cmd.Args = append(cmd.Args, flag)
}

View File

@ -139,7 +139,7 @@ ran outer cleanup
}}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
cmd := exec.Command(os.Args[0], "-test.run=TestPanicHelper")
cmd := exec.Command(os.Args[0], "-test.run=^TestPanicHelper$")
cmd.Args = append(cmd.Args, tc.flags...)
cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
b, _ := cmd.CombinedOutput()
@ -220,13 +220,13 @@ func TestMorePanic(t *testing.T) {
}{
{
desc: "Issue 48502: call runtime.Goexit in t.Cleanup after panic",
flags: []string{"-test.run=TestGoexitInCleanupAfterPanicHelper"},
flags: []string{"-test.run=^TestGoexitInCleanupAfterPanicHelper$"},
want: `panic: die
panic: test executed panic(nil) or runtime.Goexit`,
},
{
desc: "Issue 48515: call t.Run in t.Cleanup should trigger panic",
flags: []string{"-test.run=TestCallRunInCleanupHelper"},
flags: []string{"-test.run=^TestCallRunInCleanupHelper$"},
want: `panic: testing: t.Run called during t.Cleanup`,
},
}