aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec
diff options
context:
space:
mode:
authorKir Kolyshkin <kolyshkin@gmail.com>2023-09-07 17:21:16 -0700
committerGopher Robot <gobot@golang.org>2024-09-04 00:52:28 +0000
commita00195d304e6858406c6c9c961d253eeb8cb0aec (patch)
tree149e38fa97607ff78dcc037f449925a85033854c /src/os/exec
parentdebfcb5ad87b276318bd6b725797e6808adeeae0 (diff)
downloadgo-a00195d304e6858406c6c9c961d253eeb8cb0aec.tar.xz
all: use t.Chdir in tests
Change-Id: I5bc514bedeb1155e6db52e37736fd6101774aea0 Reviewed-on: https://go-review.googlesource.com/c/go/+/529896 Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/os/exec')
-rw-r--r--src/os/exec/dot_test.go3
-rw-r--r--src/os/exec/exec_test.go22
-rw-r--r--src/os/exec/lp_unix_test.go2
-rw-r--r--src/os/exec/lp_windows_test.go4
4 files changed, 4 insertions, 27 deletions
diff --git a/src/os/exec/dot_test.go b/src/os/exec/dot_test.go
index ed4bad23b1..1bf0d9c760 100644
--- a/src/os/exec/dot_test.go
+++ b/src/os/exec/dot_test.go
@@ -38,8 +38,7 @@ func TestLookPath(t *testing.T) {
if err := os.WriteFile(filepath.Join(tmpDir, executable), []byte{1, 2, 3}, 0777); err != nil {
t.Fatal(err)
}
- chdir(t, tmpDir)
- t.Setenv("PWD", tmpDir)
+ t.Chdir(tmpDir)
t.Logf(". is %#q", tmpDir)
origPath := os.Getenv(pathVar)
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go
index fd185cadcf..8c62387193 100644
--- a/src/os/exec/exec_test.go
+++ b/src/os/exec/exec_test.go
@@ -169,28 +169,6 @@ func helperCommandContext(t *testing.T, ctx context.Context, name string, args .
return cmd
}
-func chdir(t *testing.T, dir string) {
- t.Helper()
-
- prev, err := os.Getwd()
- if err != nil {
- t.Fatal(err)
- }
- if err := os.Chdir(dir); err != nil {
- t.Fatal(err)
- }
- t.Logf("Chdir(%#q)", dir)
-
- t.Cleanup(func() {
- if err := os.Chdir(prev); err != nil {
- // Couldn't chdir back to the original working directory.
- // panic instead of t.Fatal so that we don't run other tests
- // in an unexpected location.
- panic("couldn't restore working directory: " + err.Error())
- }
- })
-}
-
var helperCommandUsed sync.Map
var helperCommands = map[string]func(...string){
diff --git a/src/os/exec/lp_unix_test.go b/src/os/exec/lp_unix_test.go
index 1503ddae93..ea7ec11cc7 100644
--- a/src/os/exec/lp_unix_test.go
+++ b/src/os/exec/lp_unix_test.go
@@ -16,7 +16,7 @@ func TestLookPathUnixEmptyPath(t *testing.T) {
// Not parallel: uses Chdir and Setenv.
tmp := t.TempDir()
- chdir(t, tmp)
+ t.Chdir(tmp)
f, err := os.OpenFile("exec_me", os.O_CREATE|os.O_EXCL, 0700)
if err != nil {
diff --git a/src/os/exec/lp_windows_test.go b/src/os/exec/lp_windows_test.go
index 15b2a0032f..01eda04c75 100644
--- a/src/os/exec/lp_windows_test.go
+++ b/src/os/exec/lp_windows_test.go
@@ -314,7 +314,7 @@ func TestLookPathWindows(t *testing.T) {
t.Setenv("PATH", pathVar)
t.Logf("set PATH=%s", pathVar)
- chdir(t, root)
+ t.Chdir(root)
if !testing.Short() && !(tt.skipCmdExeCheck || errors.Is(tt.wantErr, exec.ErrDot)) {
// Check that cmd.exe, which is our source of ground truth,
@@ -549,7 +549,7 @@ func TestCommand(t *testing.T) {
t.Setenv("PATH", pathVar)
t.Logf("set PATH=%s", pathVar)
- chdir(t, root)
+ t.Chdir(root)
cmd := exec.Command(tt.arg0, "printpath")
cmd.Dir = filepath.Join(root, tt.dir)