mirror of https://github.com/golang/go.git
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>
This commit is contained in:
parent
f26c29723f
commit
6fa224a809
|
|
@ -28,11 +28,7 @@ func TestFlag(t *testing.T) {
|
||||||
flag := flag
|
flag := flag
|
||||||
t.Run(flag, func(t *testing.T) {
|
t.Run(flag, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
exe, err := os.Executable()
|
cmd := exec.Command(testenv.Executable(t), "-test.run=^TestFlag$", "-test_flag_arg="+flag)
|
||||||
if err != nil {
|
|
||||||
exe = os.Args[0]
|
|
||||||
}
|
|
||||||
cmd := exec.Command(exe, "-test.run=^TestFlag$", "-test_flag_arg="+flag)
|
|
||||||
if flag != "" {
|
if flag != "" {
|
||||||
cmd.Args = append(cmd.Args, flag)
|
cmd.Args = append(cmd.Args, flag)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,9 @@ func TestTBHelper(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
testenv.MustHaveExec(t)
|
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
exe, err := os.Executable()
|
cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^TestTBHelper$")
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := testenv.Command(t, exe, "-test.run=^TestTBHelper$")
|
|
||||||
cmd = testenv.CleanCmdEnv(cmd)
|
cmd = testenv.CleanCmdEnv(cmd)
|
||||||
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
|
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
|
||||||
out, _ := cmd.CombinedOutput()
|
out, _ := cmd.CombinedOutput()
|
||||||
|
|
@ -66,15 +60,9 @@ func TestTBHelperParallel(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
testenv.MustHaveExec(t)
|
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
exe, err := os.Executable()
|
cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^TestTBHelperParallel$")
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd := testenv.Command(t, exe, "-test.run=^TestTBHelperParallel$")
|
|
||||||
cmd = testenv.CleanCmdEnv(cmd)
|
cmd = testenv.CleanCmdEnv(cmd)
|
||||||
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
|
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
|
||||||
out, _ := cmd.CombinedOutput()
|
out, _ := cmd.CombinedOutput()
|
||||||
|
|
|
||||||
|
|
@ -440,12 +440,7 @@ func runTest(t *testing.T, test string) []byte {
|
||||||
|
|
||||||
testenv.MustHaveExec(t)
|
testenv.MustHaveExec(t)
|
||||||
|
|
||||||
exe, err := os.Executable()
|
cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^"+test+"$", "-test.bench="+test, "-test.v", "-test.parallel=2", "-test.benchtime=2x")
|
||||||
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.CleanCmdEnv(cmd)
|
cmd = testenv.CleanCmdEnv(cmd)
|
||||||
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
|
cmd.Env = append(cmd.Env, "GO_WANT_HELPER_PROCESS=1")
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
|
|
@ -674,14 +669,7 @@ func TestRaceBeforeParallel(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRaceBeforeTests(t *testing.T) {
|
func TestRaceBeforeTests(t *testing.T) {
|
||||||
testenv.MustHaveExec(t)
|
cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^$")
|
||||||
|
|
||||||
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.CleanCmdEnv(cmd)
|
cmd = testenv.CleanCmdEnv(cmd)
|
||||||
cmd.Env = append(cmd.Env, "GO_WANT_RACE_BEFORE_TESTS=1")
|
cmd.Env = append(cmd.Env, "GO_WANT_RACE_BEFORE_TESTS=1")
|
||||||
out, _ := cmd.CombinedOutput()
|
out, _ := cmd.CombinedOutput()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue