diff --git a/unix/syscall_unix_test.go b/unix/syscall_unix_test.go index 72a80941..496e4713 100644 --- a/unix/syscall_unix_test.go +++ b/unix/syscall_unix_test.go @@ -383,6 +383,7 @@ func TestGetwd(t *testing.T) { if err != nil { t.Fatalf("Open .: %s", err) } + defer fd.Close() // These are chosen carefully not to be symlinks on a Mac // (unlike, say, /var, /etc) dirs := []string{"/", "/usr/bin"} @@ -406,30 +407,23 @@ func TestGetwd(t *testing.T) { if err != nil { t.Fatalf("Chdir: %v", err) } - pwd, err1 := unix.Getwd() + pwd, err := unix.Getwd() + if err != nil { + t.Fatalf("Getwd in %s: %s", d, err) + } os.Setenv("PWD", oldwd) - err2 := fd.Chdir() - if err2 != nil { + err = fd.Chdir() + if err != nil { // We changed the current directory and cannot go back. // Don't let the tests continue; they'll scribble // all over some other directory. - fmt.Fprintf(os.Stderr, "fchdir back to dot failed: %s\n", err2) + fmt.Fprintf(os.Stderr, "fchdir back to dot failed: %s\n", err) os.Exit(1) } - if err != nil { - fd.Close() - t.Fatalf("Chdir %s: %s", d, err) - } - if err1 != nil { - fd.Close() - t.Fatalf("Getwd in %s: %s", d, err1) - } if pwd != d { - fd.Close() t.Fatalf("Getwd returned %q want %q", pwd, d) } } - fd.Close() } // mktmpfifo creates a temporary FIFO and provides a cleanup function.