diff --git a/.mockery.yaml b/.mockery.yaml index f3590418..56b72995 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -108,4 +108,10 @@ packages: mockname: InterfaceWithUnresolvedAlias - resolve-type-alias: True mockname: InterfaceWithResolvedAlias + Interface2: + configs: + - resolve-type-alias: False + mockname: Interface2WithUnresolvedAlias + - resolve-type-alias: True + mockname: Interface2WithResolvedAlias diff --git a/pkg/fixtures/type_alias/interface.go b/pkg/fixtures/type_alias/interface.go index 95b16766..171c1e67 100644 --- a/pkg/fixtures/type_alias/interface.go +++ b/pkg/fixtures/type_alias/interface.go @@ -1,7 +1,16 @@ package type_alias -type Type = int +import "github.com/vektra/mockery/v2/pkg/fixtures/type_alias/subpkg" + +type ( + Type = int + S = subpkg.S +) type Interface1 interface { Foo() Type } + +type Interface2 interface { + F(Type, S, subpkg.S) +} diff --git a/pkg/fixtures/type_alias/interface_test.go b/pkg/fixtures/type_alias/interface_test.go index c8d545ce..f6b52aae 100644 --- a/pkg/fixtures/type_alias/interface_test.go +++ b/pkg/fixtures/type_alias/interface_test.go @@ -25,6 +25,11 @@ func TestTypeAlias(t *testing.T) { filepath: "./mock_InterfaceWithUnresolvedAlias_test.go", expectedRegex: `func \((_?[a-zA-Z]*)+ \*InterfaceWithUnresolvedAlias\) Foo\(\) type_alias.Type {`, }, + { + name: "Alias to type with underlying struct with resolve-type-alias: True", + filepath: "./mock_Interface2WithResolvedAlias_test.go", + expectedRegex: `func \(_m \*Interface2WithResolvedAlias\) F\(_a0 int, _a1 subpkg.S, _a2 subpkg.S\) {`, + }, } { t.Run(tt.name, func(t *testing.T) { regex, err := regexp.Compile(tt.expectedRegex) diff --git a/pkg/fixtures/type_alias/mock_Interface2WithResolvedAlias_test.go b/pkg/fixtures/type_alias/mock_Interface2WithResolvedAlias_test.go new file mode 100644 index 00000000..80cdaabe --- /dev/null +++ b/pkg/fixtures/type_alias/mock_Interface2WithResolvedAlias_test.go @@ -0,0 +1,70 @@ +// Code generated by mockery. DO NOT EDIT. + +package type_alias_test + +import ( + mock "github.com/stretchr/testify/mock" + subpkg "github.com/vektra/mockery/v2/pkg/fixtures/type_alias/subpkg" +) + +// Interface2WithResolvedAlias is an autogenerated mock type for the Interface2 type +type Interface2WithResolvedAlias struct { + mock.Mock +} + +type Interface2WithResolvedAlias_Expecter struct { + mock *mock.Mock +} + +func (_m *Interface2WithResolvedAlias) EXPECT() *Interface2WithResolvedAlias_Expecter { + return &Interface2WithResolvedAlias_Expecter{mock: &_m.Mock} +} + +// F provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Interface2WithResolvedAlias) F(_a0 int, _a1 subpkg.S, _a2 subpkg.S) { + _m.Called(_a0, _a1, _a2) +} + +// Interface2WithResolvedAlias_F_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'F' +type Interface2WithResolvedAlias_F_Call struct { + *mock.Call +} + +// F is a helper method to define mock.On call +// - _a0 int +// - _a1 subpkg.S +// - _a2 subpkg.S +func (_e *Interface2WithResolvedAlias_Expecter) F(_a0 interface{}, _a1 interface{}, _a2 interface{}) *Interface2WithResolvedAlias_F_Call { + return &Interface2WithResolvedAlias_F_Call{Call: _e.mock.On("F", _a0, _a1, _a2)} +} + +func (_c *Interface2WithResolvedAlias_F_Call) Run(run func(_a0 int, _a1 subpkg.S, _a2 subpkg.S)) *Interface2WithResolvedAlias_F_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(int), args[1].(subpkg.S), args[2].(subpkg.S)) + }) + return _c +} + +func (_c *Interface2WithResolvedAlias_F_Call) Return() *Interface2WithResolvedAlias_F_Call { + _c.Call.Return() + return _c +} + +func (_c *Interface2WithResolvedAlias_F_Call) RunAndReturn(run func(int, subpkg.S, subpkg.S)) *Interface2WithResolvedAlias_F_Call { + _c.Call.Return(run) + return _c +} + +// NewInterface2WithResolvedAlias creates a new instance of Interface2WithResolvedAlias. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewInterface2WithResolvedAlias(t interface { + mock.TestingT + Cleanup(func()) +}) *Interface2WithResolvedAlias { + mock := &Interface2WithResolvedAlias{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/fixtures/type_alias/mock_Interface2WithUnresolvedAlias_test.go b/pkg/fixtures/type_alias/mock_Interface2WithUnresolvedAlias_test.go new file mode 100644 index 00000000..68b64cf0 --- /dev/null +++ b/pkg/fixtures/type_alias/mock_Interface2WithUnresolvedAlias_test.go @@ -0,0 +1,71 @@ +// Code generated by mockery. DO NOT EDIT. + +package type_alias_test + +import ( + mock "github.com/stretchr/testify/mock" + type_alias "github.com/vektra/mockery/v2/pkg/fixtures/type_alias" + subpkg "github.com/vektra/mockery/v2/pkg/fixtures/type_alias/subpkg" +) + +// Interface2WithUnresolvedAlias is an autogenerated mock type for the Interface2 type +type Interface2WithUnresolvedAlias struct { + mock.Mock +} + +type Interface2WithUnresolvedAlias_Expecter struct { + mock *mock.Mock +} + +func (_m *Interface2WithUnresolvedAlias) EXPECT() *Interface2WithUnresolvedAlias_Expecter { + return &Interface2WithUnresolvedAlias_Expecter{mock: &_m.Mock} +} + +// F provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Interface2WithUnresolvedAlias) F(_a0 type_alias.Type, _a1 type_alias.S, _a2 subpkg.S) { + _m.Called(_a0, _a1, _a2) +} + +// Interface2WithUnresolvedAlias_F_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'F' +type Interface2WithUnresolvedAlias_F_Call struct { + *mock.Call +} + +// F is a helper method to define mock.On call +// - _a0 type_alias.Type +// - _a1 type_alias.S +// - _a2 subpkg.S +func (_e *Interface2WithUnresolvedAlias_Expecter) F(_a0 interface{}, _a1 interface{}, _a2 interface{}) *Interface2WithUnresolvedAlias_F_Call { + return &Interface2WithUnresolvedAlias_F_Call{Call: _e.mock.On("F", _a0, _a1, _a2)} +} + +func (_c *Interface2WithUnresolvedAlias_F_Call) Run(run func(_a0 type_alias.Type, _a1 type_alias.S, _a2 subpkg.S)) *Interface2WithUnresolvedAlias_F_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(type_alias.Type), args[1].(type_alias.S), args[2].(subpkg.S)) + }) + return _c +} + +func (_c *Interface2WithUnresolvedAlias_F_Call) Return() *Interface2WithUnresolvedAlias_F_Call { + _c.Call.Return() + return _c +} + +func (_c *Interface2WithUnresolvedAlias_F_Call) RunAndReturn(run func(type_alias.Type, type_alias.S, subpkg.S)) *Interface2WithUnresolvedAlias_F_Call { + _c.Call.Return(run) + return _c +} + +// NewInterface2WithUnresolvedAlias creates a new instance of Interface2WithUnresolvedAlias. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewInterface2WithUnresolvedAlias(t interface { + mock.TestingT + Cleanup(func()) +}) *Interface2WithUnresolvedAlias { + mock := &Interface2WithUnresolvedAlias{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/pkg/fixtures/type_alias/subpkg/interface.go b/pkg/fixtures/type_alias/subpkg/interface.go new file mode 100644 index 00000000..cf7807c3 --- /dev/null +++ b/pkg/fixtures/type_alias/subpkg/interface.go @@ -0,0 +1,5 @@ +package subpkg + +type S struct { + A int +} diff --git a/pkg/generator.go b/pkg/generator.go index ae2ca81d..70587966 100644 --- a/pkg/generator.go +++ b/pkg/generator.go @@ -547,8 +547,7 @@ func (g *Generator) renderType(ctx context.Context, typ types.Type) string { "url": logging.DocsURL("/deprecations/#resolve-type-alias"), }, ) - log.Debug().Msg("resolving type alias to underlying type") - return g.renderType(ctx, t.Underlying()) + return g.renderType(ctx, t.Rhs()) } log.Debug().Msg("not resolving type alias to underlying type") return g.renderNamedType(ctx, t) diff --git a/tools/cmd/tag.go b/tools/cmd/tag.go index 4a2861c3..04b69bed 100644 --- a/tools/cmd/tag.go +++ b/tools/cmd/tag.go @@ -15,13 +15,9 @@ import ( "github.com/spf13/viper" ) -var ( - ErrNoNewVersion = errors.New("no new version specified") -) +var ErrNoNewVersion = errors.New("no new version specified") -var ( - EXIT_CODE_NO_NEW_VERSION = 8 -) +var EXIT_CODE_NO_NEW_VERSION = 8 func NewTagCmd(v *viper.Viper) (*cobra.Command, error) { if err := v.ReadInConfig(); err != nil { @@ -121,7 +117,6 @@ func (t *Tagger) largestTagSemver(repo *git.Repository) (*semver.Version, error) largestTag = version } return nil - }); err != nil { return nil, err } @@ -201,5 +196,4 @@ func (t *Tagger) Tag() error { logger.Info().Msg("created new tag. Push to origin still required.") return nil - }