]> Cypherpunks repositories - gostls13.git/commitdiff
all: surround -test.run arguments with ^$
authorqmuntal <quimmuntal@gmail.com>
Mon, 24 Feb 2025 08:57:04 +0000 (09:57 +0100)
committerQuim Muntal <quimmuntal@gmail.com>
Tue, 25 Feb 2025 18:58:29 +0000 (10:58 -0800)
If the -test.run value is not surrounded by ^$ then any test that
matches the -test.run value will be run. This is normally not the
desired behavior, as it can lead to unexpected tests being run.

Change-Id: I3447aaebad5156bbef7f263cdb9f6b8c32331324
Reviewed-on: https://go-review.googlesource.com/c/go/+/651956
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/go/testdata/script/test_fuzz_seed_corpus.txt
src/crypto/internal/fips140test/cast_test.go
src/crypto/internal/fips140test/check_test.go
src/crypto/internal/sysrand/rand_test.go
src/crypto/rand/rand_test.go
src/math/rand/default_test.go
src/net/net_windows_test.go
src/runtime/crash_test.go
src/runtime/debug/example_monitor_test.go
src/runtime/syscall_windows_test.go
src/syscall/exec_freebsd_test.go

index 3e3fbade2304f298697dc5d348771120e3a2a4b4..8a7a24ab70e61f49387c95e85225ff54d16d79af 100644 (file)
@@ -4,7 +4,7 @@ env GOCACHE=$WORK/cache
 
 # Test that fuzzing a target with a failure in f.Add prints the crash
 # and doesn't write anything to testdata/fuzz
-! go test -fuzz=FuzzWithAdd -run=FuzzWithAdd -fuzztime=1x
+! go test -fuzz=^FuzzWithAdd$ -run=^FuzzWithAdd$ -fuzztime=1x
 ! stdout ^ok
 ! stdout 'Failing input written to testdata[/\\]fuzz[/\\]FuzzWithAdd[/\\]'
 stdout FAIL
@@ -68,7 +68,7 @@ go clean -fuzzcache
 
 # Test that fuzzing a target (with -run=None set) with a failure in f.Add prints
 # the crash and doesn't write anything to testdata/fuzz -fuzztime=1x
-! go test -fuzz=FuzzWithAdd -run=None
+! go test -fuzz=^FuzzWithAdd$ -run=None
 ! stdout ^ok
 ! stdout 'Failing input written to testdata[/\\]fuzz[/\\]FuzzWithAdd[/\\]'
 stdout FAIL
@@ -107,14 +107,14 @@ go clean -fuzzcache
 # the seed corpus before attempting to fuzz.
 
 go test -c
-! exec ./x.test$GOEXE -test.fuzz=FuzzWithAdd -test.run=FuzzWithAdd -test.fuzztime=1x -test.fuzzcachedir=$WORK/cache
+! exec ./x.test$GOEXE -test.fuzz=^FuzzWithAdd$ -test.run=^FuzzWithAdd$ -test.fuzztime=1x -test.fuzzcachedir=$WORK/cache
 ! stdout ^ok
 ! stdout 'Failing input written to testdata[/\\]fuzz[/\\]FuzzWithAdd[/\\]'
 stdout FAIL
 stderr warning
 
 go test -c
-! exec ./x.test$GOEXE -test.fuzz=FuzzWithTestdata -test.run=FuzzWithTestdata -test.fuzztime=1x -test.fuzzcachedir=$WORK/cache
+! exec ./x.test$GOEXE -test.fuzz=FuzzWithTestdata -test.run=^FuzzWithTestdata$ -test.fuzztime=1x -test.fuzzcachedir=$WORK/cache
 ! stdout ^ok
 ! stdout 'Failing input written to testdata[/\\]fuzz[/\\]FuzzWithTestdata[/\\]'
 stdout FAIL
index 41122f339d1831ee63a1a06fe529c1c8fc8f8f83..1818b583d5ce2d5c1db94c17329d4e6eb6210a1c 100644 (file)
@@ -171,7 +171,7 @@ func TestCASTFailures(t *testing.T) {
                        }
                        t.Logf("CAST/PCT succeeded: %s", name)
                        t.Logf("Testing CAST/PCT failure...")
-                       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=TestConditionals", "-test.v")
+                       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^TestConditionals$", "-test.v")
                        cmd.Env = append(cmd.Env, fmt.Sprintf("GODEBUG=failfipscast=%s,fips140=on", name))
                        out, err := cmd.CombinedOutput()
                        t.Logf("%s", out)
index f516455fb4636aef3257bd001ad5a587058ce349..c4f6a95e3ecbe514eddb09e34e53680ef8ac1fbb 100644 (file)
@@ -35,7 +35,7 @@ func TestIntegrityCheck(t *testing.T) {
                t.Skipf("skipping: %v", err)
        }
 
-       cmd := testenv.Command(t, testenv.Executable(t), "-test.v", "-test.run=TestIntegrityCheck")
+       cmd := testenv.Command(t, testenv.Executable(t), "-test.v", "-test.run=^TestIntegrityCheck$")
        cmd.Env = append(cmd.Environ(), "GODEBUG=fips140=on")
        out, err := cmd.CombinedOutput()
        if err != nil {
@@ -74,7 +74,7 @@ func TestIntegrityCheckFailure(t *testing.T) {
        }
 
        t.Logf("running modified binary...")
-       cmd := testenv.Command(t, binPath, "-test.v", "-test.run=TestIntegrityCheck$")
+       cmd := testenv.Command(t, binPath, "-test.v", "-test.run=^TestIntegrityCheck$")
        cmd.Env = append(cmd.Environ(), "GODEBUG=fips140=on")
        out, err := cmd.CombinedOutput()
        t.Logf("%s", out)
index 55b11a929bd4d33061520a84a8773650bf36e4bb..1d8eb00f5669358bb7c5e430b1d21c03db084696 100644 (file)
@@ -105,7 +105,7 @@ func TestReadError(t *testing.T) {
                return
        }
 
-       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=TestReadError")
+       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^TestReadError$")
        cmd.Env = append(os.Environ(), "GO_TEST_READ_ERROR=1")
        out, err := cmd.CombinedOutput()
        if err == nil {
index 9047ac193bd009c6e2a41e67606b8219362643d4..22ccb8a35334c9f509282021ce10277248fdc176 100644 (file)
@@ -180,7 +180,7 @@ func TestReadError(t *testing.T) {
                return
        }
 
-       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=TestReadError")
+       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^TestReadError$")
        cmd.Env = append(os.Environ(), "GO_TEST_READ_ERROR=1")
        out, err := cmd.CombinedOutput()
        if err == nil {
index b42cd165c8fe94aae9b633996106e9fba4f2c663..0ba51b4dbd4f2c1576b707ac7229e4a54808d545 100644 (file)
@@ -37,7 +37,7 @@ func TestDefaultRace(t *testing.T) {
                i := i
                t.Run(strconv.Itoa(i), func(t *testing.T) {
                        t.Parallel()
-                       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=TestDefaultRace")
+                       cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^TestDefaultRace$")
                        cmd = testenv.CleanCmdEnv(cmd)
                        cmd.Env = append(cmd.Env, fmt.Sprintf("GO_RAND_TEST_HELPER_CODE=%d", i/2))
                        if i%2 != 0 {
index bc3171b4ea60c16ad56b414b8be8f7bca09df0d5..671de7678008ed9b3e87eac1d950ce4d624ee94e 100644 (file)
@@ -100,7 +100,7 @@ func TestAcceptIgnoreSomeErrors(t *testing.T) {
        defer ln.Close()
 
        // Start child process that connects to our listener.
-       cmd := exec.Command(testenv.Executable(t), "-test.run=TestAcceptIgnoreSomeErrors")
+       cmd := exec.Command(testenv.Executable(t), "-test.run=^TestAcceptIgnoreSomeErrors$")
        cmd.Env = append(os.Environ(), "GOTEST_DIAL_ADDR="+ln.Addr().String())
        stdout, err := cmd.StdoutPipe()
        if err != nil {
index 00e84a38797a7c5eea9b9b08a914180476b8541c..0265c28be13acada378e13099f487bc7066169c6 100644 (file)
@@ -901,7 +901,7 @@ func TestRuntimePanic(t *testing.T) {
 }
 
 func TestTracebackRuntimeFunction(t *testing.T) {
-       cmd := testenv.CleanCmdEnv(exec.Command(testenv.Executable(t), "-test.run=TestTracebackRuntimeFunction"))
+       cmd := testenv.CleanCmdEnv(exec.Command(testenv.Executable(t), "-test.run=^TestTracebackRuntimeFunction$"))
        cmd.Env = append(cmd.Env, "GO_TEST_RUNTIME_NPE_READMEMSTATS=1")
        out, err := cmd.CombinedOutput()
        t.Logf("%s", out)
@@ -913,7 +913,7 @@ func TestTracebackRuntimeFunction(t *testing.T) {
 }
 
 func TestTracebackRuntimeMethod(t *testing.T) {
-       cmd := testenv.CleanCmdEnv(exec.Command(testenv.Executable(t), "-test.run=TestTracebackRuntimeMethod"))
+       cmd := testenv.CleanCmdEnv(exec.Command(testenv.Executable(t), "-test.run=^TestTracebackRuntimeMethod$"))
        cmd.Env = append(cmd.Env, "GO_TEST_RUNTIME_NPE_FUNCMETHOD=1")
        out, err := cmd.CombinedOutput()
        t.Logf("%s", out)
index b077e7adb3139b0086998023521acc0e0d63489e..3b8f4dccd9f05325a8bd40fe9a3c0a4c70cbaec5 100644 (file)
@@ -83,7 +83,7 @@ func monitor() {
        if err != nil {
                log.Fatal(err)
        }
-       cmd := exec.Command(exe, "-test.run=ExampleSetCrashOutput_monitor")
+       cmd := exec.Command(exe, "-test.run=^ExampleSetCrashOutput_monitor$")
        cmd.Env = append(os.Environ(), monitorVar+"=1")
        cmd.Stderr = os.Stderr
        cmd.Stdout = os.Stderr
index 7a7269d125e396c0e8351a64d7c954595ec253fe..670926740356c252db4a11393c884683449e66de 100644 (file)
@@ -657,7 +657,7 @@ func TestWERDialogue(t *testing.T) {
        if err != nil {
                t.Fatal(err)
        }
-       cmd := testenv.CleanCmdEnv(testenv.Command(t, exe, "-test.run=TestWERDialogue"))
+       cmd := testenv.CleanCmdEnv(testenv.Command(t, exe, "-test.run=^TestWERDialogue$"))
        cmd.Env = append(cmd.Env, "TEST_WER_DIALOGUE=1", "GOTRACEBACK=wer")
        // Child process should not open WER dialogue, but return immediately instead.
        // The exit code can't be reliably tested here because Windows can change it.
@@ -1043,7 +1043,7 @@ func TestNumCPU(t *testing.T) {
        _GetProcessAffinityMask := kernel32.MustFindProc("GetProcessAffinityMask")
        _SetProcessAffinityMask := kernel32.MustFindProc("SetProcessAffinityMask")
 
-       cmd := exec.Command(testenv.Executable(t), "-test.run=TestNumCPU")
+       cmd := exec.Command(testenv.Executable(t), "-test.run=^TestNumCPU$")
        cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
        var buf strings.Builder
        cmd.Stdout = &buf
index 2e9513f0980dc898d2d639e16efa56d90a938f4c..34c4b9e2bbb6bcbeb990d512301f9d2bca98470c 100644 (file)
@@ -88,7 +88,7 @@ func TestJailAttach(t *testing.T) {
                t.Fatalf("Build of syscall in jail root failed, output %v, err %v", o, err)
        }
 
-       cmd = exec.Command("/syscall.test", "-test.run=TestJailAttach", "/")
+       cmd = exec.Command("/syscall.test", "-test.run=^TestJailAttach$", "/")
        cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
        cmd.SysProcAttr = &syscall.SysProcAttr{Jail: jid}
        out, err := cmd.CombinedOutput()