mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-01 06:46:44 -04:00
unix: rework TestGetwd to handle test dirs whose names contain symlinks
TestGetwd can fail on systems that have unexpected directory/partition configurations using symlinks. Fixes golang/go#26678 Change-Id: I44dba94c5e8b6a8e1e7e112cd7d0541d22b65d84 GitHub-Last-Rev: 727a6cc6a718969828a15d1016c89ea9be8a12e0 GitHub-Pull-Request: golang/sys#22 Reviewed-on: https://go-review.googlesource.com/c/148537 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
0cf1ed9e52
commit
62eef0e2fa
@@ -453,9 +453,9 @@ func TestGetwd(t *testing.T) {
|
|||||||
t.Fatalf("Open .: %s", err)
|
t.Fatalf("Open .: %s", err)
|
||||||
}
|
}
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
// These are chosen carefully not to be symlinks on a Mac
|
// Directory list for test. Do not worry if any are symlinks or do not
|
||||||
// (unlike, say, /var, /etc)
|
// exist on some common unix desktop environments. That will be checked.
|
||||||
dirs := []string{"/", "/usr/bin"}
|
dirs := []string{"/", "/usr/bin", "/etc", "/var", "/opt"}
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "android":
|
case "android":
|
||||||
dirs = []string{"/", "/system/bin"}
|
dirs = []string{"/", "/system/bin"}
|
||||||
@@ -475,6 +475,17 @@ func TestGetwd(t *testing.T) {
|
|||||||
}
|
}
|
||||||
oldwd := os.Getenv("PWD")
|
oldwd := os.Getenv("PWD")
|
||||||
for _, d := range dirs {
|
for _, d := range dirs {
|
||||||
|
// Check whether d exists, is a dir and that d's path does not contain a symlink
|
||||||
|
fi, err := os.Stat(d)
|
||||||
|
if err != nil || !fi.IsDir() {
|
||||||
|
t.Logf("Test dir %s stat error (%v) or not a directory, skipping", d, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
check, err := filepath.EvalSymlinks(d)
|
||||||
|
if err != nil || check != d {
|
||||||
|
t.Logf("Test dir %s (%s) is symlink or other error (%v), skipping", d, check, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
err = os.Chdir(d)
|
err = os.Chdir(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Chdir: %v", err)
|
t.Fatalf("Chdir: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user