aboutsummaryrefslogtreecommitdiff
path: root/src/internal
diff options
context:
space:
mode:
authorDmitri Shuralyov <dmitshur@golang.org>2023-09-03 14:23:02 -0400
committerGopher Robot <gobot@golang.org>2023-09-05 23:35:29 +0000
commit0dfb22ed70749a2cd6d95ec6eee63bb213a940d4 (patch)
treeba421b5cae00d9541f48ab2710a76e7fd722adda /src/internal
parentcffdfe8d2cabbe874bceaeed1eba92cc567be6db (diff)
downloadgo-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/internal')
-rw-r--r--src/internal/cpu/cpu_test.go2
-rw-r--r--src/internal/godebug/godebug_test.go4
-rw-r--r--src/internal/platform/supported.go2
-rw-r--r--src/internal/syscall/windows/exec_windows_test.go2
4 files changed, 5 insertions, 5 deletions
diff --git a/src/internal/cpu/cpu_test.go b/src/internal/cpu/cpu_test.go
index b8c74f2e9c..a6fe7f77f3 100644
--- a/src/internal/cpu/cpu_test.go
+++ b/src/internal/cpu/cpu_test.go
@@ -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()
diff --git a/src/internal/godebug/godebug_test.go b/src/internal/godebug/godebug_test.go
index 8e46283ada..ed8e93d453 100644
--- a/src/internal/godebug/godebug_test.go
+++ b/src/internal/godebug/godebug_test.go
@@ -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.
diff --git a/src/internal/platform/supported.go b/src/internal/platform/supported.go
index b1e550ef32..4589903550 100644
--- a/src/internal/platform/supported.go
+++ b/src/internal/platform/supported.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 . -run=TestGenerated -fix
+//go:generate go test . -run=^TestGenerated$ -fix
package platform
diff --git a/src/internal/syscall/windows/exec_windows_test.go b/src/internal/syscall/windows/exec_windows_test.go
index 3311da5474..72550b5a84 100644
--- a/src/internal/syscall/windows/exec_windows_test.go
+++ b/src/internal/syscall/windows/exec_windows_test.go
@@ -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)