Skip to content

Commit

Permalink
Merge pull request #165 from nkovacs/vendored
Browse files Browse the repository at this point in the history
Fix generator when kallax is vendored
  • Loading branch information
Miguel Molina committed May 24, 2017
2 parents 5b49619 + a6cde56 commit 2e2b872
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
7 changes: 6 additions & 1 deletion generator/processor.go
Expand Up @@ -506,7 +506,12 @@ func removeGoPath(path string) string {
for _, p := range parseutil.DefaultGoPath {
p = toSlash(p + "/src/")
if strings.HasPrefix(path, p) {
return prefix + strings.Replace(path, p, "", -1)
// Directories named "vendor" are only vendor directories
// if they're under $GOPATH/src.
if idx := strings.LastIndex(path, "/vendor/"); idx >= len(p)-1 {
return prefix + path[idx+8:]
}
return prefix + path[len(p):]
}
}
return prefix + path
Expand Down
39 changes: 37 additions & 2 deletions generator/processor_test.go
Expand Up @@ -356,7 +356,7 @@ func (s *ProcessorSuite) TestIsModel() {
Ptr *Bar
NoPtr Bar
Struct Struct
}
}
`
pkg := s.processFixture(src)
m := findModel(pkg, "Foo")
Expand Down Expand Up @@ -401,7 +401,7 @@ func (s *ProcessorSuite) TestIsEmbedded() {
C struct {
D int
}
}
}
`
pkg := s.processFixture(src)
m := findModel(pkg, "Foo")
Expand Down Expand Up @@ -457,6 +457,41 @@ func TestRemoveGoPath(t *testing.T) {
},
'/',
},
{
"/go/src/foo/go/src/fixtures.AliasString",
"foo/go/src/fixtures.AliasString",
[]string{
"/go",
},
'/',
},
{
"/home/workspace/gopath/src/foo/bar/vendor/gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
"gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
[]string{
"/home/foo/go",
"/home/workspace/gopath",
},
'/',
},
{
"/home/vendor/workspace/gopath/src/gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
"gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
[]string{
"/home/foo/go",
"/home/vendor/workspace/gopath",
},
'/',
},
{
"/home/vendor/workspace/gopath/src/vendor/gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
"gopkg.in/src-d/go-kallax.v1/tests/fixtures.AliasString",
[]string{
"/home/foo/go",
"/home/vendor/workspace/gopath",
},
'/',
},
}

for _, c := range cases {
Expand Down

0 comments on commit 2e2b872

Please sign in to comment.