diff options
| author | Dmitri Shuralyov <dmitshur@golang.org> | 2023-09-03 14:23:02 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-09-05 23:35:29 +0000 |
| commit | 0dfb22ed70749a2cd6d95ec6eee63bb213a940d4 (patch) | |
| tree | ba421b5cae00d9541f48ab2710a76e7fd722adda /src/cmd | |
| parent | cffdfe8d2cabbe874bceaeed1eba92cc567be6db (diff) | |
| download | go-0dfb22ed70749a2cd6d95ec6eee63bb213a940d4.tar.xz | |
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>
Diffstat (limited to 'src/cmd')
| -rw-r--r-- | src/cmd/cgo/internal/test/issue18146.go | 2 | ||||
| -rw-r--r-- | src/cmd/compile/internal/test/ssa_test.go | 2 | ||||
| -rw-r--r-- | src/cmd/go/alldocs.go | 2 | ||||
| -rw-r--r-- | src/cmd/go/internal/help/help.go | 2 | ||||
| -rw-r--r-- | src/cmd/go/internal/lockedfile/lockedfile_test.go | 2 | ||||
| -rw-r--r-- | src/cmd/go/main.go | 2 |
6 files changed, 6 insertions, 6 deletions
diff --git a/src/cmd/cgo/internal/test/issue18146.go b/src/cmd/cgo/internal/test/issue18146.go index d302bd029f..b9255234eb 100644 --- a/src/cmd/cgo/internal/test/issue18146.go +++ b/src/cmd/cgo/internal/test/issue18146.go @@ -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") diff --git a/src/cmd/compile/internal/test/ssa_test.go b/src/cmd/compile/internal/test/ssa_test.go index 5f8acdc72d..7f2faa1140 100644 --- a/src/cmd/compile/internal/test/ssa_test.go +++ b/src/cmd/compile/internal/test/ssa_test.go @@ -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) } diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 2c8f59e682..3174c6af32 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -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. diff --git a/src/cmd/go/internal/help/help.go b/src/cmd/go/internal/help/help.go index c36dae822e..501f08eb2d 100644 --- a/src/cmd/go/internal/help/help.go +++ b/src/cmd/go/internal/help/help.go @@ -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) diff --git a/src/cmd/go/internal/lockedfile/lockedfile_test.go b/src/cmd/go/internal/lockedfile/lockedfile_test.go index 8dea8f70c2..a9fa40b8df 100644 --- a/src/cmd/go/internal/lockedfile/lockedfile_test.go +++ b/src/cmd/go/internal/lockedfile/lockedfile_test.go @@ -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{}) diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index b85da97201..7d4dedc1bb 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -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 |
