aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorKir Kolyshkin <kolyshkin@gmail.com>2024-08-29 19:06:57 -0700
committerDamien Neil <dneil@google.com>2024-09-03 18:03:28 +0000
commit6fa224a80965a32228f9bc13cfe667af500d0a9d (patch)
treebc8fd767d201982bfe61651a8069f2df1216c90d /src/testing
parentf26c29723f372284ff7dc0dbf30bae5561a3e618 (diff)
downloadgo-6fa224a80965a32228f9bc13cfe667af500d0a9d.tar.xz
testing: use testenv.Executable
Note that this changes some nuances of how the tests work: - some tests had a fallback to using os.Args[0], which is removed; - some tests skipped (rather than failed) the test upon getting an error from os.Executable. I think these changes are not practically relevant. Change-Id: I0655add6d959a8b7e3359f94c38203aa06e8f490 Reviewed-on: https://go-review.googlesource.com/c/go/+/609303 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/flag_test.go6
-rw-r--r--src/testing/helper_test.go16
-rw-r--r--src/testing/testing_test.go16
3 files changed, 5 insertions, 33 deletions
diff --git a/src/testing/flag_test.go b/src/testing/flag_test.go
index 6f76c237c4..6a7754425d 100644
--- a/src/testing/flag_test.go
+++ b/src/testing/flag_test.go
@@ -28,11 +28,7 @@ func TestFlag(t *testing.T) {
flag := flag
t.Run(flag, func(t *testing.T) {
t.Parallel()
- exe, err := os.Executable()
- if err != nil {
- exe = os.Args[0]
- }
- cmd := exec.Command(exe, "-test.run=^TestFlag$", "-test_flag_arg="+flag)
+ cmd := exec.Command(testenv.Executable(t), "-test.run=^TestFlag$", "-test_flag_arg="+flag)
if flag != "" {
cmd.Args = append(cmd.Args, flag)
}
diff --git a/src/testing/helper_test.go b/src/testing/helper_test.go
index da5622f85f..a698e79fa9 100644
--- a/src/testing/helper_test.go
+++ b/src/testing/helper_test.go
@@ -23,15 +23,9 @@ func TestTBHelper(t *testing.T) {
return
}
- testenv.MustHaveExec(t)
t.Parallel()
- exe, err := os.Executable()
- if err != nil {
- t.Fatal(err)
- }
-
- cmd := testenv.Command(t, exe, "-test.run=^TestTBHelper$")
+ cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^TestTBHelper$")
cmd = testenv.CleanCmdEnv(cmd)
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
out, _ := cmd.CombinedOutput()
@@ -66,15 +60,9 @@ func TestTBHelperParallel(t *testing.T) {
return
}
- testenv.MustHaveExec(t)
t.Parallel()
- exe, err := os.Executable()
- if err != nil {
- t.Fatal(err)
- }
-
- cmd := testenv.Command(t, exe, "-test.run=^TestTBHelperParallel$")
+ cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^TestTBHelperParallel$")
cmd = testenv.CleanCmdEnv(cmd)
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
out, _ := cmd.CombinedOutput()
diff --git a/src/testing/testing_test.go b/src/testing/testing_test.go
index f53c233905..d62455baa8 100644
--- a/src/testing/testing_test.go
+++ b/src/testing/testing_test.go
@@ -440,12 +440,7 @@ func runTest(t *testing.T, test string) []byte {
testenv.MustHaveExec(t)
- exe, err := os.Executable()
- if err != nil {
- t.Skipf("can't find test executable: %v", err)
- }
-
- cmd := testenv.Command(t, exe, "-test.run=^"+test+"$", "-test.bench="+test, "-test.v", "-test.parallel=2", "-test.benchtime=2x")
+ cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^"+test+"$", "-test.bench="+test, "-test.v", "-test.parallel=2", "-test.benchtime=2x")
cmd = testenv.CleanCmdEnv(cmd)
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
out, err := cmd.CombinedOutput()
@@ -674,14 +669,7 @@ func TestRaceBeforeParallel(t *testing.T) {
}
func TestRaceBeforeTests(t *testing.T) {
- testenv.MustHaveExec(t)
-
- exe, err := os.Executable()
- if err != nil {
- t.Skipf("can't find test executable: %v", err)
- }
-
- cmd := testenv.Command(t, exe, "-test.run=^$")
+ cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^$")
cmd = testenv.CleanCmdEnv(cmd)
cmd.Env = append(cmd.Env, "GO_WANT_RACE_BEFORE_TESTS=1")
out, _ := cmd.CombinedOutput()