Commit 3239e9d3 authored by Russ Cox's avatar Russ Cox

cmd/go: fix TestModFindModulePath on Windows

The os.RemoveAll(tg.tempdir) was not a good idea.

Change-Id: I6f78cff887044186649cbf3ee04a58abdbcb71e2
Reviewed-on: https://go-review.googlesource.com/123757
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent f50448f5
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime"
"sort" "sort"
"strings" "strings"
"testing" "testing"
...@@ -213,23 +214,25 @@ func TestModFindModulePath(t *testing.T) { ...@@ -213,23 +214,25 @@ func TestModFindModulePath(t *testing.T) {
t.Fatalf("FindModulePath = %q, %v, want %q, nil", path, err, "unexpected.com/z") t.Fatalf("FindModulePath = %q, %v, want %q, nil", path, err, "unexpected.com/z")
} }
if runtime.GOOS == "windows" {
t.Skipf("windows removeall fails")
}
// Empty dir outside GOPATH // Empty dir outside GOPATH
tg.must(os.RemoveAll(tg.tempdir)) tg.must(os.MkdirAll(tg.path("gp1"), 0777))
tg.must(os.MkdirAll(tg.path("gp"), 0777)) tg.must(os.MkdirAll(tg.path("x1"), 0777))
tg.must(os.MkdirAll(tg.path("x"), 0777)) cfg.BuildContext.GOPATH = tg.path("gp1")
cfg.BuildContext.GOPATH = tg.path("gp")
path, err = modload.FindModulePath(tg.path("x")) path, err = modload.FindModulePath(tg.path("x1"))
if path != "" || err == nil { if path != "" || err == nil {
t.Fatalf("FindModulePath() = %q, %v, want %q, %q", path, err, "", "cannot determine module path for source directory") t.Fatalf("FindModulePath() = %q, %v, want %q, %q", path, err, "", "cannot determine module path for source directory")
} }
// Empty dir inside GOPATH // Empty dir inside GOPATH
tg.must(os.RemoveAll(tg.tempdir)) tg.must(os.MkdirAll(tg.path("gp2/src/x"), 0777))
tg.must(os.MkdirAll(tg.path("gp/src/x"), 0777)) cfg.BuildContext.GOPATH = tg.path("gp2")
cfg.BuildContext.GOPATH = tg.path("gp")
path, err = modload.FindModulePath(tg.path("gp/src/x")) path, err = modload.FindModulePath(tg.path("gp2/src/x"))
if path != "x" || err != nil { if path != "x" || err != nil {
t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x") t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x")
} }
...@@ -242,16 +245,15 @@ func TestModFindModulePath(t *testing.T) { ...@@ -242,16 +245,15 @@ func TestModFindModulePath(t *testing.T) {
// Empty dir inside GOPATH, dir has symlink // Empty dir inside GOPATH, dir has symlink
// GOPATH = gp // GOPATH = gp
// gplink -> gp // gplink -> gp
tg.must(os.RemoveAll(tg.tempdir)) tg.must(os.MkdirAll(tg.path("gp3/src/x"), 0777))
tg.must(os.MkdirAll(tg.path("gp/src/x"), 0777)) tg.must(os.Symlink(tg.path("gp3"), tg.path("gplink3")))
tg.must(os.Symlink(tg.path("gp"), tg.path("gplink"))) cfg.BuildContext.GOPATH = tg.path("gp3")
cfg.BuildContext.GOPATH = tg.path("gp")
path, err = modload.FindModulePath(tg.path("gplink/src/x")) path, err = modload.FindModulePath(tg.path("gplink3/src/x"))
if path != "x" || err != nil { if path != "x" || err != nil {
t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x") t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x")
} }
path, err = modload.FindModulePath(tg.path("gp/src/x")) path, err = modload.FindModulePath(tg.path("gp3/src/x"))
if path != "x" || err != nil { if path != "x" || err != nil {
t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x") t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x")
} }
...@@ -259,13 +261,12 @@ func TestModFindModulePath(t *testing.T) { ...@@ -259,13 +261,12 @@ func TestModFindModulePath(t *testing.T) {
// Empty dir inside GOPATH, dir has symlink 2 // Empty dir inside GOPATH, dir has symlink 2
// GOPATH = gp // GOPATH = gp
// gp/src/x -> x/x // gp/src/x -> x/x
tg.must(os.RemoveAll(tg.tempdir)) tg.must(os.MkdirAll(tg.path("gp4/src"), 0777))
tg.must(os.MkdirAll(tg.path("gp/src"), 0777)) tg.must(os.MkdirAll(tg.path("x4/x"), 0777))
tg.must(os.MkdirAll(tg.path("x/x"), 0777)) tg.must(os.Symlink(tg.path("x4/x"), tg.path("gp4/src/x")))
tg.must(os.Symlink(tg.path("x/x"), tg.path("gp/src/x"))) cfg.BuildContext.GOPATH = tg.path("gp4")
cfg.BuildContext.GOPATH = tg.path("gp")
path, err = modload.FindModulePath(tg.path("gp/src/x")) path, err = modload.FindModulePath(tg.path("gp4/src/x"))
if path != "x" || err != nil { if path != "x" || err != nil {
t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x") t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x")
} }
...@@ -273,16 +274,15 @@ func TestModFindModulePath(t *testing.T) { ...@@ -273,16 +274,15 @@ func TestModFindModulePath(t *testing.T) {
// Empty dir inside GOPATH, GOPATH has symlink // Empty dir inside GOPATH, GOPATH has symlink
// GOPATH = gplink // GOPATH = gplink
// gplink -> gp // gplink -> gp
tg.must(os.RemoveAll(tg.tempdir)) tg.must(os.MkdirAll(tg.path("gp5/src/x"), 0777))
tg.must(os.MkdirAll(tg.path("gp/src/x"), 0777)) tg.must(os.Symlink(tg.path("gp5"), tg.path("gplink5")))
tg.must(os.Symlink(tg.path("gp"), tg.path("gplink"))) cfg.BuildContext.GOPATH = tg.path("gplink5")
cfg.BuildContext.GOPATH = tg.path("gplink")
path, err = modload.FindModulePath(tg.path("gplink/src/x")) path, err = modload.FindModulePath(tg.path("gplink5/src/x"))
if path != "x" || err != nil { if path != "x" || err != nil {
t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x") t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x")
} }
path, err = modload.FindModulePath(tg.path("gp/src/x")) path, err = modload.FindModulePath(tg.path("gp5/src/x"))
if path != "x" || err != nil { if path != "x" || err != nil {
t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x") t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x")
} }
...@@ -291,21 +291,20 @@ func TestModFindModulePath(t *testing.T) { ...@@ -291,21 +291,20 @@ func TestModFindModulePath(t *testing.T) {
// GOPATH = gplink // GOPATH = gplink
// gplink -> gp // gplink -> gp
// gplink2 -> gp // gplink2 -> gp
tg.must(os.RemoveAll(tg.tempdir)) tg.must(os.MkdirAll(tg.path("gp6/src/x"), 0777))
tg.must(os.MkdirAll(tg.path("gp/src/x"), 0777)) tg.must(os.Symlink(tg.path("gp6"), tg.path("gplink6")))
tg.must(os.Symlink(tg.path("gp"), tg.path("gplink"))) tg.must(os.Symlink(tg.path("gp6"), tg.path("gplink62")))
tg.must(os.Symlink(tg.path("gp"), tg.path("gplink2"))) cfg.BuildContext.GOPATH = tg.path("gplink6")
cfg.BuildContext.GOPATH = tg.path("gplink")
path, err = modload.FindModulePath(tg.path("gplink2/src/x")) path, err = modload.FindModulePath(tg.path("gplink62/src/x"))
if path != "x" || err != nil { if path != "x" || err != nil {
t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x") t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x")
} }
path, err = modload.FindModulePath(tg.path("gplink/src/x")) path, err = modload.FindModulePath(tg.path("gplink6/src/x"))
if path != "x" || err != nil { if path != "x" || err != nil {
t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x") t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x")
} }
path, err = modload.FindModulePath(tg.path("gp/src/x")) path, err = modload.FindModulePath(tg.path("gp6/src/x"))
if path != "x" || err != nil { if path != "x" || err != nil {
t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x") t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x")
} }
...@@ -315,21 +314,20 @@ func TestModFindModulePath(t *testing.T) { ...@@ -315,21 +314,20 @@ func TestModFindModulePath(t *testing.T) {
// gplink -> gp // gplink -> gp
// gplink2 -> gp // gplink2 -> gp
// gp/src/x -> x/x // gp/src/x -> x/x
tg.must(os.RemoveAll(tg.tempdir)) tg.must(os.MkdirAll(tg.path("gp7/src"), 0777))
tg.must(os.MkdirAll(tg.path("gp/src"), 0777)) tg.must(os.MkdirAll(tg.path("x7/x"), 0777))
tg.must(os.MkdirAll(tg.path("x/x"), 0777)) tg.must(os.Symlink(tg.path("gp7"), tg.path("gplink7")))
tg.must(os.Symlink(tg.path("gp"), tg.path("gplink"))) tg.must(os.Symlink(tg.path("gp7"), tg.path("gplink72")))
tg.must(os.Symlink(tg.path("gp"), tg.path("gplink2"))) tg.must(os.Symlink(tg.path("x7/x"), tg.path("gp7/src/x")))
tg.must(os.Symlink(tg.path("x/x"), tg.path("gp/src/x"))) cfg.BuildContext.GOPATH = tg.path("gplink7")
cfg.BuildContext.GOPATH = tg.path("gplink")
path, err = modload.FindModulePath(tg.path("gplink7/src/x"))
path, err = modload.FindModulePath(tg.path("gplink/src/x"))
if path != "x" || err != nil { if path != "x" || err != nil {
t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x") t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x")
} }
// This test fails when /tmp -> /private/tmp. // This test fails when /tmp -> /private/tmp.
// path, err = modload.FindModulePath(tg.path("gp/src/x")) // path, err = modload.FindModulePath(tg.path("gp7/src/x"))
// if path != "x" || err != nil { // if path != "x" || err != nil {
// t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x") // t.Fatalf("FindModulePath() = %q, %v, want %q, nil", path, err, "x")
// } // }
......
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