Skip to content

Commit 0dfb22e

Browse files
dmitshurgopherbot
authored andcommitted
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 <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Kirill Kolyshkin <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent cffdfe8 commit 0dfb22e

31 files changed

+57
-57
lines changed

src/cmd/cgo/internal/test/issue18146.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func test18146(t *testing.T) {
8585
}
8686
}()
8787

88-
args := append(append([]string(nil), os.Args[1:]...), "-test.run=Test18146")
88+
args := append(append([]string(nil), os.Args[1:]...), "-test.run=^Test18146$")
8989
for n := attempts; n > 0; n-- {
9090
cmd := exec.Command(os.Args[0], args...)
9191
cmd.Env = append(os.Environ(), "test18146=exec")

src/cmd/compile/internal/test/ssa_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func TestCode(t *testing.T) {
169169
continue
170170
}
171171
t.Run(fmt.Sprintf("%s%s", test.name[4:], flag), func(t *testing.T) {
172-
out, err := testenv.Command(t, filepath.Join(tmpdir, "code.test"), "-test.run="+test.name).CombinedOutput()
172+
out, err := testenv.Command(t, filepath.Join(tmpdir, "code.test"), "-test.run=^"+test.name+"$").CombinedOutput()
173173
if err != nil || string(out) != "PASS\n" {
174174
t.Errorf("Failed:\n%s\n", out)
175175
}

src/cmd/go/alldocs.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/help/help.go

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

src/cmd/go/internal/lockedfile/lockedfile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func TestSpuriousEDEADLK(t *testing.T) {
238238
t.Fatal(err)
239239
}
240240

241-
cmd := testenv.Command(t, os.Args[0], "-test.run="+t.Name())
241+
cmd := testenv.Command(t, os.Args[0], "-test.run=^"+t.Name()+"$")
242242
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", dirVar, dir))
243243

244244
qDone := make(chan struct{})

src/cmd/go/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:generate go test cmd/go -v -run=TestDocsUpToDate -fixdocs
5+
//go:generate go test cmd/go -v -run=^TestDocsUpToDate$ -fixdocs
66

77
package main
88

src/flag/flag_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ func TestExitCode(t *testing.T) {
701701
}
702702

703703
for _, test := range tests {
704-
cmd := exec.Command(os.Args[0], "-test.run=TestExitCode")
704+
cmd := exec.Command(os.Args[0], "-test.run=^TestExitCode$")
705705
cmd.Env = append(
706706
os.Environ(),
707707
"GO_CHILD_FLAG="+test.flag,

src/internal/cpu/cpu_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func runDebugOptionsTest(t *testing.T, test string, options string) {
3030

3131
env := "GODEBUG=" + options
3232

33-
cmd := exec.Command(os.Args[0], "-test.run="+test)
33+
cmd := exec.Command(os.Args[0], "-test.run=^"+test+"$")
3434
cmd.Env = append(cmd.Env, env)
3535

3636
output, err := cmd.CombinedOutput()

src/internal/godebug/godebug_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestMetrics(t *testing.T) {
7272

7373
func TestCmdBisect(t *testing.T) {
7474
testenv.MustHaveGoBuild(t)
75-
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()
75+
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()
7676
if err != nil {
7777
t.Fatalf("exec bisect: %v\n%s", err, out)
7878
}
@@ -101,7 +101,7 @@ func TestCmdBisect(t *testing.T) {
101101

102102
// This test does nothing by itself, but you can run
103103
//
104-
// bisect 'GODEBUG=buggy=1#PATTERN' go test -run=BisectTestCase
104+
// bisect 'GODEBUG=buggy=1#PATTERN' go test -run='^TestBisectTestCase$'
105105
//
106106
// to see that the GODEBUG bisect support is working.
107107
// TestCmdBisect above does exactly that.

src/internal/platform/supported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:generate go test . -run=TestGenerated -fix
5+
//go:generate go test . -run=^TestGenerated$ -fix
66

77
package platform
88

0 commit comments

Comments
 (0)