From 9ef79c78e8275652d7024237e019a2079707c89a Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Tue, 5 Nov 2019 11:44:15 -0500 Subject: [PATCH] test for external module --- parser/parser_test.go | 8 ++++++-- parser/visitor.go | 17 +++++++++++++---- pkging/pkgtest/testdata/ref/.gitignore | 1 + pkging/pkgtest/testdata/ref/go.sum | 19 ------------------- pkging/pkgtest/testdata/ref/web/web.go | 1 + pkging/pkgutil/stuff_test.go | 10 +++++++--- 6 files changed, 28 insertions(+), 28 deletions(-) create mode 100644 pkging/pkgtest/testdata/ref/.gitignore delete mode 100644 pkging/pkgtest/testdata/ref/go.sum diff --git a/parser/parser_test.go b/parser/parser_test.go index a4c4ea5..2b2702f 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -32,10 +32,14 @@ func Test_Parser_Ref(t *testing.T) { files, err := res.Files() r.NoError(err) - r.Len(files, 22) + r.Len(files, 23) for _, f := range files { - r.True(strings.HasPrefix(f.Abs, ref.Dir), "%q %q", f.Abs, ref.Dir) + if f.Path.Pkg == ref.Module.Path { + r.True(strings.HasPrefix(f.Abs, ref.Dir), "%q %q", f.Abs, ref.Dir) + } else { + r.False(strings.HasPrefix(f.Abs, ref.Dir), "%q %q", f.Abs, ref.Dir) + } } } diff --git a/parser/visitor.go b/parser/visitor.go index ace2711..b6d75e4 100644 --- a/parser/visitor.go +++ b/parser/visitor.go @@ -142,13 +142,22 @@ func (f *file) findStatCalls() error { return false } + pt, err := info.Parse(s) + if err != nil { + return false + } + + if pt.Pkg != info.Module.Path { + info, err = here.Package(pt.Pkg) + if err != nil { + return false + } + } + pf := &File{ Abs: f.filename, Here: info, - Path: here.Path{ - Pkg: info.Module.Path, - Name: s, - }, + Path: pt, } decl := StatDecl{ diff --git a/pkging/pkgtest/testdata/ref/.gitignore b/pkging/pkgtest/testdata/ref/.gitignore new file mode 100644 index 0000000..08cb523 --- /dev/null +++ b/pkging/pkgtest/testdata/ref/.gitignore @@ -0,0 +1 @@ +go.sum diff --git a/pkging/pkgtest/testdata/ref/go.sum b/pkging/pkgtest/testdata/ref/go.sum deleted file mode 100644 index befa6e2..0000000 --- a/pkging/pkgtest/testdata/ref/go.sum +++ /dev/null @@ -1,19 +0,0 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/pkging/pkgtest/testdata/ref/web/web.go b/pkging/pkgtest/testdata/ref/web/web.go index d59e076..c63c6bd 100644 --- a/pkging/pkgtest/testdata/ref/web/web.go +++ b/pkging/pkgtest/testdata/ref/web/web.go @@ -7,6 +7,7 @@ import ( ) func Serve() { + pkger.Stat("github.com/gobuffalo/buffalo:/logo.svg") dir := http.FileServer(pkger.Dir("/public")) http.ListenAndServe(":3000", dir) } diff --git a/pkging/pkgutil/stuff_test.go b/pkging/pkgutil/stuff_test.go index 0b1b35c..e4975ee 100644 --- a/pkging/pkgutil/stuff_test.go +++ b/pkging/pkgutil/stuff_test.go @@ -29,16 +29,20 @@ func Test_Stuff(t *testing.T) { decls, err := parser.Parse(ref.Info) r.NoError(err) - r.Len(decls, 9) + r.Len(decls, 10) files, err := decls.Files() r.NoError(err) for _, f := range files { - r.Equal("app", f.Path.Pkg) + if f.Path.Pkg == ref.Module.Path { + r.Equal("app", f.Path.Pkg) + } else { + r.NotEqual("app", f.Path.Pkg) + } } - r.Len(files, 22) + r.Len(files, 23) bb := &bytes.Buffer{}