Commit 571f7bbb authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

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 <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent d5840adf
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment