aboutsummaryrefslogtreecommitdiff
path: root/src/os/executable_test.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2022-12-13 16:04:09 -0500
committerGopher Robot <gobot@golang.org>2023-01-19 20:45:37 +0000
commite49cb0208b17936f370753c820cb8dfef8d2bd5e (patch)
tree1165682592889945b2f21999fbf01f9291be9f78 /src/os/executable_test.go
parentf2884bf42317011371440d90805e63248d94c45d (diff)
downloadgo-e49cb0208b17936f370753c820cb8dfef8d2bd5e.tar.xz
os: clean up tests
- Use testenv.Command instead of exec.Command to try to get more useful timeout behavior. - Parallelize tests that appear not to require global state. (And add explanatory comments for a few that are not parallelizable for subtle reasons.) - Consolidate some “Helper” tests with their parent tests. - Use t.TempDir instead of os.MkdirTemp when appropriate. - Factor out subtests for repeated test helpers. For #36107. Updates #22315. Change-Id: Ic24b6957094dcd40908a59f48e44c8993729222b Reviewed-on: https://go-review.googlesource.com/c/go/+/458015 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/os/executable_test.go')
-rw-r--r--src/os/executable_test.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/os/executable_test.go b/src/os/executable_test.go
index b69fe41ea3..8d1794d340 100644
--- a/src/os/executable_test.go
+++ b/src/os/executable_test.go
@@ -8,7 +8,6 @@ import (
"fmt"
"internal/testenv"
"os"
- osexec "os/exec"
"path/filepath"
"runtime"
"testing"
@@ -18,6 +17,8 @@ const executable_EnvVar = "OSTEST_OUTPUT_EXECPATH"
func TestExecutable(t *testing.T) {
testenv.MustHaveExec(t)
+ t.Parallel()
+
ep, err := os.Executable()
if err != nil {
t.Fatalf("Executable failed: %v", err)
@@ -29,18 +30,18 @@ func TestExecutable(t *testing.T) {
t.Fatalf("filepath.Rel: %v", err)
}
- cmd := &osexec.Cmd{}
+ cmd := testenv.Command(t, fn, "-test.run=XXXX")
// make child start with a relative program path
cmd.Dir = dir
cmd.Path = fn
- // forge argv[0] for child, so that we can verify we could correctly
- // get real path of the executable without influenced by argv[0].
- cmd.Args = []string{"-", "-test.run=XXXX"}
if runtime.GOOS == "openbsd" || runtime.GOOS == "aix" {
// OpenBSD and AIX rely on argv[0]
- cmd.Args[0] = fn
+ } else {
+ // forge argv[0] for child, so that we can verify we could correctly
+ // get real path of the executable without influenced by argv[0].
+ cmd.Args[0] = "-"
}
- cmd.Env = append(os.Environ(), fmt.Sprintf("%s=1", executable_EnvVar))
+ cmd.Env = append(cmd.Environ(), fmt.Sprintf("%s=1", executable_EnvVar))
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("exec(self) failed: %v", err)
@@ -95,6 +96,7 @@ func TestExecutableDeleted(t *testing.T) {
case "openbsd", "freebsd", "aix":
t.Skipf("%v does not support reading deleted binary name", runtime.GOOS)
}
+ t.Parallel()
dir := t.TempDir()