aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/golang.org/x/sys/unix/syscall_unix_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/sys/unix/syscall_unix_test.go')
-rw-r--r--vendor/golang.org/x/sys/unix/syscall_unix_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/vendor/golang.org/x/sys/unix/syscall_unix_test.go b/vendor/golang.org/x/sys/unix/syscall_unix_test.go
index d0a09ce..496e471 100644
--- a/vendor/golang.org/x/sys/unix/syscall_unix_test.go
+++ b/vendor/golang.org/x/sys/unix/syscall_unix_test.go
@@ -378,6 +378,54 @@ func TestPoll(t *testing.T) {
}
}
+func TestGetwd(t *testing.T) {
+ fd, err := os.Open(".")
+ 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"}
+ if runtime.GOOS == "darwin" {
+ switch runtime.GOARCH {
+ case "arm", "arm64":
+ d1, err := ioutil.TempDir("", "d1")
+ if err != nil {
+ t.Fatalf("TempDir: %v", err)
+ }
+ d2, err := ioutil.TempDir("", "d2")
+ if err != nil {
+ t.Fatalf("TempDir: %v", err)
+ }
+ dirs = []string{d1, d2}
+ }
+ }
+ oldwd := os.Getenv("PWD")
+ for _, d := range dirs {
+ err = os.Chdir(d)
+ if err != nil {
+ t.Fatalf("Chdir: %v", err)
+ }
+ pwd, err := unix.Getwd()
+ if err != nil {
+ t.Fatalf("Getwd in %s: %s", d, err)
+ }
+ os.Setenv("PWD", oldwd)
+ 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", err)
+ os.Exit(1)
+ }
+ if pwd != d {
+ t.Fatalf("Getwd returned %q want %q", pwd, d)
+ }
+ }
+}
+
// mktmpfifo creates a temporary FIFO and provides a cleanup function.
func mktmpfifo(t *testing.T) (*os.File, func()) {
err := unix.Mkfifo("fifo", 0666)