Skip to content

Commit

Permalink
Merge pull request #853 from LandonTClipp/LandonTClipp/bugfix
Browse files Browse the repository at this point in the history
Fix bug with type aliases to structs
  • Loading branch information
LandonTClipp authored Nov 26, 2024
2 parents bc56391 + b1145cb commit 773408f
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 11 deletions.
6 changes: 6 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

11 changes: 10 additions & 1 deletion pkg/fixtures/type_alias/interface.go
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 5 additions & 0 deletions pkg/fixtures/type_alias/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
70 changes: 70 additions & 0 deletions pkg/fixtures/type_alias/mock_Interface2WithResolvedAlias_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions pkg/fixtures/type_alias/mock_Interface2WithUnresolvedAlias_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/fixtures/type_alias/subpkg/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package subpkg

type S struct {
A int
}
3 changes: 1 addition & 2 deletions pkg/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 2 additions & 8 deletions tools/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -121,7 +117,6 @@ func (t *Tagger) largestTagSemver(repo *git.Repository) (*semver.Version, error)
largestTag = version
}
return nil

}); err != nil {
return nil, err
}
Expand Down Expand Up @@ -201,5 +196,4 @@ func (t *Tagger) Tag() error {
logger.Info().Msg("created new tag. Push to origin still required.")

return nil

}

0 comments on commit 773408f

Please sign in to comment.