1
0
mirror of https://github.com/golang/go synced 2024-11-22 05:24:39 -07:00

path/filepath/path_test.go: repair and enable TestAbs

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5759051
This commit is contained in:
Rob Pike 2012-03-07 07:54:56 +11:00
parent 73b8ccb0b0
commit 2184137cf3

View File

@ -642,33 +642,61 @@ func TestEvalSymlinks(t *testing.T) {
} }
} }
// Test paths relative to $GOROOT/src // Test directories relative to temporary directory.
var abstests = []string{ // The tests are run in absTestDirs[0].
"../AUTHORS", var absTestDirs = []string{
"pkg/../../AUTHORS", "a",
"Make.inc", "a/b",
"pkg/math", "a/b/c",
}
// Test paths relative to temporary directory. $ expands to the directory.
// The tests are run in absTestDirs[0].
// We create absTestDirs first.
var absTests = []string{
".", ".",
"$GOROOT/src/Make.inc", "b",
"$GOROOT/src/../src/Make.inc", "../a",
"$GOROOT/misc/cgo", "../a/b",
"$GOROOT", "../a/b/./c/../../.././a",
"$",
"$/.",
"$/a/../a/b",
"$/a/b/c/../../.././a",
} }
func TestAbs(t *testing.T) { func TestAbs(t *testing.T) {
t.Logf("test needs to be rewritten; disabled")
return
oldwd, err := os.Getwd() oldwd, err := os.Getwd()
if err != nil { if err != nil {
t.Fatal("Getwd failed: " + err.Error()) t.Fatal("Getwd failed: ", err)
} }
defer os.Chdir(oldwd) defer os.Chdir(oldwd)
goroot := os.Getenv("GOROOT")
cwd := filepath.Join(goroot, "src") root, err := ioutil.TempDir("", "TestAbs")
os.Chdir(cwd) if err != nil {
for _, path := range abstests { t.Fatal("TempDir failed: ", err)
path = strings.Replace(path, "$GOROOT", goroot, -1) }
defer os.RemoveAll(root)
err = os.Chdir(root)
if err != nil {
t.Fatal("chdir failed: ", err)
}
for _, dir := range absTestDirs {
err = os.Mkdir(dir, 0777)
if err != nil {
t.Fatal("Mkdir failed: ", err)
}
}
err = os.Chdir(absTestDirs[0])
if err != nil {
t.Fatal("chdir failed: ", err)
}
for _, path := range absTests {
path = strings.Replace(path, "$", root, -1)
info, err := os.Stat(path) info, err := os.Stat(path)
if err != nil { if err != nil {
t.Errorf("%s: %s", path, err) t.Errorf("%s: %s", path, err)