]> Cypherpunks.ru repositories - gostls13.git/commitdiff
all: use ^TestName$ regular pattern for invoking a single test
authorDmitri Shuralyov <dmitshur@golang.org>
Sun, 3 Sep 2023 18:23:02 +0000 (14:23 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 5 Sep 2023 23:35:29 +0000 (23:35 +0000)
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>

31 files changed:
src/cmd/cgo/internal/test/issue18146.go
src/cmd/compile/internal/test/ssa_test.go
src/cmd/go/alldocs.go
src/cmd/go/internal/help/help.go
src/cmd/go/internal/lockedfile/lockedfile_test.go
src/cmd/go/main.go
src/flag/flag_test.go
src/internal/cpu/cpu_test.go
src/internal/godebug/godebug_test.go
src/internal/platform/supported.go
src/internal/syscall/windows/exec_windows_test.go
src/math/big/calibrate_test.go
src/net/http/cgi/integration_test.go
src/net/http/fs_test.go
src/net/http/httptest/server.go
src/net/http/serve_test.go
src/os/os_test.go
src/os/os_windows_test.go
src/os/pipe_test.go
src/os/removeall_test.go
src/os/signal/signal_cgo_test.go
src/os/signal/signal_test.go
src/runtime/abi_test.go
src/runtime/crash_test.go
src/runtime/malloc_test.go
src/runtime/vdso_test.go
src/syscall/exec_linux_test.go
src/syscall/exec_unix_test.go
src/syscall/exec_windows_test.go
src/testing/flag_test.go
src/testing/panic_test.go

index d302bd029fa26ecab45df69e5baf53f989df7584..b9255234eb345f3f24c5ad6d1738b0c024a20669 100644 (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")
index 5f8acdc72d5a81315c632c5cb936fde8f1d39747..7f2faa1140d445438c5ee2fb447a6ab50b7756b4 100644 (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)
                                }
index 2c8f59e6820e8566ccc73ae535f3ebd163a189aa..3174c6af32608d12a2264f1c4fedb66ecce6b97a 100644 (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.
index c36dae822e9fb2b3add46ad977cf6e5bad2cfaf9..501f08eb2d63cbbdbc3f901dd62fe0ea542a069b 100644 (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)
index 8dea8f70c2619fd1d71e4cce846539354c89ddd8..a9fa40b8df22a7f641734db4bc1b031f953c12c3 100644 (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{})
index b85da972011bf9a796fd69db9c97cd2533abba5c..7d4dedc1bb0137a3df9813ea2e8ba22d5cfcc4d2 100644 (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
 
index 57c88f009f1c4f6da7d80fb54181e5c879f0836e..8e9ae316fe0e7dbbe234d7b44992dec734ff9cc5 100644 (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,
index b8c74f2e9cb6e7e203dd42f0892b26046e3016c6..a6fe7f77f34585f344ae4879ecdda51467f35dbb 100644 (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()
index 8e46283adab3267a9f7bf671791748c03eecaf00..ed8e93d453fd4feb70102417716bf9748fe3154c 100644 (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.
index b1e550ef32d6ccde08adb2583c494e48cb7256db..4589903550c29526299d16285a5a1a60edfe7b48 100644 (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
 
index 3311da5474164620b6fa65e00084f9c453df53c1..72550b5a84eac8eb49842be70702ba0c9f8ca458 100644 (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)
index 4fa663ff08331e850b0412edd336b388c7f35809..d85833aedef619937716a943f5ed2058009c868d 100644 (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
 
index ef2eaf748bdb66df7071530e8cf2a57630fff567..4890ae0707852fcb4b8a7603a3a70ac7ec46513f 100644 (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": "",
index 2e1577365264618f98385e432e19d99ab10dae2b..cfabaae3539be8f4d0c5feac81084afc5dc11290 100644 (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
index f254a494d162d947f8fa2e51faf761468343fe93..79749a0378df0e609513dab5602c6fa6d7ef3d74 100644 (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
index e71c5365e14c31a7b89fdfb7654597c2497b157a..2473a88056c96bd15797d1d0ea6dad3f26b0f9d5 100644 (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()
index c5776a9f293f56ac81eca3432dc64239224f2eac..25837dce9eeb63024b75dc064d6c9deaf2ae1b77 100644 (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
index bfbe7ec81519517b6c2c5f33e50b4df8e78f939b..90c1eabd962775aad8c715e60c7a35b913298101 100644 (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)
index 6f01d30e2447eae282af91f36afe3fb4454c3ae2..a9e0c8bc8a9d2c71693681d1858f5facb56e5d6b 100644 (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()
index 2f7938bb5c4298fc54307339fab4eb9f37539176..c0b2dd6505608c4f39d1b4827cf771f1b04dfac5 100644 (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()
index 5e85f45e705ef3aa33f479794924f91b542c95e8..9e9a9fe52655803010c477d70c486486b1c151f6 100644 (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)
index e5af885511983fe152837bf46b7a4c7e052af37c..e7575eb70e2c7d78248f10f5d2e91a449b16f681 100644 (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),
                        }
index 0c9488a5f4ee596f7fb01d9b1890cce3b1208164..d7039e758a4bb503d54c94b0da9ab5f0b28858ec 100644 (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 {
index df75658750f271211c009d0b0d811637f2684c8d..2c990c199ccaff8ec32bb2e13607bdd21ff23d8a 100644 (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.
index 5b9ce9882e2e1d0a0d9a3e33cc744db262da5a1f..8c162fbea4b158a2f3f69cc6b59b74f0a5d2a1b3 100644 (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 {
index 61f651614b44f93b42ccd8a81434502c08f408d6..126fd8d199ec801f2f7de1fcac9ceb7887d9b84a 100644 (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()
index d192b904d2e34ee096cd605f2613ae96cdc64d75..ca92a153f863624f9585a73e6f43ed47c31846b5 100644 (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
index 9627317bb38a9e373d9aca12c3b8d6e9de3ba1e0..accf6cc5c517836c13b4d8302f1f16cc7dbc09dd 100644 (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")
 
index 8b8f330e9910a515bb832e529b5b4dcce2c27dcd..5cacf42b6b92d016ab79d3e4850ba0a14fc9ec38 100644 (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)
index 416d8c986245423eeb07137e8d473b682daf8dd0..6f76c237c4bdf045f3b290201efb71777837c985 100644 (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)
                        }
index 8733bc3f30cef4067ea928ac72b2cfd9b1891543..6307b84a7a534b5c1d2a8f4d74626d7fcaf6efe0 100644 (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`,
                },
        }