mirror of
https://github.com/golang/sys.git
synced 2026-02-08 03:36:03 +03:00
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: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
d5840adf78
commit
571f7bbbe0
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user