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

mockgen: Sanitize the "any" package name #132

Merged
merged 1 commit into from
Dec 20, 2023
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
5 changes: 5 additions & 0 deletions mockgen/internal/tests/sanitization/any/any.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package any

// Any is a type of a package that tests the sanitization of imported packages
// named any.
type Any struct {}
11 changes: 11 additions & 0 deletions mockgen/internal/tests/sanitization/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sanitization

import (
"go.uber.org/mock/mockgen/internal/tests/sanitization/any"
)

//go:generate mockgen -destination mockout/mock.go -package mockout . AnyMock

type AnyMock interface {
Do(a *any.Any, b int)
}
52 changes: 52 additions & 0 deletions mockgen/internal/tests/sanitization/mockout/mock.go

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

16 changes: 16 additions & 0 deletions mockgen/internal/tests/sanitization/sanitization_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package sanitization

import (
"testing"

"go.uber.org/mock/gomock"
any0 "go.uber.org/mock/mockgen/internal/tests/sanitization/any"
"go.uber.org/mock/mockgen/internal/tests/sanitization/mockout"
)

func TestSanitization(t *testing.T) {
ctrl := gomock.NewController(t)
m := mockout.NewMockAnyMock(ctrl)
m.EXPECT().Do(gomock.Any(), 1)
m.Do(&any0.Any{}, 1)
}
2 changes: 1 addition & 1 deletion mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (g *generator) Generate(pkg *model.Package, outputPkgName string, outputPac
}

i := 0
for localNames[pkgName] || token.Lookup(pkgName).IsKeyword() {
for localNames[pkgName] || token.Lookup(pkgName).IsKeyword() || pkgName == "any" {
pkgName = base + strconv.Itoa(i)
i++
}
Expand Down