Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support *ast.SelectorExpr aliases #881

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/fixtures/iface_new_type/iface_new_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestParsing(t *testing.T) {
require.NoError(t, parser.ParsePackages(ctx, []string{"github.com/vektra/mockery/v2/pkg/fixtures/iface_new_type"}))
require.NoError(t, parser.Load(ctx))

for _, ifaceName := range []string{"Interface1", "Interface2", "Interface3"} {
for _, ifaceName := range []string{"Interface1", "Interface2", "Interface3", "Interface4"} {
iface, err := parser.Find(ifaceName)
require.NoError(t, err)
require.NotNil(t, iface)
Expand All @@ -33,4 +33,8 @@ func TestUsage(t *testing.T) {
interface3 := NewMockInterface3(t)
interface3.EXPECT().Method1().Return()
interface3.Method1()

interface4 := NewMockInterface4(t)
interface4.EXPECT().Method1().Return()
interface4.Method1()
}
1 change: 1 addition & 0 deletions pkg/fixtures/iface_new_type/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type Interface1 interface {
type (
Interface2 Interface1
Interface3 subpkg.SubPkgInterface
Interface4 = subpkg.SubPkgInterface
)
64 changes: 64 additions & 0 deletions pkg/fixtures/iface_new_type/mock_interface_4_test.go

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

16 changes: 14 additions & 2 deletions pkg/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,24 @@ func (p *Parser) packageInterfaces(
continue
}

typ, ok := obj.Type().(*types.Named)
var typ *types.Named
var name string

ttyp := obj.Type()

if talias, ok := obj.Type().(*types.Alias); ok {
name = talias.Obj().Name()
ttyp = types.Unalias(obj.Type())
}

typ, ok := ttyp.(*types.Named)
if !ok {
continue
}

name = typ.Obj().Name()
if name == "" {
name = typ.Obj().Name()
}

if typ.Obj().Pkg() == nil {
continue
Expand Down
Loading