From b334bd73acb5839bc08969a0c85960ef64dca383 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Wed, 11 Dec 2019 15:02:51 -0500 Subject: [PATCH] handle main functions --- cmd/pkger/cmds/pack.go | 8 +++++++- go.sum | 1 + parser/parser_test.go | 18 ------------------ pkging/pkgtest/ref.go | 1 - 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/cmd/pkger/cmds/pack.go b/cmd/pkger/cmds/pack.go index cea99da..a5a75d6 100644 --- a/cmd/pkger/cmds/pack.go +++ b/cmd/pkger/cmds/pack.go @@ -141,7 +141,13 @@ func Package(info here.Info, out string, decls parser.Decls) error { if err != nil { return err } - fmt.Fprintf(f, "package %s\n\n", c.Name) + + name := c.Name + if info.Module.Main { + name = "main" + } + + fmt.Fprintf(f, "package %s\n\n", name) fmt.Fprintf(f, "import \"github.com/markbates/pkger\"\n\n") fmt.Fprintf(f, "import \"github.com/markbates/pkger/pkging/mem\"\n\n") fmt.Fprintf(f, "\nvar _ = pkger.Apply(mem.UnmarshalEmbed([]byte(`") diff --git a/go.sum b/go.sum index c67dc0a..ade87ab 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,7 @@ 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 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= 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= diff --git a/parser/parser_test.go b/parser/parser_test.go index 65a0ccc..99ce1ca 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -41,14 +41,6 @@ func Test_Parser_Ref(t *testing.T) { fmt.Println(f.Path) } r.Len(files, 25) - - for _, f := range files { - 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) - } - } } func Test_Parser_Ref_Include(t *testing.T) { @@ -75,19 +67,9 @@ func Test_Parser_Ref_Include(t *testing.T) { files, err := res.Files() r.NoError(err) - // t.FailNow() l := len(files) r.Equal(26, l) - // r.Len(files, 27) - - for _, f := range files { - 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) - } - } } func Test_Parser_Example_HTTP(t *testing.T) { diff --git a/pkging/pkgtest/ref.go b/pkging/pkgtest/ref.go index a9a8dca..5fe1a0a 100644 --- a/pkging/pkgtest/ref.go +++ b/pkging/pkgtest/ref.go @@ -21,7 +21,6 @@ func NewRef() (*Ref, error) { if err != nil { return nil, err } - root := filepath.Join( her.Module.Dir, "pkging",