Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Fix output for empty interfaces. Added a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
balshetzer committed Apr 5, 2018
1 parent 44f7022 commit b391ab3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,15 @@ func (g *generator) Generate(pkg *model.Package, pkgName string, outputPackagePa
// Get all required imports, and generate unique names for them all.
im := pkg.Imports()
im[gomockImportPath] = true
im["reflect"] = true

// Only import reflect if it's used. We only use reflect in mocked methods
// so only import if any of the mocked interfaces have methods.
for _, intf := range pkg.Interfaces {
if len(intf.Methods) > 0 {
im["reflect"] = true
break
}
}

// Sort keys to make import alias generation predictable
sorted_paths := make([]string, len(im), len(im))
Expand Down
4 changes: 4 additions & 0 deletions mockgen/tests/empty_interface/input.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//go:generate mockgen -package empty_interface -destination mock.go -source input.go
package empty_interface

type Empty interface{}
32 changes: 32 additions & 0 deletions mockgen/tests/empty_interface/mock.go

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

0 comments on commit b391ab3

Please sign in to comment.