aboutsummaryrefslogtreecommitdiff
path: root/src/os
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/os
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/os')
-rw-r--r--src/os/os_test.go2
-rw-r--r--src/os/os_windows_test.go2
-rw-r--r--src/os/pipe_test.go2
-rw-r--r--src/os/removeall_test.go2
-rw-r--r--src/os/signal/signal_cgo_test.go4
-rw-r--r--src/os/signal/signal_test.go12
6 files changed, 12 insertions, 12 deletions
diff --git a/src/os/os_test.go b/src/os/os_test.go
index c5776a9f29..25837dce9e 100644
--- a/src/os/os_test.go
+++ b/src/os/os_test.go
@@ -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
diff --git a/src/os/os_windows_test.go b/src/os/os_windows_test.go
index bfbe7ec815..90c1eabd96 100644
--- a/src/os/os_windows_test.go
+++ b/src/os/os_windows_test.go
@@ -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)
diff --git a/src/os/pipe_test.go b/src/os/pipe_test.go
index 6f01d30e24..a9e0c8bc8a 100644
--- a/src/os/pipe_test.go
+++ b/src/os/pipe_test.go
@@ -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()
diff --git a/src/os/removeall_test.go b/src/os/removeall_test.go
index 2f7938bb5c..c0b2dd6505 100644
--- a/src/os/removeall_test.go
+++ b/src/os/removeall_test.go
@@ -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()
diff --git a/src/os/signal/signal_cgo_test.go b/src/os/signal/signal_cgo_test.go
index 5e85f45e70..9e9a9fe526 100644
--- a/src/os/signal/signal_cgo_test.go
+++ b/src/os/signal/signal_cgo_test.go
@@ -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)
diff --git a/src/os/signal/signal_test.go b/src/os/signal/signal_test.go
index e5af885511..e7575eb70e 100644
--- a/src/os/signal/signal_test.go
+++ b/src/os/signal/signal_test.go
@@ -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),
}