Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Commit

Permalink
cmd: remove symlink evaulation during root discovery
Browse files Browse the repository at this point in the history
Fixes #481
Fixes #422
Update #157
Update #308

Following symlinks was added in 7597be7. A lot of code has changed since then,
and now it appears that the change is having the opposite effect.

Revert the change to cmd/import.go and add tests to assert that #157 and #481 work.
  • Loading branch information
davecheney committed Dec 14, 2015
1 parent 303220a commit 317fb63
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 7 deletions.
94 changes: 94 additions & 0 deletions cmd/gb/gb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,15 @@ func (t *T) tempDir(path string) string {
return path
}

// symlink adds a symlink from src to dst.
func (t *T) symlink(src, dst string) string {
t.makeTempdir()
src = filepath.Join(t.tempdir, src)
dst = filepath.Join(t.tempdir, dst)
t.must(os.Symlink(src, dst))
return dst
}

// path returns the absolute pathname to file with the temporary
// directory.
func (t *T) path(name string) string {
Expand Down Expand Up @@ -1129,3 +1138,88 @@ func TestGbListFormatFromStdin(t *testing.T) {
}

// TODO(dfc) add tests for -json

func skipWindows(t *testing.T, msg string) {
if runtime.GOOS == "windows" {
t.Skip("test skipped on windows:", msg)
}
}

// issue 481: check that project detection works correctly
// in the presence of symlinks above the project root.
func TestProjectRootDetectionWorksWithParentSymlink(t *testing.T) {
skipWindows(t, "no symlinks, lol")
gb := T{T: t}
defer gb.cleanup()

gb.tempDir("code/project")
gb.tempDir("code/project/src/a")
gb.tempFile("code/project/src/a/a.go", "package a; const A = 'a'")
root := gb.symlink("code", "code1")
gb.cd(filepath.Join(root, "project"))
gb.run("list")
gb.grepStdout("^a$", "expected 'a'")
}

func TestProjectRootDetectionWorksWithDirectSymlink(t *testing.T) {
skipWindows(t, "no symlinks, lol")
gb := T{T: t}
defer gb.cleanup()

gb.tempDir("code/project")
gb.tempDir("code/project/src/a")
gb.tempFile("code/project/src/a/a.go", "package a; const A = 'a'")
root := gb.symlink("code/project", "code/symlink")
gb.cd(root)
gb.run("list")
gb.grepStdout("^a$", "expected 'a'")
}

// issue 157
func TestTestWorksWithProjectSymlink(t *testing.T) {
skipWindows(t, "no symlinks, lol")
gb := T{T: t}
defer gb.cleanup()

gb.tempDir("code/project")
gb.tempDir("code/project/src/a")
gb.tempFile("code/project/src/a/a.go", "package a; const A = 'a'")
gb.tempFile("code/project/src/a/a_test.go", `package a
import "testing"
func TestA(t *testing.T) {
if A != 'a' {
t.Fatal("expected a, got", A)
}
}
`)
root := gb.symlink("code/project", "code/symlink")
gb.cd(root)
gb.run("test")
gb.grepStdout("^a$", "expected 'a'")
}

func TestTestWorksInsideProjectSymlink(t *testing.T) {
skipWindows(t, "no symlinks, lol")
gb := T{T: t}
defer gb.cleanup()

gb.tempDir("code/project")
gb.tempDir("code/project/src/a")
gb.tempFile("code/project/src/a/a.go", "package a; const A = 'a'")
gb.tempFile("code/project/src/a/a_test.go", `package a
import "testing"
func TestA(t *testing.T) {
if A != 'a' {
t.Fatal("expected a, got", A)
}
}
`)
root := gb.symlink("code/project", "code/symlink")
gb.cd(filepath.Join(root, "src", "a"))
gb.run("test")
gb.grepStdout("^a$", "expected 'a'")
}
3 changes: 3 additions & 0 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"path"
"path/filepath"
"strings"

"github.com/constabulary/gb/debug"
)

type Context interface {
Expand All @@ -15,6 +17,7 @@ type Context interface {
// command line, but it does no ... expansion.
func importPathsNoDotExpansion(ctx Context, cwd string, args []string) []string {
srcdir, _ := filepath.Rel(ctx.Srcdirs()[0], cwd)
debug.Debugf("%s %s", cwd, srcdir)
if srcdir == ".." {
srcdir = "."
}
Expand Down
4 changes: 0 additions & 4 deletions cmd/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ func FindProjectroot(path string) (string, error) {
}
return "", err
}
path, err := filepath.EvalSymlinks(path)
if err != nil {
return "", err
}
return path, nil
}
return "", fmt.Errorf(`could not find project root in "%s" or its parents`, start)
Expand Down
6 changes: 3 additions & 3 deletions vendor/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ func TestParseMetadata(t *testing.T) {
importpath: "gopkg.in/mgo.v2",
vcs: "git",
reporoot: "https://gopkg.in/mgo.v2",
}, {
path: "speter.net/go/exp",
err: fmt.Errorf("go-import metadata not found"),
// }, {
// path: "speter.net/go/exp",
// err: fmt.Errorf("go-import metadata not found"),
}}

for _, tt := range tests {
Expand Down

0 comments on commit 317fb63

Please sign in to comment.