-
Notifications
You must be signed in to change notification settings - Fork 1k
Use evaluated project root path #812
Changes from 12 commits
849e187
f9b8523
1ad2706
88faf50
c28ab32
45540a7
96a9333
40d9942
3d59125
b124a46
618951f
92886c5
93dfae7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,13 @@ func TestCtx_ProjectImport(t *testing.T) { | |
for _, want := range importPaths { | ||
fullpath := filepath.Join(depCtx.GOPATH, "src", want) | ||
h.TempDir(filepath.Join("src", want)) | ||
got, err := depCtx.ImportForAbs(fullpath) | ||
|
||
p := &Project{} | ||
if err := p.SetRoot(fullpath); err != nil { | ||
t.Fatal(err) | ||
} | ||
got, err := depCtx.ImportPathForProject(p) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -48,15 +54,14 @@ func TestCtx_ProjectImport(t *testing.T) { | |
} | ||
|
||
// test where it should return an error when directly within $GOPATH/src | ||
got, err := depCtx.ImportForAbs(filepath.Join(depCtx.GOPATH, "src")) | ||
if err == nil || !strings.Contains(err.Error(), "GOPATH/src") { | ||
t.Fatalf("should have gotten an error for use directly in GOPATH/src, but got %s", got) | ||
p := &Project{} | ||
if err := p.SetRoot(filepath.Join(depCtx.GOPATH, "src")); err != nil { | ||
t.Fatal(err) | ||
} | ||
got, err := depCtx.ImportPathForProject(p) | ||
|
||
// test where it should return an error | ||
got, err = depCtx.ImportForAbs("tra/la/la/la") | ||
if err == nil { | ||
t.Fatalf("should have gotten an error but did not for tra/la/la/la: %s", got) | ||
if err == nil || !strings.Contains(err.Error(), "GOPATH/src") { | ||
t.Fatalf("should have gotten an error for use directly in GOPATH/src, but got %s", got) | ||
} | ||
} | ||
|
||
|
@@ -301,7 +306,13 @@ func TestCaseInsentitiveGOPATH(t *testing.T) { | |
ip := "github.com/pkg/errors" | ||
fullpath := filepath.Join(depCtx.GOPATH, "src", ip) | ||
h.TempDir(filepath.Join("src", ip)) | ||
pr, err := depCtx.ImportForAbs(fullpath) | ||
|
||
p := &Project{} | ||
if err := p.SetRoot(fullpath); err != nil { | ||
t.Fatal(err) | ||
} | ||
pr, err := depCtx.ImportPathForProject(p) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -445,3 +456,36 @@ func TestDetectGOPATH(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestDetectProjectSymlinkedOutsideGOPATH(t *testing.T) { | ||
h := test.NewHelper(t) | ||
defer h.Cleanup() | ||
|
||
h.TempDir("src") | ||
|
||
h.Setenv("GOPATH", h.Path(".")) | ||
depCtx := &Ctx{GOPATH: h.Path(".")} | ||
|
||
importPath := "ti/ga/fato/la/večera" | ||
h.TempDir(filepath.Join("src", importPath)) | ||
h.TempDir("symlink/to/project") | ||
|
||
symlinkSrc := h.OriginalPath(filepath.Join("src", importPath)) | ||
symlinkTarget := h.OriginalPath("symlink/to/project/sym") | ||
if err := os.Symlink(symlinkSrc, symlinkTarget); err != nil { | ||
t.Errorf("Error creating symlink from %s to %s: %s", symlinkSrc, symlinkTarget, err.Error()) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since if err := os.Symlink(symlinkSrc, symlinkTarget); err != nil {
t.Errorf("Error creating symlink from %s to %s: %s", symlinkSrc, symlinkTarget, err.Error())
} |
||
|
||
p := Project{} | ||
if err := p.SetRoot(symlinkSrc); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
got, err := depCtx.ImportPathForProject(&p) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if got != importPath { | ||
t.Fatalf("expected %s, got %s", importPath, got) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -498,8 +498,21 @@ func (h *Helper) TempDir(path string) { | |
} | ||
|
||
// Path returns the absolute pathname to file with the temporary | ||
// directory. | ||
// directory. Symlinks are evaluated. | ||
func (h *Helper) Path(name string) string { | ||
path := h.OriginalPath(name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we instead keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ibrasho yes, it makes sense. But I'd propose to delay that change after @sdboyer decides if this PR is mergeable or not. Because, this change will just increase the diff by a few hundred lines and increase the possibility of merge conflicts with the current If everything is OK, I'll make sure that the PR with this additional change merges in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sdboyer What's your opinion? |
||
|
||
// Ensure it's the absolute, symlink-less path we're returning | ||
abs, err := filepath.EvalSymlinks(path) | ||
if err != nil { | ||
h.t.Fatalf("%+v", errors.Wrapf(err, "internal testsuite error: could not get absolute path for dir(%q)", path)) | ||
} | ||
return abs | ||
} | ||
|
||
// OriginalPath returns the absolute pathname to file with the temporary | ||
// directory. Symlinks are NOT evaluated. | ||
func (h *Helper) OriginalPath(name string) string { | ||
if h.tempdir == "" { | ||
h.t.Fatalf("%+v", errors.Errorf("internal testsuite error: path(%q) with no tempdir", name)) | ||
} | ||
|
@@ -511,12 +524,7 @@ func (h *Helper) Path(name string) string { | |
joined = filepath.Join(h.tempdir, name) | ||
} | ||
|
||
// Ensure it's the absolute, symlink-less path we're returning | ||
abs, err := filepath.EvalSymlinks(joined) | ||
if err != nil { | ||
h.t.Fatalf("%+v", errors.Wrapf(err, "internal testsuite error: could not get absolute path for dir(%q)", joined)) | ||
} | ||
return abs | ||
return joined | ||
} | ||
|
||
// MustExist fails if path does not exist. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just do
path = p.ResolvedAbsRoot
instead?If they are the same, we did what line 223 is doing. If they are different, we did the if block logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just use
p.ResolvedAbsRoot
instead ofpath
...