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

Commit

Permalink
Merge pull request #170 from golang/iss102
Browse files Browse the repository at this point in the history
Fix output for empty interfaces. Added a test.
  • Loading branch information
balshetzer authored Apr 5, 2018
2 parents 44f7022 + b391ab3 commit c34cdb4
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 c34cdb4

Please sign in to comment.