diff --git a/internal/template_generator.go b/internal/template_generator.go index 7b982906b..7e66ec1b9 100644 --- a/internal/template_generator.go +++ b/internal/template_generator.go @@ -16,7 +16,6 @@ import ( "github.com/chigopher/pathlib" "github.com/rs/zerolog" "github.com/vektra/mockery/v3/internal/stackerr" - "github.com/vektra/mockery/v3/registry" "github.com/vektra/mockery/v3/template" "golang.org/x/tools/go/packages" "golang.org/x/tools/imports" @@ -101,7 +100,7 @@ func findPkgPath(dirPath *pathlib.Path) (string, error) { type TemplateGenerator struct { templateName string - registry *registry.Registry + registry *template.Registry formatter Formatter pkgConfig *Config inPackage bool @@ -148,7 +147,7 @@ func NewTemplateGenerator( log.Debug().Msg("output package detected to not be in-package of original package") } - reg, err := registry.New(srcPkg, outPkgPath, inPackage) + reg, err := template.NewRegistry(srcPkg, outPkgPath, inPackage) if err != nil { return nil, fmt.Errorf("creating new registry: %w", err) } diff --git a/mockery-tools.env b/mockery-tools.env index 59d6cbbbe..42cfa76d2 100644 --- a/mockery-tools.env +++ b/mockery-tools.env @@ -1 +1 @@ -VERSION=v3.0.0-alpha.11 +VERSION=v3.0.0-alpha.12 diff --git a/registry/method_scope.go b/template/method_scope.go similarity index 99% rename from registry/method_scope.go rename to template/method_scope.go index 7fc3a7249..38857005d 100644 --- a/registry/method_scope.go +++ b/template/method_scope.go @@ -1,4 +1,4 @@ -package registry +package template import ( "context" diff --git a/registry/package.go b/template/package.go similarity index 98% rename from registry/package.go rename to template/package.go index 901922869..2baf441fa 100644 --- a/registry/package.go +++ b/template/package.go @@ -1,4 +1,4 @@ -package registry +package template import ( "strings" diff --git a/registry/registry.go b/template/registry.go similarity index 97% rename from registry/registry.go rename to template/registry.go index fc9c25403..da96b0977 100644 --- a/registry/registry.go +++ b/template/registry.go @@ -1,4 +1,4 @@ -package registry +package template import ( "context" @@ -33,7 +33,7 @@ type Registry struct { // New loads the source package info and returns a new instance of // Registry. -func New(srcPkg *packages.Package, dstPkgPath string, inPackage bool) (*Registry, error) { +func NewRegistry(srcPkg *packages.Package, dstPkgPath string, inPackage bool) (*Registry, error) { return &Registry{ dstPkgPath: dstPkgPath, srcPkg: srcPkg, diff --git a/template/template.go b/template/template.go index 776374a9a..60c1b0bbe 100644 --- a/template/template.go +++ b/template/template.go @@ -9,7 +9,6 @@ import ( "text/template" "github.com/huandu/xstrings" - "github.com/vektra/mockery/v3/registry" ) // Template is the Moq template. It is capable of generating the Moq @@ -63,13 +62,13 @@ func exported(s string) string { } var TemplateMockFuncs = template.FuncMap{ - "importStatement": func(imprt *registry.Package) string { + "importStatement": func(imprt *Package) string { if imprt.Alias == "" { return `"` + imprt.Path() + `"` } return imprt.Alias + ` "` + imprt.Path() + `"` }, - "syncPkgQualifier": func(imports []*registry.Package) string { + "syncPkgQualifier": func(imports []*Package) string { for _, imprt := range imports { if imprt.Path() == "sync" { return imprt.Qualifier() diff --git a/template/template_data.go b/template/template_data.go index 370c04441..c67d423c7 100644 --- a/template/template_data.go +++ b/template/template_data.go @@ -4,10 +4,9 @@ import ( "fmt" "go/types" "strings" - - "github.com/vektra/mockery/v3/registry" ) +// ConfigData is the data sent to the template for the config file. type ConfigData struct { ConfigDir string InterfaceDir string @@ -20,13 +19,13 @@ type ConfigData struct { SrcPackagePath string } -// Data is the template data used to render the Moq template. +// Data is the template data used to render the mock template. type Data struct { Boilerplate string BuildTags string PkgName string SrcPkgQualifier string - Imports []*registry.Package + Imports []*Package Mocks []MockData TemplateData map[string]any } @@ -98,7 +97,7 @@ type MethodData struct { // Scope represents the lexical scope of the method. Its primary function // is keeping track of all names visible in the current scope, which allows // the creation of new variables with guaranteed non-conflicting names. - Scope *registry.MethodScope + Scope *MethodScope } // ArgList is the string representation of method parameters, ex: @@ -217,7 +216,7 @@ type TypeParamData struct { // ParamData is the data which represents a parameter to some method of // an interface. type ParamData struct { - Var *registry.Var + Var *Var Variadic bool } diff --git a/template/template_test.go b/template/template_test.go index 8e234be62..e74b8135e 100644 --- a/template/template_test.go +++ b/template/template_test.go @@ -3,8 +3,6 @@ package template import ( "go/types" "testing" - - "github.com/vektra/mockery/v3/registry" ) func TestTemplateMockFuncs(t *testing.T) { @@ -19,8 +17,8 @@ func TestTemplateMockFuncs(t *testing.T) { }) t.Run("ImportStatement", func(t *testing.T) { - f := TemplateMockFuncs["ImportStatement"].(func(*registry.Package) string) - pkg := registry.NewPackage(types.NewPackage("xyz", "xyz")) + f := TemplateMockFuncs["ImportStatement"].(func(*Package) string) + pkg := NewPackage(types.NewPackage("xyz", "xyz")) if f(pkg) != `"xyz"` { t.Errorf("ImportStatement(...): want: `\"xyz\"`; got: `%s`", f(pkg)) } @@ -32,22 +30,22 @@ func TestTemplateMockFuncs(t *testing.T) { }) t.Run("SyncPkgQualifier", func(t *testing.T) { - f := TemplateMockFuncs["SyncPkgQualifier"].(func([]*registry.Package) string) + f := TemplateMockFuncs["SyncPkgQualifier"].(func([]*Package) string) if f(nil) != "sync" { t.Errorf("SyncPkgQualifier(...): want: `sync`; got: `%s`", f(nil)) } - imports := []*registry.Package{ - registry.NewPackage(types.NewPackage("sync", "sync")), - registry.NewPackage(types.NewPackage("github.com/some/module", "module")), + imports := []*Package{ + NewPackage(types.NewPackage("sync", "sync")), + NewPackage(types.NewPackage("github.com/some/module", "module")), } if f(imports) != "sync" { t.Errorf("SyncPkgQualifier(...): want: `sync`; got: `%s`", f(imports)) } - syncPkg := registry.NewPackage(types.NewPackage("sync", "sync")) + syncPkg := NewPackage(types.NewPackage("sync", "sync")) syncPkg.Alias = "stdsync" - otherSyncPkg := registry.NewPackage(types.NewPackage("github.com/someother/sync", "sync")) - imports = []*registry.Package{otherSyncPkg, syncPkg} + otherSyncPkg := NewPackage(types.NewPackage("github.com/someother/sync", "sync")) + imports = []*Package{otherSyncPkg, syncPkg} if f(imports) != "stdsync" { t.Errorf("SyncPkgQualifier(...): want: `stdsync`; got: `%s`", f(imports)) } diff --git a/registry/var.go b/template/var.go similarity index 99% rename from registry/var.go rename to template/var.go index 58d7a79df..24f42bc90 100644 --- a/registry/var.go +++ b/template/var.go @@ -1,4 +1,4 @@ -package registry +package template import ( "go/types"