cmd/guru: avoid testing symlinks on OSes that do not support them
Add condition to prevent unit tests from checking cases with symlinks on Windows and Plan 9. Change-Id: Idc41db94a04a0daab556a26390db3f75ded7be73 Reviewed-on: https://go-review.googlesource.com/33923 Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
ae1141fc8b
commit
4073e786f5
|
@ -9,6 +9,7 @@ import (
|
||||||
"go/build"
|
"go/build"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -30,30 +31,39 @@ func TestIssue17515(t *testing.T) {
|
||||||
t.Errorf("Unable to create a temporary directory in %s", os.TempDir())
|
t.Errorf("Unable to create a temporary directory in %s", os.TempDir())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer os.RemoveAll(home)
|
||||||
|
|
||||||
// create filepath /tmp/home/go/src/test/test.go
|
// create filepath /tmp/home/go/src/test/test.go
|
||||||
if err = os.MkdirAll(home+"/go/src/test", 0755); err != nil {
|
if err = os.MkdirAll(home+"/go/src/test", 0755); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// symlink between /tmp/home/go/src and /tmp/home/src
|
|
||||||
if err = os.Symlink(home+"/go/src", home+"/src"); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Defer tear down (removing files, symlinks)
|
|
||||||
defer os.RemoveAll(home)
|
|
||||||
|
|
||||||
var buildContext = build.Default
|
var buildContext = build.Default
|
||||||
|
|
||||||
// Success test cases
|
// Success test cases
|
||||||
for _, test := range []struct {
|
type SuccessTest struct {
|
||||||
gopath, filename, wantSrcdir string
|
gopath, filename, wantSrcdir string
|
||||||
}{
|
}
|
||||||
|
|
||||||
|
successTests := []SuccessTest{
|
||||||
{home + "/go", home + "/go/src/test/test.go", home + "/go/src"},
|
{home + "/go", home + "/go/src/test/test.go", home + "/go/src"},
|
||||||
{home + "/go", home + "/src/test/test.go", home + "/go/src"},
|
}
|
||||||
{home, home + "/src/test/test.go", home + "/src"},
|
|
||||||
{home, home + "/go/src/test/test.go", home + "/src"},
|
// Add symlink cases if not on Windows, Plan 9
|
||||||
} {
|
if runtime.GOOS != "windows" && runtime.GOOS != "plan9" {
|
||||||
|
// symlink between /tmp/home/go/src and /tmp/home/src
|
||||||
|
if err := os.Symlink(home+"/go/src", home+"/src"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
successTests = append(successTests, []SuccessTest{
|
||||||
|
{home + "/go", home + "/src/test/test.go", home + "/go/src"},
|
||||||
|
{home, home + "/go/src/test/test.go", home + "/src"},
|
||||||
|
{home, home + "/src/test/test.go", home + "/src"},
|
||||||
|
}...)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range successTests {
|
||||||
buildContext.GOPATH = test.gopath
|
buildContext.GOPATH = test.gopath
|
||||||
srcdir, importPath, err := guessImportPath(test.filename, &buildContext)
|
srcdir, importPath, err := guessImportPath(test.filename, &buildContext)
|
||||||
if srcdir != test.wantSrcdir || importPath != "test" || err != nil {
|
if srcdir != test.wantSrcdir || importPath != "test" || err != nil {
|
||||||
|
@ -67,14 +77,23 @@ func TestIssue17515(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Failure test cases
|
// Failure test cases
|
||||||
for _, test := range []struct {
|
type FailTest struct {
|
||||||
gopath, filename, wantErr string
|
gopath, filename, wantErr string
|
||||||
}{
|
}
|
||||||
|
|
||||||
|
failTests := []FailTest{
|
||||||
{home + "/go", home + "/go/src/fake/test.go", errFormat(home + "/go/src/fake")},
|
{home + "/go", home + "/go/src/fake/test.go", errFormat(home + "/go/src/fake")},
|
||||||
{home + "/go", home + "/src/fake/test.go", errFormat(home + "/src/fake")},
|
}
|
||||||
{home, home + "/src/fake/test.go", errFormat(home + "/src/fake")},
|
|
||||||
{home, home + "/go/src/fake/test.go", errFormat(home + "/go/src/fake")},
|
if runtime.GOOS != "windows" && runtime.GOOS != "plan9" {
|
||||||
} {
|
failTests = append(failTests, []FailTest{
|
||||||
|
{home + "/go", home + "/src/fake/test.go", errFormat(home + "/src/fake")},
|
||||||
|
{home, home + "/src/fake/test.go", errFormat(home + "/src/fake")},
|
||||||
|
{home, home + "/go/src/fake/test.go", errFormat(home + "/go/src/fake")},
|
||||||
|
}...)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range failTests {
|
||||||
buildContext.GOPATH = test.gopath
|
buildContext.GOPATH = test.gopath
|
||||||
srcdir, importPath, err := guessImportPath(test.filename, &buildContext)
|
srcdir, importPath, err := guessImportPath(test.filename, &buildContext)
|
||||||
if !strings.HasPrefix(fmt.Sprint(err), test.wantErr) {
|
if !strings.HasPrefix(fmt.Sprint(err), test.wantErr) {
|
||||||
|
|
Loading…
Reference in New Issue