1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:04:49 -07:00

Revert "go/buildutil, cmd/guru: fix tests for symlinks in guru and gorename to account for windows."

Reason: ContainingPackage must do all I/O through build.Context.

This reverts commit c945ee3be4.

Change-Id: I625410bc754ea2d150be097bf424de2be42acde4
Reviewed-on: https://go-review.googlesource.com/33921
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Rebecca Stambler 2016-12-05 22:40:03 +00:00 committed by Alan Donovan
parent c945ee3be4
commit 07e766bf81
3 changed files with 41 additions and 65 deletions

View File

@ -9,7 +9,6 @@ import (
"go/build"
"io/ioutil"
"os"
"runtime"
"strings"
"testing"
)
@ -36,34 +35,25 @@ func TestIssue17515(t *testing.T) {
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
// Success test cases
type SuccessTest struct {
for _, test := range []struct {
gopath, filename, wantSrcdir string
}
successTests := []SuccessTest{
}{
{home + "/go", home + "/go/src/test/test.go", home + "/go/src"},
}
// Add symlink cases if not on windows
if runtime.GOOS != "windows" {
// 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 {
{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"},
} {
buildContext.GOPATH = test.gopath
srcdir, importPath, err := guessImportPath(test.filename, &buildContext)
if srcdir != test.wantSrcdir || importPath != "test" || err != nil {
@ -77,23 +67,14 @@ func TestIssue17515(t *testing.T) {
}
// Failure test cases
type FailTest struct {
for _, test := range []struct {
gopath, filename, wantErr string
}
failTests := []FailTest{
}{
{home + "/go", home + "/go/src/fake/test.go", errFormat(home + "/go/src/fake")},
}
if runtime.GOOS != "windows" {
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 {
{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")},
} {
buildContext.GOPATH = test.gopath
srcdir, importPath, err := guessImportPath(test.filename, &buildContext)
if !strings.HasPrefix(fmt.Sprint(err), test.wantErr) {

View File

@ -68,7 +68,7 @@ func ContainingPackage(ctxt *build.Context, dir, filename string) (*build.Packag
resolvedFilename, err := filepath.EvalSymlinks(filepath.Dir(filename))
if err != nil {
return nil, fmt.Errorf("can't evaluate symlinks of %s: %v", filepath.Dir(filename), err)
return nil, fmt.Errorf("can't evaluate symlinks of %s: %v", path.Dir(filename), err)
}
resolvedDir := filepath.ToSlash(resolvedFilename)

View File

@ -24,40 +24,35 @@ func TestContainingPackage(t *testing.T) {
goroot := runtime.GOROOT()
gopath := filepath.SplitList(os.Getenv("GOPATH"))[0]
type Test struct {
gopath, filename, wantPkg string
// Make a symlink to gopath for test
tmp, err := ioutil.TempDir(os.TempDir(), "go")
if err != nil {
t.Errorf("Unable to create a temporary directory in %s", os.TempDir())
}
tests := []Test{
// symlink between $GOPATH/src and /tmp/go/src
// in order to test all possible symlink cases
if err := os.Symlink(gopath+"/src", tmp+"/src"); err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmp)
for _, test := range []struct {
gopath, filename, wantPkg string
}{
{gopath, goroot + "/src/fmt/print.go", "fmt"},
{gopath, goroot + "/src/encoding/json/foo.go", "encoding/json"},
{gopath, goroot + "/src/encoding/missing/foo.go", "(not found)"},
{gopath, gopath + "/src/golang.org/x/tools/go/buildutil/util_test.go",
"golang.org/x/tools/go/buildutil"},
}
if runtime.GOOS != "windows" {
// Make a symlink to gopath for test
tmp, err := ioutil.TempDir(os.TempDir(), "go")
if err != nil {
t.Errorf("Unable to create a temporary directory in %s", os.TempDir())
}
defer os.RemoveAll(tmp)
// symlink between $GOPATH/src and /tmp/go/src
// in order to test all possible symlink cases
if err := os.Symlink(gopath+"/src", tmp+"/src"); err != nil {
t.Fatal(err)
}
tests = append(tests, []Test{
{gopath, tmp + "/src/golang.org/x/tools/go/buildutil/util_test.go", "golang.org/x/tools/go/buildutil"},
{tmp, gopath + "/src/golang.org/x/tools/go/buildutil/util_test.go", "golang.org/x/tools/go/buildutil"},
{tmp, tmp + "/src/golang.org/x/tools/go/buildutil/util_test.go", "golang.org/x/tools/go/buildutil"},
}...)
}
for _, test := range tests {
{gopath, tmp + "/src/golang.org/x/tools/go/buildutil/util_test.go",
"golang.org/x/tools/go/buildutil"},
{tmp, gopath + "/src/golang.org/x/tools/go/buildutil/util_test.go",
"golang.org/x/tools/go/buildutil"},
{tmp, tmp + "/src/golang.org/x/tools/go/buildutil/util_test.go",
"golang.org/x/tools/go/buildutil"},
} {
var got string
var buildContext = build.Default
buildContext.GOPATH = test.gopath