From 571f7bbbe08da2a8955aed9d4db316e78630e9a3 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sat, 16 Dec 2017 15:55:03 +0100 Subject: [PATCH] unix: simplify TestGetwd No need to use err1 and err2, because there is no mode like in TestChdirAndGetwd (from os/os_test.go). Also, call fd.Close() via defer. Change-Id: I8e57acbb382f072c48805f8931c464a169203512 Reviewed-on: https://go-review.googlesource.com/84476 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- unix/syscall_unix_test.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) 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.