From 30754231db8d098974fa253890fcef649cf000aa Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Fri, 9 Aug 2024 14:02:45 +0300 Subject: [PATCH 01/16] deprecated reflect mode has been replaced with import mode. benefits: * generation mocks for generic interfaces * generation mocks for aliases to interfaces * correct names for method arguments --- go.mod | 9 +- go.sum | 11 + gomock/internal/mock_gomock/mock_matcher.go | 8 +- mockgen/import_mode.go | 352 ++++ mockgen/import_mode_test.go | 238 +++ .../tests/add_generate_directive/mock.go | 12 +- mockgen/internal/tests/extra_import/mock.go | 8 +- mockgen/internal/tests/generics/external.go | 1 + mockgen/internal/tests/generics/generics.go | 2 +- .../generics/import_mode/import_mode_test.go | 23 + .../import_mode/mock_external_mock.go | 623 +++++++ .../tests/generics/import_mode/mock_test.go | 527 ++++++ .../internal/tests/import_mode/guns/guns.go | 49 + .../internal/tests/import_mode/interfaces.go | 74 + .../tests/import_mode/mock/interfaces.go | 1451 +++++++++++++++++ .../import_mode/projectiles/projectiles.go | 30 + .../import_mode/stratagems/interfaces.go | 14 + .../tests/mock_name/mocks/post_service.go | 8 +- .../tests/mock_name/mocks/user_service.go | 8 +- .../tests/sanitization/mockout/mock.go | 8 +- mockgen/mockgen.go | 3 +- mockgen/reflect.go | 256 --- sample/concurrent/mock/concurrent_mock.go | 8 +- sample/mock_user_test.go | 114 +- 24 files changed, 3491 insertions(+), 346 deletions(-) create mode 100644 mockgen/import_mode.go create mode 100644 mockgen/import_mode_test.go create mode 100644 mockgen/internal/tests/generics/import_mode/import_mode_test.go create mode 100644 mockgen/internal/tests/generics/import_mode/mock_external_mock.go create mode 100644 mockgen/internal/tests/generics/import_mode/mock_test.go create mode 100644 mockgen/internal/tests/import_mode/guns/guns.go create mode 100644 mockgen/internal/tests/import_mode/interfaces.go create mode 100644 mockgen/internal/tests/import_mode/mock/interfaces.go create mode 100644 mockgen/internal/tests/import_mode/projectiles/projectiles.go create mode 100644 mockgen/internal/tests/import_mode/stratagems/interfaces.go delete mode 100644 mockgen/reflect.go diff --git a/go.mod b/go.mod index 9bc7fad..46ce2f8 100644 --- a/go.mod +++ b/go.mod @@ -3,8 +3,15 @@ module go.uber.org/mock go 1.19 require ( + github.com/stretchr/testify v1.9.0 golang.org/x/mod v0.18.0 golang.org/x/tools v0.22.0 ) -require github.com/yuin/goldmark v1.4.13 // indirect +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/yuin/goldmark v1.4.13 // indirect + golang.org/x/sync v0.7.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum index 00a4009..e0222c2 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,18 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/gomock/internal/mock_gomock/mock_matcher.go b/gomock/internal/mock_gomock/mock_matcher.go index fb0693c..dad59be 100644 --- a/gomock/internal/mock_gomock/mock_matcher.go +++ b/gomock/internal/mock_gomock/mock_matcher.go @@ -44,17 +44,17 @@ func (m *MockMatcher) ISGOMOCK() struct{} { } // Matches mocks base method. -func (m *MockMatcher) Matches(arg0 any) bool { +func (m *MockMatcher) Matches(x any) bool { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Matches", arg0) + ret := m.ctrl.Call(m, "Matches", x) ret0, _ := ret[0].(bool) return ret0 } // Matches indicates an expected call of Matches. -func (mr *MockMatcherMockRecorder) Matches(arg0 any) *gomock.Call { +func (mr *MockMatcherMockRecorder) Matches(x any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Matches", reflect.TypeOf((*MockMatcher)(nil).Matches), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Matches", reflect.TypeOf((*MockMatcher)(nil).Matches), x) } // String mocks base method. diff --git a/mockgen/import_mode.go b/mockgen/import_mode.go new file mode 100644 index 0000000..9298cb6 --- /dev/null +++ b/mockgen/import_mode.go @@ -0,0 +1,352 @@ +package main + +import ( + "fmt" + "go/token" + "go/types" + "math/rand" + "os" + + "go.uber.org/mock/mockgen/model" + "golang.org/x/tools/go/packages" +) + +type importModeParser struct { + pkgName string +} + +func (p *importModeParser) parsePackage(packageName string, ifaces []string) (*model.Package, error) { + p.pkgName = packageName + + pkg, err := p.loadPackage(packageName) + if err != nil { + return nil, fmt.Errorf("failed to load package: %w", err) + } + + interfaces, err := p.extractInterfacesFromPackage(pkg, ifaces) + if err != nil { + return nil, fmt.Errorf("failed to extract interfaces from package: %w", err) + } + + return &model.Package{ + Name: pkg.Types.Name(), + PkgPath: packageName, + Interfaces: interfaces, + }, nil +} + +func (p *importModeParser) loadPackage(packageName string) (*packages.Package, error) { + const fakeFileTemplate = ` + package main + + import ( + "%s" + ) + ` + + dirName := "mockgen_" + p.generateSalt() + err := os.Mkdir(dirName, 0755) + if err != nil { + return nil, fmt.Errorf("failed to create temp dir for fake package: %w", err) + } + defer os.RemoveAll(dirName) + + err = os.WriteFile(dirName+"/main.go", []byte(fmt.Sprintf(fakeFileTemplate, packageName)), 0666) + if err != nil { + return nil, fmt.Errorf("failed to write fake main.go: %w", err) + } + + fileSet := token.NewFileSet() + + cfg := &packages.Config{ + Mode: packages.NeedDeps | packages.NeedImports | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedEmbedFiles, + Dir: dirName, + Fset: fileSet, + } + pkgs, err := packages.Load(cfg) + if err != nil { + return nil, fmt.Errorf("failed to load packages: %w", err) + } + + if len(pkgs) != 1 { + return nil, fmt.Errorf("packages length must be 1: %d", len(pkgs)) + } + + pkg := pkgs[0] + searchedPkg, ok := pkg.Imports[packageName] + if !ok { + return nil, fmt.Errorf("package %s not found", packageName) + } + + return searchedPkg, nil +} + +func (p *importModeParser) generateSalt() string { + var numbers = []byte("0123456789") + + result := make([]byte, 8) + for i := range result { + result[i] = numbers[rand.Intn(len(numbers))] + } + + return string(result) +} + +func (p *importModeParser) extractInterfacesFromPackage(pkg *packages.Package, ifaces []string) ([]*model.Interface, error) { + interfaces := make([]*model.Interface, len(ifaces)) + for i, iface := range ifaces { + obj := pkg.Types.Scope().Lookup(iface) + if obj == nil { + return nil, fmt.Errorf("interface %s does not exists", iface) + } + + modelIface, err := p.parseInterface(obj) + if err != nil { + return nil, fmt.Errorf("failed to parse interface: %w", err) + } + + interfaces[i] = modelIface + } + + return interfaces, nil +} + +func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, error) { + named, ok := obj.Type().(*types.Named) + if !ok { + return nil, fmt.Errorf("%s is not an interface. it is a %s", obj.Name(), obj.Type().Underlying().String()) + } + + iface, ok := named.Underlying().(*types.Interface) + if !ok { + return nil, fmt.Errorf("%s is not an interface. it is a %s", obj.Name(), obj.Type().Underlying().String()) + } + + iface = iface.Complete() + + if !p.checkInterfaceIsNotConstraint(iface) { + return nil, fmt.Errorf("interface %s is a constraint", obj.Name()) + } + + methods := make([]*model.Method, iface.NumMethods()) + for i := 0; i < iface.NumMethods(); i++ { + method := iface.Method(i) + typedMethod, ok := method.Type().(*types.Signature) + if !ok { + return nil, fmt.Errorf("method %s is not a signature", method.Name()) + } + + modelFunc, err := p.parseFunc(typedMethod) + if err != nil { + return nil, fmt.Errorf("failed to parse method: %w", err) + } + + methods[i] = &model.Method{ + Name: method.Name(), + In: modelFunc.In, + Out: modelFunc.Out, + Variadic: modelFunc.Variadic, + } + } + + var typeParams []*model.Parameter + if named.TypeParams() != nil { + typeParams = make([]*model.Parameter, named.TypeParams().Len()) + for i := 0; i < named.TypeParams().Len(); i++ { + param := named.TypeParams().At(i) + typeParam, err := p.parseConstraint(param) + if err != nil { + return nil, fmt.Errorf("failed to parse type parameter: %w", err) + } + + typeParams[i] = &model.Parameter{Name: param.Obj().Name(), Type: typeParam} + } + } + + return &model.Interface{Name: obj.Name(), Methods: methods, TypeParams: typeParams}, nil +} + +func (o *importModeParser) checkInterfaceIsNotConstraint(t *types.Interface) bool { + for i := 0; i < t.NumEmbeddeds(); i++ { + embed := t.EmbeddedType(i) + if _, ok := embed.Underlying().(*types.Interface); !ok { + return false + } + } + + return true +} + +func (p *importModeParser) parseType(t types.Type) (model.Type, error) { + switch t := t.(type) { + case *types.Array: + elementType, err := p.parseType(t.Elem()) + if err != nil { + return nil, fmt.Errorf("failed to parse array type: %w", err) + } + return &model.ArrayType{Len: int(t.Len()), Type: elementType}, nil + case *types.Slice: + elementType, err := p.parseType(t.Elem()) + if err != nil { + return nil, fmt.Errorf("failed to parse array type: %w", err) + } + + return &model.ArrayType{Len: -1, Type: elementType}, nil + case *types.Chan: + var dir model.ChanDir + switch t.Dir() { + case types.RecvOnly: + dir = model.RecvDir + case types.SendOnly: + dir = model.SendDir + } + + chanType, err := p.parseType(t.Elem()) + if err != nil { + return nil, fmt.Errorf("failed to parse chan type: %w", err) + } + + return &model.ChanType{Dir: dir, Type: chanType}, nil + case *types.Signature: + sig, err := p.parseFunc(t) + if err != nil { + return nil, fmt.Errorf("failed to parse signature: %w", err) + } + + return sig, nil + case *types.Named: + var typeParams *model.TypeParametersType + if t.TypeArgs() != nil { + typeParams = &model.TypeParametersType{TypeParameters: make([]model.Type, t.TypeArgs().Len())} + for i := 0; i < t.TypeArgs().Len(); i++ { + typeParam := t.TypeArgs().At(i) + typedParam, err := p.parseType(typeParam) + if err != nil { + return nil, fmt.Errorf("failed to parse type parameter: %w", err) + } + + typeParams.TypeParameters[i] = typedParam + } + } + + var pkg string + if t.Obj().Pkg() != nil { + pkg = t.Obj().Pkg().Path() + } + + return &model.NamedType{ + Package: pkg, + Type: t.Obj().Name(), + TypeParams: typeParams, + }, nil + case *types.Interface: + if t.Empty() { + return model.PredeclaredType("any"), nil + } + + return nil, fmt.Errorf("cannot handle non-empty unnamed interfaces") + case *types.Map: + key, err := p.parseType(t.Key()) + if err != nil { + return nil, fmt.Errorf("failed to parse map key type: %w", err) + } + value, err := p.parseType(t.Elem()) + if err != nil { + return nil, fmt.Errorf("failed to parse map value type: %w", err) + } + + return &model.MapType{Key: key, Value: value}, nil + case *types.Pointer: + valueType, err := p.parseType(t.Elem()) + if err != nil { + return nil, fmt.Errorf("failed to parse pointer type: %w", err) + } + + return &model.PointerType{Type: valueType}, nil + case *types.Struct: + if t.NumFields() > 0 { + return nil, fmt.Errorf("cannot handle non-empty unnamed structs") + } + + return model.PredeclaredType("struct{}"), nil + case *types.Basic: + return model.PredeclaredType(t.Name()), nil + case *types.Tuple: + panic("tuple field") // TODO + case *types.TypeParam: + return &model.NamedType{Type: t.Obj().Name()}, nil + default: + panic("unknown type") // TODO + } +} + +func (p *importModeParser) parseFunc(sig *types.Signature) (*model.FuncType, error) { + var variadic *model.Parameter + params := make([]*model.Parameter, 0, sig.Params().Len()) + for i := 0; i < sig.Params().Len(); i++ { + param := sig.Params().At(i) + + isVariadicParam := i == sig.Params().Len()-1 && sig.Variadic() + parseType := param.Type() + if isVariadicParam { + sliceType, ok := param.Type().(*types.Slice) + if !ok { + return nil, fmt.Errorf("variadic parameter is not a slice") + } + + parseType = sliceType.Elem() + } + + paramType, err := p.parseType(parseType) + if err != nil { + return nil, fmt.Errorf("failed to parse parameter type: %w", err) + } + + modelParameter := &model.Parameter{Type: paramType, Name: param.Name()} + + if isVariadicParam { + variadic = modelParameter + } else { + params = append(params, modelParameter) + } + } + + if len(params) == 0 { + params = nil + } + + results := make([]*model.Parameter, sig.Results().Len()) + for i := 0; i < sig.Results().Len(); i++ { + result := sig.Results().At(i) + + resultType, err := p.parseType(result.Type()) + if err != nil { + return nil, fmt.Errorf("failed to parse result type: %w", err) + } + + results[i] = &model.Parameter{Type: resultType, Name: result.Name()} + } + + if len(results) == 0 { + results = nil + } + + return &model.FuncType{ + In: params, + Out: results, + Variadic: variadic, + }, nil +} + +func (p *importModeParser) parseConstraint(t *types.TypeParam) (model.Type, error) { + if t == nil { + return nil, fmt.Errorf("nil type param") + } + + typeParam, err := p.parseType(t.Constraint()) + if err != nil { + return nil, fmt.Errorf("failed to parse type parameter: %w", err) + } + + return typeParam, nil +} diff --git a/mockgen/import_mode_test.go b/mockgen/import_mode_test.go new file mode 100644 index 0000000..8c893aa --- /dev/null +++ b/mockgen/import_mode_test.go @@ -0,0 +1,238 @@ +package main + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "go.uber.org/mock/mockgen/model" +) + +func Test_importModeParser_parsePackage(t *testing.T) { + type args struct { + packageName string + ifaces []string + } + tests := []struct { + name string + args args + expected *model.Package + expectedErr string + }{ + { + name: "error: no found package", + args: args{ + packageName: "", + ifaces: []string{"ImmortalHelldiver"}, + }, + expectedErr: "failed to load package: package not found", + }, + { + name: "error: interface does not exists", + args: args{ + packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + ifaces: []string{"ImmortalHelldiver"}, + }, + expectedErr: "failed to extract interfaces from package: interface ImmortalHelldiver does not exists", + }, + { + name: "error: search for struct instead of interface", + args: args{ + packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + ifaces: []string{"Enemy"}, + }, + expectedErr: "failed to extract interfaces from package: failed to parse interface: " + + "Enemy is not an interface. it is a struct{Name string; Fraction string; Hp int}", + }, + { + name: "error: search for constraint instead of interface", + args: args{ + packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + ifaces: []string{"Counter"}, + }, + expectedErr: "failed to extract interfaces from package: failed to parse interface: " + + "interface Counter is a constraint", + }, + { + name: "success: simple interface", + args: args{ + packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + ifaces: []string{"DemocracyFan"}, + }, + expected: &model.Package{ + Name: "import_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Interfaces: []*model.Interface{ + { + Name: "DemocracyFan", + Methods: []*model.Method{ + {Name: "ILoveDemocracy"}, + {Name: "YouWillNeverDestroyOurWayOfLife"}, + }, + }, + }, + }, + }, + { + name: "success: interface with generic", + args: args{ + packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + ifaces: []string{"Shooter"}, + }, + expected: &model.Package{ + Name: "import_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Interfaces: []*model.Interface{ + { + Name: "Shooter", + Methods: []*model.Method{ + { + Name: "Gun", + Out: []*model.Parameter{ + {Type: &model.NamedType{Type: "GunType"}}, + }, + }, + { + Name: "Reload", + Out: []*model.Parameter{ + {Type: model.PredeclaredType("bool")}, + }, + }, + { + Name: "Shoot", + In: []*model.Parameter{ + {Name: "times", Type: model.PredeclaredType("int")}, + }, + Out: []*model.Parameter{ + {Type: model.PredeclaredType("bool")}, + {Type: &model.NamedType{Type: "error"}}, + }, + Variadic: &model.Parameter{ + Name: "targets", + Type: &model.PointerType{ + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Type: "Enemy", + }, + }, + }, + }, + }, + TypeParams: []*model.Parameter{ + { + Name: "ProjectileType", + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Type: "Projectile", + }, + }, + { + Name: "GunType", + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Type: "Gun", + TypeParams: &model.TypeParametersType{ + TypeParameters: []model.Type{ + &model.NamedType{ + Type: "ProjectileType", + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + { + name: "success: interface with embedded interfaces", + args: args{ + packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + ifaces: []string{"Helldiver"}, + }, + expected: &model.Package{ + Name: "import_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Interfaces: []*model.Interface{ + { + Name: "Helldiver", + Methods: []*model.Method{ + { + Name: "AvailableStratagems", + Out: []*model.Parameter{ + { + Type: &model.ArrayType{ + Len: -1, + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode/stratagems", + Type: "Stratagem", + }, + }, + }, + }, + }, + {Name: "ILoveDemocracy"}, + {Name: "YouWillNeverDestroyOurWayOfLife"}, + }, + }, + }, + }, + }, + { + name: "success: alias to interface", + args: args{ + packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + ifaces: []string{"SuperEarthCitizen"}, + }, + expected: &model.Package{ + Name: "import_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Interfaces: []*model.Interface{ + { + Name: "SuperEarthCitizen", + Methods: []*model.Method{ + {Name: "ILoveDemocracy"}, + {Name: "YouWillNeverDestroyOurWayOfLife"}, + }, + }, + }, + }, + }, + { + name: "success: embedded anonymous interface", + args: args{ + packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + ifaces: []string{"AgitationCampaign"}, + }, + expected: &model.Package{ + Name: "import_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Interfaces: []*model.Interface{ + { + Name: "AgitationCampaign", + Methods: []*model.Method{ + {Name: "BecomeAHelldiver"}, + {Name: "BecomeAHero"}, + {Name: "BecomeALegend"}, + }, + }, + }, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + parser := importModeParser{} + actual, err := parser.parsePackage(tt.args.packageName, tt.args.ifaces) + + if tt.expectedErr != "" { + assert.EqualError(t, err, tt.expectedErr) + } else { + assert.NoError(t, err) + } + + assert.Equal(t, tt.expected, actual) + }) + } +} diff --git a/mockgen/internal/tests/add_generate_directive/mock.go b/mockgen/internal/tests/add_generate_directive/mock.go index 1594548..142afb5 100644 --- a/mockgen/internal/tests/add_generate_directive/mock.go +++ b/mockgen/internal/tests/add_generate_directive/mock.go @@ -3,7 +3,7 @@ // // Generated by this command: // -// mockgen -write_generate_directive -destination mock.go -package add_generate_directive . Foo +// ___package_mode -write_generate_directive -destination mock.go -package add_generate_directive . Foo // // Package add_generate_directive is a generated GoMock package. @@ -15,7 +15,7 @@ import ( gomock "go.uber.org/mock/gomock" ) -//go:generate mockgen -write_generate_directive -destination mock.go -package add_generate_directive . Foo +//go:generate /Users/tulzke/Library/Caches/JetBrains/GoLand2023.3/tmp/GoLand/___package_mode -write_generate_directive -destination mock.go -package add_generate_directive . Foo // MockFoo is a mock of Foo interface. type MockFoo struct { @@ -46,13 +46,13 @@ func (m *MockFoo) ISGOMOCK() struct{} { } // Bar mocks base method. -func (m *MockFoo) Bar(arg0 []string, arg1 chan<- Message) { +func (m *MockFoo) Bar(channels []string, message chan<- Message) { m.ctrl.T.Helper() - m.ctrl.Call(m, "Bar", arg0, arg1) + m.ctrl.Call(m, "Bar", channels, message) } // Bar indicates an expected call of Bar. -func (mr *MockFooMockRecorder) Bar(arg0, arg1 any) *gomock.Call { +func (mr *MockFooMockRecorder) Bar(channels, message any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Bar", reflect.TypeOf((*MockFoo)(nil).Bar), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Bar", reflect.TypeOf((*MockFoo)(nil).Bar), channels, message) } diff --git a/mockgen/internal/tests/extra_import/mock.go b/mockgen/internal/tests/extra_import/mock.go index 1c3173c..d9aa28a 100644 --- a/mockgen/internal/tests/extra_import/mock.go +++ b/mockgen/internal/tests/extra_import/mock.go @@ -44,13 +44,13 @@ func (m *MockFoo) ISGOMOCK() struct{} { } // Bar mocks base method. -func (m *MockFoo) Bar(arg0 []string, arg1 chan<- Message) { +func (m *MockFoo) Bar(channels []string, message chan<- Message) { m.ctrl.T.Helper() - m.ctrl.Call(m, "Bar", arg0, arg1) + m.ctrl.Call(m, "Bar", channels, message) } // Bar indicates an expected call of Bar. -func (mr *MockFooMockRecorder) Bar(arg0, arg1 any) *gomock.Call { +func (mr *MockFooMockRecorder) Bar(channels, message any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Bar", reflect.TypeOf((*MockFoo)(nil).Bar), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Bar", reflect.TypeOf((*MockFoo)(nil).Bar), channels, message) } diff --git a/mockgen/internal/tests/generics/external.go b/mockgen/internal/tests/generics/external.go index a12c39f..6756361 100644 --- a/mockgen/internal/tests/generics/external.go +++ b/mockgen/internal/tests/generics/external.go @@ -9,6 +9,7 @@ import ( ) //go:generate mockgen --source=external.go --destination=source/mock_external_mock.go --package source +//go:generate mockgen --destination=import_mode/mock_external_mock.go -package=import_mode . ExternalConstraint,EmbeddingIface,Generator,Group type ExternalConstraint[I constraints.Integer, F any] interface { One(string) string diff --git a/mockgen/internal/tests/generics/generics.go b/mockgen/internal/tests/generics/generics.go index db0c49e..a788f21 100644 --- a/mockgen/internal/tests/generics/generics.go +++ b/mockgen/internal/tests/generics/generics.go @@ -6,7 +6,7 @@ import ( ) //go:generate mockgen --source=generics.go --destination=source/mock_generics_mock.go --package source -////go:generate mockgen --destination=reflect/mock_test.go --package reflect . Bar,Bar2 +//go:generate mockgen --destination=import_mode/mock_test.go --package=import_mode . Bar,Universe,MilkyWay,SolarSystem,Earth,Water type Bar[T any, R any] interface { One(string) string diff --git a/mockgen/internal/tests/generics/import_mode/import_mode_test.go b/mockgen/internal/tests/generics/import_mode/import_mode_test.go new file mode 100644 index 0000000..462af95 --- /dev/null +++ b/mockgen/internal/tests/generics/import_mode/import_mode_test.go @@ -0,0 +1,23 @@ +package import_mode + +import ( + "go.uber.org/mock/mockgen/internal/tests/generics" +) + +var bar generics.Bar[int, int] = &MockBar[int, int]{} + +var universe generics.Universe[int] = &MockUniverse[int]{} + +var solarSystem generics.SolarSystem[int] = &MockSolarSystem[int]{} + +var earth generics.Earth[int] = &MockEarth[int]{} + +var water generics.Water[int, uint] = &MockWater[int, uint]{} + +var externalConstraint generics.ExternalConstraint[int64, int] = &MockExternalConstraint[int64, int]{} + +var embeddedIface generics.EmbeddingIface[int, float64] = &MockEmbeddingIface[int, float64]{} + +var generator generics.Generator[int] = &MockGenerator[int]{} + +var group generics.Group[generics.Generator[any]] = &MockGroup[generics.Generator[any]]{} diff --git a/mockgen/internal/tests/generics/import_mode/mock_external_mock.go b/mockgen/internal/tests/generics/import_mode/mock_external_mock.go new file mode 100644 index 0000000..0766384 --- /dev/null +++ b/mockgen/internal/tests/generics/import_mode/mock_external_mock.go @@ -0,0 +1,623 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: go.uber.org/mock/mockgen/internal/tests/generics (interfaces: ExternalConstraint,EmbeddingIface,Generator,Group) +// +// Generated by this command: +// +// mockgen --destination=import_mode/mock_external_mock.go -package=import_mode . ExternalConstraint,EmbeddingIface,Generator,Group +// + +// Package import_mode is a generated GoMock package. +package import_mode + +import ( + context "context" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + generics "go.uber.org/mock/mockgen/internal/tests/generics" + other "go.uber.org/mock/mockgen/internal/tests/generics/other" + constraints "golang.org/x/exp/constraints" +) + +// MockExternalConstraint is a mock of ExternalConstraint interface. +type MockExternalConstraint[I constraints.Integer, F any] struct { + ctrl *gomock.Controller + recorder *MockExternalConstraintMockRecorder[I, F] +} + +// MockExternalConstraintMockRecorder is the mock recorder for MockExternalConstraint. +type MockExternalConstraintMockRecorder[I constraints.Integer, F any] struct { + mock *MockExternalConstraint[I, F] +} + +// NewMockExternalConstraint creates a new mock instance. +func NewMockExternalConstraint[I constraints.Integer, F any](ctrl *gomock.Controller) *MockExternalConstraint[I, F] { + mock := &MockExternalConstraint[I, F]{ctrl: ctrl} + mock.recorder = &MockExternalConstraintMockRecorder[I, F]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExternalConstraint[I, F]) EXPECT() *MockExternalConstraintMockRecorder[I, F] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockExternalConstraint[I, F]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Eight mocks base method. +func (m *MockExternalConstraint[I, F]) Eight(arg0 F) other.Two[I, F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[I, F]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockExternalConstraintMockRecorder[I, F]) Eight(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eight), arg0) +} + +// Eleven mocks base method. +func (m *MockExternalConstraint[I, F]) Eleven() map[string]I { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(map[string]I) + return ret0 +} + +// Eleven indicates an expected call of Eleven. +func (mr *MockExternalConstraintMockRecorder[I, F]) Eleven() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eleven)) +} + +// Five mocks base method. +func (m *MockExternalConstraint[I, F]) Five(arg0 I) generics.Baz[F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(generics.Baz[F]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockExternalConstraintMockRecorder[I, F]) Five(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Five), arg0) +} + +// Four mocks base method. +func (m *MockExternalConstraint[I, F]) Four(arg0 I) generics.Foo[I, F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(generics.Foo[I, F]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockExternalConstraintMockRecorder[I, F]) Four(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Four), arg0) +} + +// Nine mocks base method. +func (m *MockExternalConstraint[I, F]) Nine(arg0 generics.Iface[I]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockExternalConstraintMockRecorder[I, F]) Nine(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Nine), arg0) +} + +// One mocks base method. +func (m *MockExternalConstraint[I, F]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockExternalConstraintMockRecorder[I, F]) One(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).One), arg0) +} + +// Seven mocks base method. +func (m *MockExternalConstraint[I, F]) Seven(arg0 I) other.One[I] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[I]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockExternalConstraintMockRecorder[I, F]) Seven(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Seven), arg0) +} + +// Six mocks base method. +func (m *MockExternalConstraint[I, F]) Six(arg0 I) *generics.Baz[F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*generics.Baz[F]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockExternalConstraintMockRecorder[I, F]) Six(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Six), arg0) +} + +// Ten mocks base method. +func (m *MockExternalConstraint[I, F]) Ten(arg0 *I) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockExternalConstraintMockRecorder[I, F]) Ten(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Ten), arg0) +} + +// Thirteen mocks base method. +func (m *MockExternalConstraint[I, F]) Thirteen(arg0 ...I) *F { + m.ctrl.T.Helper() + varargs := []any{} + for _, a := range arg0 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Thirteen", varargs...) + ret0, _ := ret[0].(*F) + return ret0 +} + +// Thirteen indicates an expected call of Thirteen. +func (mr *MockExternalConstraintMockRecorder[I, F]) Thirteen(arg0 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Thirteen), arg0...) +} + +// Three mocks base method. +func (m *MockExternalConstraint[I, F]) Three(arg0 I) F { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(F) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockExternalConstraintMockRecorder[I, F]) Three(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Three), arg0) +} + +// Twelve mocks base method. +func (m *MockExternalConstraint[I, F]) Twelve(arg0 context.Context) <-chan []I { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twelve", arg0) + ret0, _ := ret[0].(<-chan []I) + return ret0 +} + +// Twelve indicates an expected call of Twelve. +func (mr *MockExternalConstraintMockRecorder[I, F]) Twelve(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Twelve), arg0) +} + +// Two mocks base method. +func (m *MockExternalConstraint[I, F]) Two(arg0 I) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockExternalConstraintMockRecorder[I, F]) Two(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Two), arg0) +} + +// MockEmbeddingIface is a mock of EmbeddingIface interface. +type MockEmbeddingIface[T constraints.Integer, R constraints.Float] struct { + ctrl *gomock.Controller + recorder *MockEmbeddingIfaceMockRecorder[T, R] +} + +// MockEmbeddingIfaceMockRecorder is the mock recorder for MockEmbeddingIface. +type MockEmbeddingIfaceMockRecorder[T constraints.Integer, R constraints.Float] struct { + mock *MockEmbeddingIface[T, R] +} + +// NewMockEmbeddingIface creates a new mock instance. +func NewMockEmbeddingIface[T constraints.Integer, R constraints.Float](ctrl *gomock.Controller) *MockEmbeddingIface[T, R] { + mock := &MockEmbeddingIface[T, R]{ctrl: ctrl} + mock.recorder = &MockEmbeddingIfaceMockRecorder[T, R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEmbeddingIface[T, R]) EXPECT() *MockEmbeddingIfaceMockRecorder[T, R] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockEmbeddingIface[T, R]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Eight mocks base method. +func (m *MockEmbeddingIface[T, R]) Eight(arg0 R) other.Two[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[T, R]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eight(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eight), arg0) +} + +// Eleven mocks base method. +func (m *MockEmbeddingIface[T, R]) Eleven() map[string]T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(map[string]T) + return ret0 +} + +// Eleven indicates an expected call of Eleven. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eleven() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eleven)) +} + +// First mocks base method. +func (m *MockEmbeddingIface[T, R]) First() R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "First") + ret0, _ := ret[0].(R) + return ret0 +} + +// First indicates an expected call of First. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) First() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "First", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).First)) +} + +// Five mocks base method. +func (m *MockEmbeddingIface[T, R]) Five(arg0 T) generics.Baz[R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(generics.Baz[R]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Five(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Five), arg0) +} + +// Four mocks base method. +func (m *MockEmbeddingIface[T, R]) Four(arg0 T) generics.Foo[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(generics.Foo[T, R]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Four(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Four), arg0) +} + +// Fourth mocks base method. +func (m *MockEmbeddingIface[T, R]) Fourth() generics.Generator[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Fourth") + ret0, _ := ret[0].(generics.Generator[T]) + return ret0 +} + +// Fourth indicates an expected call of Fourth. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Fourth() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fourth", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Fourth)) +} + +// Generate mocks base method. +func (m *MockEmbeddingIface[T, R]) Generate() R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Generate") + ret0, _ := ret[0].(R) + return ret0 +} + +// Generate indicates an expected call of Generate. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Generate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Generate)) +} + +// Nine mocks base method. +func (m *MockEmbeddingIface[T, R]) Nine(arg0 generics.Iface[T]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Nine(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Nine), arg0) +} + +// One mocks base method. +func (m *MockEmbeddingIface[T, R]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) One(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).One), arg0) +} + +// Read mocks base method. +func (m *MockEmbeddingIface[T, R]) Read(arg0 []byte) (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Read", arg0) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Read(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Read), arg0) +} + +// Second mocks base method. +func (m *MockEmbeddingIface[T, R]) Second() generics.StructType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Second") + ret0, _ := ret[0].(generics.StructType) + return ret0 +} + +// Second indicates an expected call of Second. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Second() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Second", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Second)) +} + +// Seven mocks base method. +func (m *MockEmbeddingIface[T, R]) Seven(arg0 T) other.One[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[T]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Seven(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Seven), arg0) +} + +// Six mocks base method. +func (m *MockEmbeddingIface[T, R]) Six(arg0 T) *generics.Baz[R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*generics.Baz[R]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Six(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Six), arg0) +} + +// Ten mocks base method. +func (m *MockEmbeddingIface[T, R]) Ten(arg0 *T) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Ten(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Ten), arg0) +} + +// Third mocks base method. +func (m *MockEmbeddingIface[T, R]) Third() other.Five { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Third") + ret0, _ := ret[0].(other.Five) + return ret0 +} + +// Third indicates an expected call of Third. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Third() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Third", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Third)) +} + +// Thirteen mocks base method. +func (m *MockEmbeddingIface[T, R]) Thirteen(arg0 ...T) *R { + m.ctrl.T.Helper() + varargs := []any{} + for _, a := range arg0 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Thirteen", varargs...) + ret0, _ := ret[0].(*R) + return ret0 +} + +// Thirteen indicates an expected call of Thirteen. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Thirteen(arg0 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Thirteen), arg0...) +} + +// Three mocks base method. +func (m *MockEmbeddingIface[T, R]) Three(arg0 T) R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(R) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Three(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Three), arg0) +} + +// Twelve mocks base method. +func (m *MockEmbeddingIface[T, R]) Twelve(arg0 context.Context) <-chan []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twelve", arg0) + ret0, _ := ret[0].(<-chan []T) + return ret0 +} + +// Twelve indicates an expected call of Twelve. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Twelve(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Twelve), arg0) +} + +// Two mocks base method. +func (m *MockEmbeddingIface[T, R]) Two(arg0 T) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Two(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Two), arg0) +} + +// Water mocks base method. +func (m *MockEmbeddingIface[T, R]) Water(arg0 generics.Generator[T]) []generics.Generator[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]generics.Generator[T]) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Water(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Water), arg0) +} + +// MockGenerator is a mock of Generator interface. +type MockGenerator[T any] struct { + ctrl *gomock.Controller + recorder *MockGeneratorMockRecorder[T] +} + +// MockGeneratorMockRecorder is the mock recorder for MockGenerator. +type MockGeneratorMockRecorder[T any] struct { + mock *MockGenerator[T] +} + +// NewMockGenerator creates a new mock instance. +func NewMockGenerator[T any](ctrl *gomock.Controller) *MockGenerator[T] { + mock := &MockGenerator[T]{ctrl: ctrl} + mock.recorder = &MockGeneratorMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGenerator[T]) EXPECT() *MockGeneratorMockRecorder[T] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockGenerator[T]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Generate mocks base method. +func (m *MockGenerator[T]) Generate() T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Generate") + ret0, _ := ret[0].(T) + return ret0 +} + +// Generate indicates an expected call of Generate. +func (mr *MockGeneratorMockRecorder[T]) Generate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockGenerator[T])(nil).Generate)) +} + +// MockGroup is a mock of Group interface. +type MockGroup[T generics.Generator[any]] struct { + ctrl *gomock.Controller + recorder *MockGroupMockRecorder[T] +} + +// MockGroupMockRecorder is the mock recorder for MockGroup. +type MockGroupMockRecorder[T generics.Generator[any]] struct { + mock *MockGroup[T] +} + +// NewMockGroup creates a new mock instance. +func NewMockGroup[T generics.Generator[any]](ctrl *gomock.Controller) *MockGroup[T] { + mock := &MockGroup[T]{ctrl: ctrl} + mock.recorder = &MockGroupMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGroup[T]) EXPECT() *MockGroupMockRecorder[T] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockGroup[T]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Join mocks base method. +func (m *MockGroup[T]) Join(arg0 context.Context) []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Join", arg0) + ret0, _ := ret[0].([]T) + return ret0 +} + +// Join indicates an expected call of Join. +func (mr *MockGroupMockRecorder[T]) Join(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Join", reflect.TypeOf((*MockGroup[T])(nil).Join), arg0) +} diff --git a/mockgen/internal/tests/generics/import_mode/mock_test.go b/mockgen/internal/tests/generics/import_mode/mock_test.go new file mode 100644 index 0000000..23546b6 --- /dev/null +++ b/mockgen/internal/tests/generics/import_mode/mock_test.go @@ -0,0 +1,527 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: go.uber.org/mock/mockgen/internal/tests/generics (interfaces: Bar,Universe,MilkyWay,SolarSystem,Earth,Water) +// +// Generated by this command: +// +// ___1package_mode --destination=import_mode/mock_test.go --package=import_mode . Bar,Universe,MilkyWay,SolarSystem,Earth,Water +// + +// Package import_mode is a generated GoMock package. +package import_mode + +import ( + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + generics "go.uber.org/mock/mockgen/internal/tests/generics" + other "go.uber.org/mock/mockgen/internal/tests/generics/other" + constraints "golang.org/x/exp/constraints" +) + +// MockBar is a mock of Bar interface. +type MockBar[T any, R any] struct { + ctrl *gomock.Controller + recorder *MockBarMockRecorder[T, R] +} + +// MockBarMockRecorder is the mock recorder for MockBar. +type MockBarMockRecorder[T any, R any] struct { + mock *MockBar[T, R] +} + +// NewMockBar creates a new mock instance. +func NewMockBar[T any, R any](ctrl *gomock.Controller) *MockBar[T, R] { + mock := &MockBar[T, R]{ctrl: ctrl} + mock.recorder = &MockBarMockRecorder[T, R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockBar[T, R]) EXPECT() *MockBarMockRecorder[T, R] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockBar[T, R]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Eight mocks base method. +func (m *MockBar[T, R]) Eight(arg0 T) other.Two[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[T, R]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockBarMockRecorder[T, R]) Eight(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockBar[T, R])(nil).Eight), arg0) +} + +// Eighteen mocks base method. +func (m *MockBar[T, R]) Eighteen() (generics.Iface[*other.Five], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eighteen") + ret0, _ := ret[0].(generics.Iface[*other.Five]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Eighteen indicates an expected call of Eighteen. +func (mr *MockBarMockRecorder[T, R]) Eighteen() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eighteen", reflect.TypeOf((*MockBar[T, R])(nil).Eighteen)) +} + +// Eleven mocks base method. +func (m *MockBar[T, R]) Eleven() (*other.One[T], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(*other.One[T]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Eleven indicates an expected call of Eleven. +func (mr *MockBarMockRecorder[T, R]) Eleven() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockBar[T, R])(nil).Eleven)) +} + +// Fifteen mocks base method. +func (m *MockBar[T, R]) Fifteen() (generics.Iface[generics.StructType], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Fifteen") + ret0, _ := ret[0].(generics.Iface[generics.StructType]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Fifteen indicates an expected call of Fifteen. +func (mr *MockBarMockRecorder[T, R]) Fifteen() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fifteen", reflect.TypeOf((*MockBar[T, R])(nil).Fifteen)) +} + +// Five mocks base method. +func (m *MockBar[T, R]) Five(arg0 T) generics.Baz[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(generics.Baz[T]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockBarMockRecorder[T, R]) Five(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockBar[T, R])(nil).Five), arg0) +} + +// Four mocks base method. +func (m *MockBar[T, R]) Four(arg0 T) generics.Foo[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(generics.Foo[T, R]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockBarMockRecorder[T, R]) Four(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockBar[T, R])(nil).Four), arg0) +} + +// Fourteen mocks base method. +func (m *MockBar[T, R]) Fourteen() (*generics.Foo[generics.StructType, generics.StructType2], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Fourteen") + ret0, _ := ret[0].(*generics.Foo[generics.StructType, generics.StructType2]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Fourteen indicates an expected call of Fourteen. +func (mr *MockBarMockRecorder[T, R]) Fourteen() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fourteen", reflect.TypeOf((*MockBar[T, R])(nil).Fourteen)) +} + +// Nine mocks base method. +func (m *MockBar[T, R]) Nine(arg0 generics.Iface[T]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockBarMockRecorder[T, R]) Nine(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockBar[T, R])(nil).Nine), arg0) +} + +// Nineteen mocks base method. +func (m *MockBar[T, R]) Nineteen() generics.AliasType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Nineteen") + ret0, _ := ret[0].(generics.AliasType) + return ret0 +} + +// Nineteen indicates an expected call of Nineteen. +func (mr *MockBarMockRecorder[T, R]) Nineteen() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nineteen", reflect.TypeOf((*MockBar[T, R])(nil).Nineteen)) +} + +// One mocks base method. +func (m *MockBar[T, R]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockBarMockRecorder[T, R]) One(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockBar[T, R])(nil).One), arg0) +} + +// Seven mocks base method. +func (m *MockBar[T, R]) Seven(arg0 T) other.One[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[T]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockBarMockRecorder[T, R]) Seven(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockBar[T, R])(nil).Seven), arg0) +} + +// Seventeen mocks base method. +func (m *MockBar[T, R]) Seventeen() (*generics.Foo[other.Three, other.Four], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seventeen") + ret0, _ := ret[0].(*generics.Foo[other.Three, other.Four]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Seventeen indicates an expected call of Seventeen. +func (mr *MockBarMockRecorder[T, R]) Seventeen() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seventeen", reflect.TypeOf((*MockBar[T, R])(nil).Seventeen)) +} + +// Six mocks base method. +func (m *MockBar[T, R]) Six(arg0 T) *generics.Baz[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*generics.Baz[T]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockBarMockRecorder[T, R]) Six(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockBar[T, R])(nil).Six), arg0) +} + +// Sixteen mocks base method. +func (m *MockBar[T, R]) Sixteen() (generics.Baz[other.Three], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Sixteen") + ret0, _ := ret[0].(generics.Baz[other.Three]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Sixteen indicates an expected call of Sixteen. +func (mr *MockBarMockRecorder[T, R]) Sixteen() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sixteen", reflect.TypeOf((*MockBar[T, R])(nil).Sixteen)) +} + +// Ten mocks base method. +func (m *MockBar[T, R]) Ten(arg0 *T) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockBarMockRecorder[T, R]) Ten(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockBar[T, R])(nil).Ten), arg0) +} + +// Thirteen mocks base method. +func (m *MockBar[T, R]) Thirteen() (generics.Baz[generics.StructType], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Thirteen") + ret0, _ := ret[0].(generics.Baz[generics.StructType]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Thirteen indicates an expected call of Thirteen. +func (mr *MockBarMockRecorder[T, R]) Thirteen() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockBar[T, R])(nil).Thirteen)) +} + +// Three mocks base method. +func (m *MockBar[T, R]) Three(arg0 T) R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(R) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockBarMockRecorder[T, R]) Three(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockBar[T, R])(nil).Three), arg0) +} + +// Twelve mocks base method. +func (m *MockBar[T, R]) Twelve() (*other.Two[T, R], error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twelve") + ret0, _ := ret[0].(*other.Two[T, R]) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Twelve indicates an expected call of Twelve. +func (mr *MockBarMockRecorder[T, R]) Twelve() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockBar[T, R])(nil).Twelve)) +} + +// Two mocks base method. +func (m *MockBar[T, R]) Two(arg0 T) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockBarMockRecorder[T, R]) Two(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockBar[T, R])(nil).Two), arg0) +} + +// MockUniverse is a mock of Universe interface. +type MockUniverse[T constraints.Signed] struct { + ctrl *gomock.Controller + recorder *MockUniverseMockRecorder[T] +} + +// MockUniverseMockRecorder is the mock recorder for MockUniverse. +type MockUniverseMockRecorder[T constraints.Signed] struct { + mock *MockUniverse[T] +} + +// NewMockUniverse creates a new mock instance. +func NewMockUniverse[T constraints.Signed](ctrl *gomock.Controller) *MockUniverse[T] { + mock := &MockUniverse[T]{ctrl: ctrl} + mock.recorder = &MockUniverseMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockUniverse[T]) EXPECT() *MockUniverseMockRecorder[T] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockUniverse[T]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Water mocks base method. +func (m *MockUniverse[T]) Water(arg0 T) []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]T) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockUniverseMockRecorder[T]) Water(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockUniverse[T])(nil).Water), arg0) +} + +// MockMilkyWay is a mock of MilkyWay interface. +type MockMilkyWay[R constraints.Integer] struct { + ctrl *gomock.Controller + recorder *MockMilkyWayMockRecorder[R] +} + +// MockMilkyWayMockRecorder is the mock recorder for MockMilkyWay. +type MockMilkyWayMockRecorder[R constraints.Integer] struct { + mock *MockMilkyWay[R] +} + +// NewMockMilkyWay creates a new mock instance. +func NewMockMilkyWay[R constraints.Integer](ctrl *gomock.Controller) *MockMilkyWay[R] { + mock := &MockMilkyWay[R]{ctrl: ctrl} + mock.recorder = &MockMilkyWayMockRecorder[R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockMilkyWay[R]) EXPECT() *MockMilkyWayMockRecorder[R] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockMilkyWay[R]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Water mocks base method. +func (m *MockMilkyWay[R]) Water(arg0 R) []R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]R) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockMilkyWayMockRecorder[R]) Water(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockMilkyWay[R])(nil).Water), arg0) +} + +// MockSolarSystem is a mock of SolarSystem interface. +type MockSolarSystem[T constraints.Ordered] struct { + ctrl *gomock.Controller + recorder *MockSolarSystemMockRecorder[T] +} + +// MockSolarSystemMockRecorder is the mock recorder for MockSolarSystem. +type MockSolarSystemMockRecorder[T constraints.Ordered] struct { + mock *MockSolarSystem[T] +} + +// NewMockSolarSystem creates a new mock instance. +func NewMockSolarSystem[T constraints.Ordered](ctrl *gomock.Controller) *MockSolarSystem[T] { + mock := &MockSolarSystem[T]{ctrl: ctrl} + mock.recorder = &MockSolarSystemMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSolarSystem[T]) EXPECT() *MockSolarSystemMockRecorder[T] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockSolarSystem[T]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Water mocks base method. +func (m *MockSolarSystem[T]) Water(arg0 T) []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]T) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockSolarSystemMockRecorder[T]) Water(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockSolarSystem[T])(nil).Water), arg0) +} + +// MockEarth is a mock of Earth interface. +type MockEarth[R any] struct { + ctrl *gomock.Controller + recorder *MockEarthMockRecorder[R] +} + +// MockEarthMockRecorder is the mock recorder for MockEarth. +type MockEarthMockRecorder[R any] struct { + mock *MockEarth[R] +} + +// NewMockEarth creates a new mock instance. +func NewMockEarth[R any](ctrl *gomock.Controller) *MockEarth[R] { + mock := &MockEarth[R]{ctrl: ctrl} + mock.recorder = &MockEarthMockRecorder[R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEarth[R]) EXPECT() *MockEarthMockRecorder[R] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockEarth[R]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Water mocks base method. +func (m *MockEarth[R]) Water(arg0 R) []R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]R) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockEarthMockRecorder[R]) Water(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockEarth[R])(nil).Water), arg0) +} + +// MockWater is a mock of Water interface. +type MockWater[R any, C generics.UnsignedInteger] struct { + ctrl *gomock.Controller + recorder *MockWaterMockRecorder[R, C] +} + +// MockWaterMockRecorder is the mock recorder for MockWater. +type MockWaterMockRecorder[R any, C generics.UnsignedInteger] struct { + mock *MockWater[R, C] +} + +// NewMockWater creates a new mock instance. +func NewMockWater[R any, C generics.UnsignedInteger](ctrl *gomock.Controller) *MockWater[R, C] { + mock := &MockWater[R, C]{ctrl: ctrl} + mock.recorder = &MockWaterMockRecorder[R, C]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockWater[R, C]) EXPECT() *MockWaterMockRecorder[R, C] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockWater[R, C]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Fish mocks base method. +func (m *MockWater[R, C]) Fish(arg0 R) []C { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Fish", arg0) + ret0, _ := ret[0].([]C) + return ret0 +} + +// Fish indicates an expected call of Fish. +func (mr *MockWaterMockRecorder[R, C]) Fish(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fish", reflect.TypeOf((*MockWater[R, C])(nil).Fish), arg0) +} diff --git a/mockgen/internal/tests/import_mode/guns/guns.go b/mockgen/internal/tests/import_mode/guns/guns.go new file mode 100644 index 0000000..4f62927 --- /dev/null +++ b/mockgen/internal/tests/import_mode/guns/guns.go @@ -0,0 +1,49 @@ +package guns + +import ( + "go.uber.org/mock/mockgen/internal/tests/import_mode/projectiles" +) + +type Rifle struct { + ammoSize int +} + +func (r *Rifle) Shoot(times int) []projectiles.Bullet { + currentAmmo := r.ammoSize + r.ammoSize = min(0, currentAmmo-times) + + return make([]projectiles.Bullet, min(currentAmmo, times)) +} + +func (r *Rifle) Ammo() int { + return r.ammoSize +} + +type RocketLauncher struct { + loaded bool +} + +func (r *RocketLauncher) Shoot(times int) []projectiles.Missle { + if r.loaded { + r.loaded = false + return make([]projectiles.Missle, 1) + } + + return nil +} + +func (r *RocketLauncher) Ammo() int { + if r.loaded { + return 1 + } + + return 0 +} + +func min(a, b int) int { + if a < b { + return a + } + + return b +} diff --git a/mockgen/internal/tests/import_mode/interfaces.go b/mockgen/internal/tests/import_mode/interfaces.go new file mode 100644 index 0000000..75271b5 --- /dev/null +++ b/mockgen/internal/tests/import_mode/interfaces.go @@ -0,0 +1,74 @@ +package import_mode + +// This package is used for unit testing of import_mode.go. +// All the entities described here are inspired by the video game Helldivers 2 + +//go:generate mockgen -typed -package=mock -destination=mock/interfaces.go . DemocracyFan,SuperEarthCitizen,Projectile,Gun,Shooter,HelldiverRifleShooter,HelldiverRocketMan,PotentialTraitor,AgitationCampaign + +import ( + "go.uber.org/mock/mockgen/internal/tests/import_mode/guns" + "go.uber.org/mock/mockgen/internal/tests/import_mode/projectiles" + . "go.uber.org/mock/mockgen/internal/tests/import_mode/stratagems" +) + +type DemocracyFan interface { + ILoveDemocracy() + YouWillNeverDestroyOurWayOfLife() +} + +type SuperEarthCitizen DemocracyFan + +type Projectile interface { + Speed() int + FlightRange() int + Explosive() bool +} + +type Gun[ProjectileType Projectile] interface { + Shoot(times int) []ProjectileType + Ammo() int +} + +type Shooter[ProjectileType Projectile, GunType Gun[ProjectileType]] interface { + Gun() GunType + Shoot(times int, targets ...*Enemy) (bool, error) + Reload() bool +} + +type Helldiver interface { + DemocracyFan + StratagemCarrier +} + +type HelldiverRifleShooter interface { + Helldiver + Shooter[projectiles.Bullet, *guns.Rifle] +} + +type HelldiverRocketMan interface { + Helldiver + Shooter[projectiles.Missle, *guns.RocketLauncher] +} + +type PotentialTraitor interface { + StratagemCarrier + Shooter[projectiles.Bullet, *guns.Rifle] +} + +type AgitationCampaign interface { + interface { + BecomeAHero() + BecomeALegend() + BecomeAHelldiver() + } +} + +type Enemy struct { + Name string + Fraction string + Hp int +} + +type Counter interface { + int +} diff --git a/mockgen/internal/tests/import_mode/mock/interfaces.go b/mockgen/internal/tests/import_mode/mock/interfaces.go new file mode 100644 index 0000000..9687585 --- /dev/null +++ b/mockgen/internal/tests/import_mode/mock/interfaces.go @@ -0,0 +1,1451 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: go.uber.org/mock/mockgen/internal/tests/import_mode (interfaces: DemocracyFan,SuperEarthCitizen,Projectile,Gun,Shooter,HelldiverRifleShooter,HelldiverRocketMan,PotentialTraitor,AgitationCampaign) +// +// Generated by this command: +// +// mockgen -typed -package=mock -destination=mock/interfaces.go . DemocracyFan,SuperEarthCitizen,Projectile,Gun,Shooter,HelldiverRifleShooter,HelldiverRocketMan,PotentialTraitor,AgitationCampaign +// + +// Package mock is a generated GoMock package. +package mock + +import ( + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + import_mode "go.uber.org/mock/mockgen/internal/tests/import_mode" + guns "go.uber.org/mock/mockgen/internal/tests/import_mode/guns" + stratagems "go.uber.org/mock/mockgen/internal/tests/import_mode/stratagems" +) + +// MockDemocracyFan is a mock of DemocracyFan interface. +type MockDemocracyFan struct { + ctrl *gomock.Controller + recorder *MockDemocracyFanMockRecorder +} + +// MockDemocracyFanMockRecorder is the mock recorder for MockDemocracyFan. +type MockDemocracyFanMockRecorder struct { + mock *MockDemocracyFan +} + +// NewMockDemocracyFan creates a new mock instance. +func NewMockDemocracyFan(ctrl *gomock.Controller) *MockDemocracyFan { + mock := &MockDemocracyFan{ctrl: ctrl} + mock.recorder = &MockDemocracyFanMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockDemocracyFan) EXPECT() *MockDemocracyFanMockRecorder { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockDemocracyFan) ISGOMOCK() struct{} { + return struct{}{} +} + +// ILoveDemocracy mocks base method. +func (m *MockDemocracyFan) ILoveDemocracy() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "ILoveDemocracy") +} + +// ILoveDemocracy indicates an expected call of ILoveDemocracy. +func (mr *MockDemocracyFanMockRecorder) ILoveDemocracy() *MockDemocracyFanILoveDemocracyCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ILoveDemocracy", reflect.TypeOf((*MockDemocracyFan)(nil).ILoveDemocracy)) + return &MockDemocracyFanILoveDemocracyCall{Call: call} +} + +// MockDemocracyFanILoveDemocracyCall wrap *gomock.Call +type MockDemocracyFanILoveDemocracyCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockDemocracyFanILoveDemocracyCall) Return() *MockDemocracyFanILoveDemocracyCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockDemocracyFanILoveDemocracyCall) Do(f func()) *MockDemocracyFanILoveDemocracyCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockDemocracyFanILoveDemocracyCall) DoAndReturn(f func()) *MockDemocracyFanILoveDemocracyCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// YouWillNeverDestroyOurWayOfLife mocks base method. +func (m *MockDemocracyFan) YouWillNeverDestroyOurWayOfLife() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "YouWillNeverDestroyOurWayOfLife") +} + +// YouWillNeverDestroyOurWayOfLife indicates an expected call of YouWillNeverDestroyOurWayOfLife. +func (mr *MockDemocracyFanMockRecorder) YouWillNeverDestroyOurWayOfLife() *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "YouWillNeverDestroyOurWayOfLife", reflect.TypeOf((*MockDemocracyFan)(nil).YouWillNeverDestroyOurWayOfLife)) + return &MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall{Call: call} +} + +// MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall wrap *gomock.Call +type MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall) Return() *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall) Do(f func()) *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall) DoAndReturn(f func()) *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// MockSuperEarthCitizen is a mock of SuperEarthCitizen interface. +type MockSuperEarthCitizen struct { + ctrl *gomock.Controller + recorder *MockSuperEarthCitizenMockRecorder +} + +// MockSuperEarthCitizenMockRecorder is the mock recorder for MockSuperEarthCitizen. +type MockSuperEarthCitizenMockRecorder struct { + mock *MockSuperEarthCitizen +} + +// NewMockSuperEarthCitizen creates a new mock instance. +func NewMockSuperEarthCitizen(ctrl *gomock.Controller) *MockSuperEarthCitizen { + mock := &MockSuperEarthCitizen{ctrl: ctrl} + mock.recorder = &MockSuperEarthCitizenMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockSuperEarthCitizen) EXPECT() *MockSuperEarthCitizenMockRecorder { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockSuperEarthCitizen) ISGOMOCK() struct{} { + return struct{}{} +} + +// ILoveDemocracy mocks base method. +func (m *MockSuperEarthCitizen) ILoveDemocracy() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "ILoveDemocracy") +} + +// ILoveDemocracy indicates an expected call of ILoveDemocracy. +func (mr *MockSuperEarthCitizenMockRecorder) ILoveDemocracy() *MockSuperEarthCitizenILoveDemocracyCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ILoveDemocracy", reflect.TypeOf((*MockSuperEarthCitizen)(nil).ILoveDemocracy)) + return &MockSuperEarthCitizenILoveDemocracyCall{Call: call} +} + +// MockSuperEarthCitizenILoveDemocracyCall wrap *gomock.Call +type MockSuperEarthCitizenILoveDemocracyCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSuperEarthCitizenILoveDemocracyCall) Return() *MockSuperEarthCitizenILoveDemocracyCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSuperEarthCitizenILoveDemocracyCall) Do(f func()) *MockSuperEarthCitizenILoveDemocracyCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSuperEarthCitizenILoveDemocracyCall) DoAndReturn(f func()) *MockSuperEarthCitizenILoveDemocracyCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// YouWillNeverDestroyOurWayOfLife mocks base method. +func (m *MockSuperEarthCitizen) YouWillNeverDestroyOurWayOfLife() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "YouWillNeverDestroyOurWayOfLife") +} + +// YouWillNeverDestroyOurWayOfLife indicates an expected call of YouWillNeverDestroyOurWayOfLife. +func (mr *MockSuperEarthCitizenMockRecorder) YouWillNeverDestroyOurWayOfLife() *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "YouWillNeverDestroyOurWayOfLife", reflect.TypeOf((*MockSuperEarthCitizen)(nil).YouWillNeverDestroyOurWayOfLife)) + return &MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall{Call: call} +} + +// MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall wrap *gomock.Call +type MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall) Return() *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall) Do(f func()) *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall) DoAndReturn(f func()) *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// MockProjectile is a mock of Projectile interface. +type MockProjectile struct { + ctrl *gomock.Controller + recorder *MockProjectileMockRecorder +} + +// MockProjectileMockRecorder is the mock recorder for MockProjectile. +type MockProjectileMockRecorder struct { + mock *MockProjectile +} + +// NewMockProjectile creates a new mock instance. +func NewMockProjectile(ctrl *gomock.Controller) *MockProjectile { + mock := &MockProjectile{ctrl: ctrl} + mock.recorder = &MockProjectileMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockProjectile) EXPECT() *MockProjectileMockRecorder { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockProjectile) ISGOMOCK() struct{} { + return struct{}{} +} + +// Explosive mocks base method. +func (m *MockProjectile) Explosive() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Explosive") + ret0, _ := ret[0].(bool) + return ret0 +} + +// Explosive indicates an expected call of Explosive. +func (mr *MockProjectileMockRecorder) Explosive() *MockProjectileExplosiveCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Explosive", reflect.TypeOf((*MockProjectile)(nil).Explosive)) + return &MockProjectileExplosiveCall{Call: call} +} + +// MockProjectileExplosiveCall wrap *gomock.Call +type MockProjectileExplosiveCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockProjectileExplosiveCall) Return(arg0 bool) *MockProjectileExplosiveCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockProjectileExplosiveCall) Do(f func() bool) *MockProjectileExplosiveCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockProjectileExplosiveCall) DoAndReturn(f func() bool) *MockProjectileExplosiveCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// FlightRange mocks base method. +func (m *MockProjectile) FlightRange() int { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "FlightRange") + ret0, _ := ret[0].(int) + return ret0 +} + +// FlightRange indicates an expected call of FlightRange. +func (mr *MockProjectileMockRecorder) FlightRange() *MockProjectileFlightRangeCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FlightRange", reflect.TypeOf((*MockProjectile)(nil).FlightRange)) + return &MockProjectileFlightRangeCall{Call: call} +} + +// MockProjectileFlightRangeCall wrap *gomock.Call +type MockProjectileFlightRangeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockProjectileFlightRangeCall) Return(arg0 int) *MockProjectileFlightRangeCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockProjectileFlightRangeCall) Do(f func() int) *MockProjectileFlightRangeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockProjectileFlightRangeCall) DoAndReturn(f func() int) *MockProjectileFlightRangeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Speed mocks base method. +func (m *MockProjectile) Speed() int { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Speed") + ret0, _ := ret[0].(int) + return ret0 +} + +// Speed indicates an expected call of Speed. +func (mr *MockProjectileMockRecorder) Speed() *MockProjectileSpeedCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Speed", reflect.TypeOf((*MockProjectile)(nil).Speed)) + return &MockProjectileSpeedCall{Call: call} +} + +// MockProjectileSpeedCall wrap *gomock.Call +type MockProjectileSpeedCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockProjectileSpeedCall) Return(arg0 int) *MockProjectileSpeedCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockProjectileSpeedCall) Do(f func() int) *MockProjectileSpeedCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockProjectileSpeedCall) DoAndReturn(f func() int) *MockProjectileSpeedCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// MockGun is a mock of Gun interface. +type MockGun[ProjectileType import_mode.Projectile] struct { + ctrl *gomock.Controller + recorder *MockGunMockRecorder[ProjectileType] +} + +// MockGunMockRecorder is the mock recorder for MockGun. +type MockGunMockRecorder[ProjectileType import_mode.Projectile] struct { + mock *MockGun[ProjectileType] +} + +// NewMockGun creates a new mock instance. +func NewMockGun[ProjectileType import_mode.Projectile](ctrl *gomock.Controller) *MockGun[ProjectileType] { + mock := &MockGun[ProjectileType]{ctrl: ctrl} + mock.recorder = &MockGunMockRecorder[ProjectileType]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGun[ProjectileType]) EXPECT() *MockGunMockRecorder[ProjectileType] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockGun[ProjectileType]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Ammo mocks base method. +func (m *MockGun[ProjectileType]) Ammo() int { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Ammo") + ret0, _ := ret[0].(int) + return ret0 +} + +// Ammo indicates an expected call of Ammo. +func (mr *MockGunMockRecorder[ProjectileType]) Ammo() *MockGunAmmoCall[ProjectileType] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ammo", reflect.TypeOf((*MockGun[ProjectileType])(nil).Ammo)) + return &MockGunAmmoCall[ProjectileType]{Call: call} +} + +// MockGunAmmoCall wrap *gomock.Call +type MockGunAmmoCall[ProjectileType import_mode.Projectile] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockGunAmmoCall[ProjectileType]) Return(arg0 int) *MockGunAmmoCall[ProjectileType] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockGunAmmoCall[ProjectileType]) Do(f func() int) *MockGunAmmoCall[ProjectileType] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockGunAmmoCall[ProjectileType]) DoAndReturn(f func() int) *MockGunAmmoCall[ProjectileType] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Shoot mocks base method. +func (m *MockGun[ProjectileType]) Shoot(times int) []ProjectileType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Shoot", times) + ret0, _ := ret[0].([]ProjectileType) + return ret0 +} + +// Shoot indicates an expected call of Shoot. +func (mr *MockGunMockRecorder[ProjectileType]) Shoot(times any) *MockGunShootCall[ProjectileType] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shoot", reflect.TypeOf((*MockGun[ProjectileType])(nil).Shoot), times) + return &MockGunShootCall[ProjectileType]{Call: call} +} + +// MockGunShootCall wrap *gomock.Call +type MockGunShootCall[ProjectileType import_mode.Projectile] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockGunShootCall[ProjectileType]) Return(arg0 []ProjectileType) *MockGunShootCall[ProjectileType] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockGunShootCall[ProjectileType]) Do(f func(int) []ProjectileType) *MockGunShootCall[ProjectileType] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockGunShootCall[ProjectileType]) DoAndReturn(f func(int) []ProjectileType) *MockGunShootCall[ProjectileType] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// MockShooter is a mock of Shooter interface. +type MockShooter[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]] struct { + ctrl *gomock.Controller + recorder *MockShooterMockRecorder[ProjectileType, GunType] +} + +// MockShooterMockRecorder is the mock recorder for MockShooter. +type MockShooterMockRecorder[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]] struct { + mock *MockShooter[ProjectileType, GunType] +} + +// NewMockShooter creates a new mock instance. +func NewMockShooter[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]](ctrl *gomock.Controller) *MockShooter[ProjectileType, GunType] { + mock := &MockShooter[ProjectileType, GunType]{ctrl: ctrl} + mock.recorder = &MockShooterMockRecorder[ProjectileType, GunType]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockShooter[ProjectileType, GunType]) EXPECT() *MockShooterMockRecorder[ProjectileType, GunType] { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockShooter[ProjectileType, GunType]) ISGOMOCK() struct{} { + return struct{}{} +} + +// Gun mocks base method. +func (m *MockShooter[ProjectileType, GunType]) Gun() GunType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Gun") + ret0, _ := ret[0].(GunType) + return ret0 +} + +// Gun indicates an expected call of Gun. +func (mr *MockShooterMockRecorder[ProjectileType, GunType]) Gun() *MockShooterGunCall[ProjectileType, GunType] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Gun", reflect.TypeOf((*MockShooter[ProjectileType, GunType])(nil).Gun)) + return &MockShooterGunCall[ProjectileType, GunType]{Call: call} +} + +// MockShooterGunCall wrap *gomock.Call +type MockShooterGunCall[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockShooterGunCall[ProjectileType, GunType]) Return(arg0 GunType) *MockShooterGunCall[ProjectileType, GunType] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockShooterGunCall[ProjectileType, GunType]) Do(f func() GunType) *MockShooterGunCall[ProjectileType, GunType] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockShooterGunCall[ProjectileType, GunType]) DoAndReturn(f func() GunType) *MockShooterGunCall[ProjectileType, GunType] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Reload mocks base method. +func (m *MockShooter[ProjectileType, GunType]) Reload() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Reload") + ret0, _ := ret[0].(bool) + return ret0 +} + +// Reload indicates an expected call of Reload. +func (mr *MockShooterMockRecorder[ProjectileType, GunType]) Reload() *MockShooterReloadCall[ProjectileType, GunType] { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reload", reflect.TypeOf((*MockShooter[ProjectileType, GunType])(nil).Reload)) + return &MockShooterReloadCall[ProjectileType, GunType]{Call: call} +} + +// MockShooterReloadCall wrap *gomock.Call +type MockShooterReloadCall[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockShooterReloadCall[ProjectileType, GunType]) Return(arg0 bool) *MockShooterReloadCall[ProjectileType, GunType] { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockShooterReloadCall[ProjectileType, GunType]) Do(f func() bool) *MockShooterReloadCall[ProjectileType, GunType] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockShooterReloadCall[ProjectileType, GunType]) DoAndReturn(f func() bool) *MockShooterReloadCall[ProjectileType, GunType] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Shoot mocks base method. +func (m *MockShooter[ProjectileType, GunType]) Shoot(times int, targets ...*import_mode.Enemy) (bool, error) { + m.ctrl.T.Helper() + varargs := []any{times} + for _, a := range targets { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Shoot", varargs...) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Shoot indicates an expected call of Shoot. +func (mr *MockShooterMockRecorder[ProjectileType, GunType]) Shoot(times any, targets ...any) *MockShooterShootCall[ProjectileType, GunType] { + mr.mock.ctrl.T.Helper() + varargs := append([]any{times}, targets...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shoot", reflect.TypeOf((*MockShooter[ProjectileType, GunType])(nil).Shoot), varargs...) + return &MockShooterShootCall[ProjectileType, GunType]{Call: call} +} + +// MockShooterShootCall wrap *gomock.Call +type MockShooterShootCall[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]] struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockShooterShootCall[ProjectileType, GunType]) Return(arg0 bool, arg1 error) *MockShooterShootCall[ProjectileType, GunType] { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockShooterShootCall[ProjectileType, GunType]) Do(f func(int, ...*import_mode.Enemy) (bool, error)) *MockShooterShootCall[ProjectileType, GunType] { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockShooterShootCall[ProjectileType, GunType]) DoAndReturn(f func(int, ...*import_mode.Enemy) (bool, error)) *MockShooterShootCall[ProjectileType, GunType] { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// MockHelldiverRifleShooter is a mock of HelldiverRifleShooter interface. +type MockHelldiverRifleShooter struct { + ctrl *gomock.Controller + recorder *MockHelldiverRifleShooterMockRecorder +} + +// MockHelldiverRifleShooterMockRecorder is the mock recorder for MockHelldiverRifleShooter. +type MockHelldiverRifleShooterMockRecorder struct { + mock *MockHelldiverRifleShooter +} + +// NewMockHelldiverRifleShooter creates a new mock instance. +func NewMockHelldiverRifleShooter(ctrl *gomock.Controller) *MockHelldiverRifleShooter { + mock := &MockHelldiverRifleShooter{ctrl: ctrl} + mock.recorder = &MockHelldiverRifleShooterMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockHelldiverRifleShooter) EXPECT() *MockHelldiverRifleShooterMockRecorder { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockHelldiverRifleShooter) ISGOMOCK() struct{} { + return struct{}{} +} + +// AvailableStratagems mocks base method. +func (m *MockHelldiverRifleShooter) AvailableStratagems() []stratagems.Stratagem { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AvailableStratagems") + ret0, _ := ret[0].([]stratagems.Stratagem) + return ret0 +} + +// AvailableStratagems indicates an expected call of AvailableStratagems. +func (mr *MockHelldiverRifleShooterMockRecorder) AvailableStratagems() *MockHelldiverRifleShooterAvailableStratagemsCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AvailableStratagems", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).AvailableStratagems)) + return &MockHelldiverRifleShooterAvailableStratagemsCall{Call: call} +} + +// MockHelldiverRifleShooterAvailableStratagemsCall wrap *gomock.Call +type MockHelldiverRifleShooterAvailableStratagemsCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRifleShooterAvailableStratagemsCall) Return(arg0 []stratagems.Stratagem) *MockHelldiverRifleShooterAvailableStratagemsCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRifleShooterAvailableStratagemsCall) Do(f func() []stratagems.Stratagem) *MockHelldiverRifleShooterAvailableStratagemsCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRifleShooterAvailableStratagemsCall) DoAndReturn(f func() []stratagems.Stratagem) *MockHelldiverRifleShooterAvailableStratagemsCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Gun mocks base method. +func (m *MockHelldiverRifleShooter) Gun() *guns.Rifle { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Gun") + ret0, _ := ret[0].(*guns.Rifle) + return ret0 +} + +// Gun indicates an expected call of Gun. +func (mr *MockHelldiverRifleShooterMockRecorder) Gun() *MockHelldiverRifleShooterGunCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Gun", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).Gun)) + return &MockHelldiverRifleShooterGunCall{Call: call} +} + +// MockHelldiverRifleShooterGunCall wrap *gomock.Call +type MockHelldiverRifleShooterGunCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRifleShooterGunCall) Return(arg0 *guns.Rifle) *MockHelldiverRifleShooterGunCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRifleShooterGunCall) Do(f func() *guns.Rifle) *MockHelldiverRifleShooterGunCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRifleShooterGunCall) DoAndReturn(f func() *guns.Rifle) *MockHelldiverRifleShooterGunCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// ILoveDemocracy mocks base method. +func (m *MockHelldiverRifleShooter) ILoveDemocracy() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "ILoveDemocracy") +} + +// ILoveDemocracy indicates an expected call of ILoveDemocracy. +func (mr *MockHelldiverRifleShooterMockRecorder) ILoveDemocracy() *MockHelldiverRifleShooterILoveDemocracyCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ILoveDemocracy", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).ILoveDemocracy)) + return &MockHelldiverRifleShooterILoveDemocracyCall{Call: call} +} + +// MockHelldiverRifleShooterILoveDemocracyCall wrap *gomock.Call +type MockHelldiverRifleShooterILoveDemocracyCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRifleShooterILoveDemocracyCall) Return() *MockHelldiverRifleShooterILoveDemocracyCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRifleShooterILoveDemocracyCall) Do(f func()) *MockHelldiverRifleShooterILoveDemocracyCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRifleShooterILoveDemocracyCall) DoAndReturn(f func()) *MockHelldiverRifleShooterILoveDemocracyCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Reload mocks base method. +func (m *MockHelldiverRifleShooter) Reload() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Reload") + ret0, _ := ret[0].(bool) + return ret0 +} + +// Reload indicates an expected call of Reload. +func (mr *MockHelldiverRifleShooterMockRecorder) Reload() *MockHelldiverRifleShooterReloadCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reload", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).Reload)) + return &MockHelldiverRifleShooterReloadCall{Call: call} +} + +// MockHelldiverRifleShooterReloadCall wrap *gomock.Call +type MockHelldiverRifleShooterReloadCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRifleShooterReloadCall) Return(arg0 bool) *MockHelldiverRifleShooterReloadCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRifleShooterReloadCall) Do(f func() bool) *MockHelldiverRifleShooterReloadCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRifleShooterReloadCall) DoAndReturn(f func() bool) *MockHelldiverRifleShooterReloadCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Shoot mocks base method. +func (m *MockHelldiverRifleShooter) Shoot(times int, targets ...*import_mode.Enemy) (bool, error) { + m.ctrl.T.Helper() + varargs := []any{times} + for _, a := range targets { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Shoot", varargs...) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Shoot indicates an expected call of Shoot. +func (mr *MockHelldiverRifleShooterMockRecorder) Shoot(times any, targets ...any) *MockHelldiverRifleShooterShootCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{times}, targets...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shoot", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).Shoot), varargs...) + return &MockHelldiverRifleShooterShootCall{Call: call} +} + +// MockHelldiverRifleShooterShootCall wrap *gomock.Call +type MockHelldiverRifleShooterShootCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRifleShooterShootCall) Return(arg0 bool, arg1 error) *MockHelldiverRifleShooterShootCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRifleShooterShootCall) Do(f func(int, ...*import_mode.Enemy) (bool, error)) *MockHelldiverRifleShooterShootCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRifleShooterShootCall) DoAndReturn(f func(int, ...*import_mode.Enemy) (bool, error)) *MockHelldiverRifleShooterShootCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// YouWillNeverDestroyOurWayOfLife mocks base method. +func (m *MockHelldiverRifleShooter) YouWillNeverDestroyOurWayOfLife() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "YouWillNeverDestroyOurWayOfLife") +} + +// YouWillNeverDestroyOurWayOfLife indicates an expected call of YouWillNeverDestroyOurWayOfLife. +func (mr *MockHelldiverRifleShooterMockRecorder) YouWillNeverDestroyOurWayOfLife() *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "YouWillNeverDestroyOurWayOfLife", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).YouWillNeverDestroyOurWayOfLife)) + return &MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall{Call: call} +} + +// MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall wrap *gomock.Call +type MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall) Return() *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall) Do(f func()) *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall) DoAndReturn(f func()) *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// MockHelldiverRocketMan is a mock of HelldiverRocketMan interface. +type MockHelldiverRocketMan struct { + ctrl *gomock.Controller + recorder *MockHelldiverRocketManMockRecorder +} + +// MockHelldiverRocketManMockRecorder is the mock recorder for MockHelldiverRocketMan. +type MockHelldiverRocketManMockRecorder struct { + mock *MockHelldiverRocketMan +} + +// NewMockHelldiverRocketMan creates a new mock instance. +func NewMockHelldiverRocketMan(ctrl *gomock.Controller) *MockHelldiverRocketMan { + mock := &MockHelldiverRocketMan{ctrl: ctrl} + mock.recorder = &MockHelldiverRocketManMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockHelldiverRocketMan) EXPECT() *MockHelldiverRocketManMockRecorder { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockHelldiverRocketMan) ISGOMOCK() struct{} { + return struct{}{} +} + +// AvailableStratagems mocks base method. +func (m *MockHelldiverRocketMan) AvailableStratagems() []stratagems.Stratagem { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AvailableStratagems") + ret0, _ := ret[0].([]stratagems.Stratagem) + return ret0 +} + +// AvailableStratagems indicates an expected call of AvailableStratagems. +func (mr *MockHelldiverRocketManMockRecorder) AvailableStratagems() *MockHelldiverRocketManAvailableStratagemsCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AvailableStratagems", reflect.TypeOf((*MockHelldiverRocketMan)(nil).AvailableStratagems)) + return &MockHelldiverRocketManAvailableStratagemsCall{Call: call} +} + +// MockHelldiverRocketManAvailableStratagemsCall wrap *gomock.Call +type MockHelldiverRocketManAvailableStratagemsCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRocketManAvailableStratagemsCall) Return(arg0 []stratagems.Stratagem) *MockHelldiverRocketManAvailableStratagemsCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRocketManAvailableStratagemsCall) Do(f func() []stratagems.Stratagem) *MockHelldiverRocketManAvailableStratagemsCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRocketManAvailableStratagemsCall) DoAndReturn(f func() []stratagems.Stratagem) *MockHelldiverRocketManAvailableStratagemsCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Gun mocks base method. +func (m *MockHelldiverRocketMan) Gun() *guns.RocketLauncher { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Gun") + ret0, _ := ret[0].(*guns.RocketLauncher) + return ret0 +} + +// Gun indicates an expected call of Gun. +func (mr *MockHelldiverRocketManMockRecorder) Gun() *MockHelldiverRocketManGunCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Gun", reflect.TypeOf((*MockHelldiverRocketMan)(nil).Gun)) + return &MockHelldiverRocketManGunCall{Call: call} +} + +// MockHelldiverRocketManGunCall wrap *gomock.Call +type MockHelldiverRocketManGunCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRocketManGunCall) Return(arg0 *guns.RocketLauncher) *MockHelldiverRocketManGunCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRocketManGunCall) Do(f func() *guns.RocketLauncher) *MockHelldiverRocketManGunCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRocketManGunCall) DoAndReturn(f func() *guns.RocketLauncher) *MockHelldiverRocketManGunCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// ILoveDemocracy mocks base method. +func (m *MockHelldiverRocketMan) ILoveDemocracy() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "ILoveDemocracy") +} + +// ILoveDemocracy indicates an expected call of ILoveDemocracy. +func (mr *MockHelldiverRocketManMockRecorder) ILoveDemocracy() *MockHelldiverRocketManILoveDemocracyCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ILoveDemocracy", reflect.TypeOf((*MockHelldiverRocketMan)(nil).ILoveDemocracy)) + return &MockHelldiverRocketManILoveDemocracyCall{Call: call} +} + +// MockHelldiverRocketManILoveDemocracyCall wrap *gomock.Call +type MockHelldiverRocketManILoveDemocracyCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRocketManILoveDemocracyCall) Return() *MockHelldiverRocketManILoveDemocracyCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRocketManILoveDemocracyCall) Do(f func()) *MockHelldiverRocketManILoveDemocracyCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRocketManILoveDemocracyCall) DoAndReturn(f func()) *MockHelldiverRocketManILoveDemocracyCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Reload mocks base method. +func (m *MockHelldiverRocketMan) Reload() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Reload") + ret0, _ := ret[0].(bool) + return ret0 +} + +// Reload indicates an expected call of Reload. +func (mr *MockHelldiverRocketManMockRecorder) Reload() *MockHelldiverRocketManReloadCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reload", reflect.TypeOf((*MockHelldiverRocketMan)(nil).Reload)) + return &MockHelldiverRocketManReloadCall{Call: call} +} + +// MockHelldiverRocketManReloadCall wrap *gomock.Call +type MockHelldiverRocketManReloadCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRocketManReloadCall) Return(arg0 bool) *MockHelldiverRocketManReloadCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRocketManReloadCall) Do(f func() bool) *MockHelldiverRocketManReloadCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRocketManReloadCall) DoAndReturn(f func() bool) *MockHelldiverRocketManReloadCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Shoot mocks base method. +func (m *MockHelldiverRocketMan) Shoot(times int, targets ...*import_mode.Enemy) (bool, error) { + m.ctrl.T.Helper() + varargs := []any{times} + for _, a := range targets { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Shoot", varargs...) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Shoot indicates an expected call of Shoot. +func (mr *MockHelldiverRocketManMockRecorder) Shoot(times any, targets ...any) *MockHelldiverRocketManShootCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{times}, targets...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shoot", reflect.TypeOf((*MockHelldiverRocketMan)(nil).Shoot), varargs...) + return &MockHelldiverRocketManShootCall{Call: call} +} + +// MockHelldiverRocketManShootCall wrap *gomock.Call +type MockHelldiverRocketManShootCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRocketManShootCall) Return(arg0 bool, arg1 error) *MockHelldiverRocketManShootCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRocketManShootCall) Do(f func(int, ...*import_mode.Enemy) (bool, error)) *MockHelldiverRocketManShootCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRocketManShootCall) DoAndReturn(f func(int, ...*import_mode.Enemy) (bool, error)) *MockHelldiverRocketManShootCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// YouWillNeverDestroyOurWayOfLife mocks base method. +func (m *MockHelldiverRocketMan) YouWillNeverDestroyOurWayOfLife() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "YouWillNeverDestroyOurWayOfLife") +} + +// YouWillNeverDestroyOurWayOfLife indicates an expected call of YouWillNeverDestroyOurWayOfLife. +func (mr *MockHelldiverRocketManMockRecorder) YouWillNeverDestroyOurWayOfLife() *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "YouWillNeverDestroyOurWayOfLife", reflect.TypeOf((*MockHelldiverRocketMan)(nil).YouWillNeverDestroyOurWayOfLife)) + return &MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall{Call: call} +} + +// MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall wrap *gomock.Call +type MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall) Return() *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall) Do(f func()) *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall) DoAndReturn(f func()) *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// MockPotentialTraitor is a mock of PotentialTraitor interface. +type MockPotentialTraitor struct { + ctrl *gomock.Controller + recorder *MockPotentialTraitorMockRecorder +} + +// MockPotentialTraitorMockRecorder is the mock recorder for MockPotentialTraitor. +type MockPotentialTraitorMockRecorder struct { + mock *MockPotentialTraitor +} + +// NewMockPotentialTraitor creates a new mock instance. +func NewMockPotentialTraitor(ctrl *gomock.Controller) *MockPotentialTraitor { + mock := &MockPotentialTraitor{ctrl: ctrl} + mock.recorder = &MockPotentialTraitorMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockPotentialTraitor) EXPECT() *MockPotentialTraitorMockRecorder { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockPotentialTraitor) ISGOMOCK() struct{} { + return struct{}{} +} + +// AvailableStratagems mocks base method. +func (m *MockPotentialTraitor) AvailableStratagems() []stratagems.Stratagem { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AvailableStratagems") + ret0, _ := ret[0].([]stratagems.Stratagem) + return ret0 +} + +// AvailableStratagems indicates an expected call of AvailableStratagems. +func (mr *MockPotentialTraitorMockRecorder) AvailableStratagems() *MockPotentialTraitorAvailableStratagemsCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AvailableStratagems", reflect.TypeOf((*MockPotentialTraitor)(nil).AvailableStratagems)) + return &MockPotentialTraitorAvailableStratagemsCall{Call: call} +} + +// MockPotentialTraitorAvailableStratagemsCall wrap *gomock.Call +type MockPotentialTraitorAvailableStratagemsCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPotentialTraitorAvailableStratagemsCall) Return(arg0 []stratagems.Stratagem) *MockPotentialTraitorAvailableStratagemsCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPotentialTraitorAvailableStratagemsCall) Do(f func() []stratagems.Stratagem) *MockPotentialTraitorAvailableStratagemsCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPotentialTraitorAvailableStratagemsCall) DoAndReturn(f func() []stratagems.Stratagem) *MockPotentialTraitorAvailableStratagemsCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Gun mocks base method. +func (m *MockPotentialTraitor) Gun() *guns.Rifle { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Gun") + ret0, _ := ret[0].(*guns.Rifle) + return ret0 +} + +// Gun indicates an expected call of Gun. +func (mr *MockPotentialTraitorMockRecorder) Gun() *MockPotentialTraitorGunCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Gun", reflect.TypeOf((*MockPotentialTraitor)(nil).Gun)) + return &MockPotentialTraitorGunCall{Call: call} +} + +// MockPotentialTraitorGunCall wrap *gomock.Call +type MockPotentialTraitorGunCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPotentialTraitorGunCall) Return(arg0 *guns.Rifle) *MockPotentialTraitorGunCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPotentialTraitorGunCall) Do(f func() *guns.Rifle) *MockPotentialTraitorGunCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPotentialTraitorGunCall) DoAndReturn(f func() *guns.Rifle) *MockPotentialTraitorGunCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Reload mocks base method. +func (m *MockPotentialTraitor) Reload() bool { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Reload") + ret0, _ := ret[0].(bool) + return ret0 +} + +// Reload indicates an expected call of Reload. +func (mr *MockPotentialTraitorMockRecorder) Reload() *MockPotentialTraitorReloadCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reload", reflect.TypeOf((*MockPotentialTraitor)(nil).Reload)) + return &MockPotentialTraitorReloadCall{Call: call} +} + +// MockPotentialTraitorReloadCall wrap *gomock.Call +type MockPotentialTraitorReloadCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPotentialTraitorReloadCall) Return(arg0 bool) *MockPotentialTraitorReloadCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPotentialTraitorReloadCall) Do(f func() bool) *MockPotentialTraitorReloadCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPotentialTraitorReloadCall) DoAndReturn(f func() bool) *MockPotentialTraitorReloadCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Shoot mocks base method. +func (m *MockPotentialTraitor) Shoot(times int, targets ...*import_mode.Enemy) (bool, error) { + m.ctrl.T.Helper() + varargs := []any{times} + for _, a := range targets { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Shoot", varargs...) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Shoot indicates an expected call of Shoot. +func (mr *MockPotentialTraitorMockRecorder) Shoot(times any, targets ...any) *MockPotentialTraitorShootCall { + mr.mock.ctrl.T.Helper() + varargs := append([]any{times}, targets...) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shoot", reflect.TypeOf((*MockPotentialTraitor)(nil).Shoot), varargs...) + return &MockPotentialTraitorShootCall{Call: call} +} + +// MockPotentialTraitorShootCall wrap *gomock.Call +type MockPotentialTraitorShootCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockPotentialTraitorShootCall) Return(arg0 bool, arg1 error) *MockPotentialTraitorShootCall { + c.Call = c.Call.Return(arg0, arg1) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockPotentialTraitorShootCall) Do(f func(int, ...*import_mode.Enemy) (bool, error)) *MockPotentialTraitorShootCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockPotentialTraitorShootCall) DoAndReturn(f func(int, ...*import_mode.Enemy) (bool, error)) *MockPotentialTraitorShootCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// MockAgitationCampaign is a mock of AgitationCampaign interface. +type MockAgitationCampaign struct { + ctrl *gomock.Controller + recorder *MockAgitationCampaignMockRecorder +} + +// MockAgitationCampaignMockRecorder is the mock recorder for MockAgitationCampaign. +type MockAgitationCampaignMockRecorder struct { + mock *MockAgitationCampaign +} + +// NewMockAgitationCampaign creates a new mock instance. +func NewMockAgitationCampaign(ctrl *gomock.Controller) *MockAgitationCampaign { + mock := &MockAgitationCampaign{ctrl: ctrl} + mock.recorder = &MockAgitationCampaignMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockAgitationCampaign) EXPECT() *MockAgitationCampaignMockRecorder { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockAgitationCampaign) ISGOMOCK() struct{} { + return struct{}{} +} + +// BecomeAHelldiver mocks base method. +func (m *MockAgitationCampaign) BecomeAHelldiver() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "BecomeAHelldiver") +} + +// BecomeAHelldiver indicates an expected call of BecomeAHelldiver. +func (mr *MockAgitationCampaignMockRecorder) BecomeAHelldiver() *MockAgitationCampaignBecomeAHelldiverCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BecomeAHelldiver", reflect.TypeOf((*MockAgitationCampaign)(nil).BecomeAHelldiver)) + return &MockAgitationCampaignBecomeAHelldiverCall{Call: call} +} + +// MockAgitationCampaignBecomeAHelldiverCall wrap *gomock.Call +type MockAgitationCampaignBecomeAHelldiverCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockAgitationCampaignBecomeAHelldiverCall) Return() *MockAgitationCampaignBecomeAHelldiverCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockAgitationCampaignBecomeAHelldiverCall) Do(f func()) *MockAgitationCampaignBecomeAHelldiverCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockAgitationCampaignBecomeAHelldiverCall) DoAndReturn(f func()) *MockAgitationCampaignBecomeAHelldiverCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// BecomeAHero mocks base method. +func (m *MockAgitationCampaign) BecomeAHero() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "BecomeAHero") +} + +// BecomeAHero indicates an expected call of BecomeAHero. +func (mr *MockAgitationCampaignMockRecorder) BecomeAHero() *MockAgitationCampaignBecomeAHeroCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BecomeAHero", reflect.TypeOf((*MockAgitationCampaign)(nil).BecomeAHero)) + return &MockAgitationCampaignBecomeAHeroCall{Call: call} +} + +// MockAgitationCampaignBecomeAHeroCall wrap *gomock.Call +type MockAgitationCampaignBecomeAHeroCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockAgitationCampaignBecomeAHeroCall) Return() *MockAgitationCampaignBecomeAHeroCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockAgitationCampaignBecomeAHeroCall) Do(f func()) *MockAgitationCampaignBecomeAHeroCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockAgitationCampaignBecomeAHeroCall) DoAndReturn(f func()) *MockAgitationCampaignBecomeAHeroCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// BecomeALegend mocks base method. +func (m *MockAgitationCampaign) BecomeALegend() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "BecomeALegend") +} + +// BecomeALegend indicates an expected call of BecomeALegend. +func (mr *MockAgitationCampaignMockRecorder) BecomeALegend() *MockAgitationCampaignBecomeALegendCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BecomeALegend", reflect.TypeOf((*MockAgitationCampaign)(nil).BecomeALegend)) + return &MockAgitationCampaignBecomeALegendCall{Call: call} +} + +// MockAgitationCampaignBecomeALegendCall wrap *gomock.Call +type MockAgitationCampaignBecomeALegendCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockAgitationCampaignBecomeALegendCall) Return() *MockAgitationCampaignBecomeALegendCall { + c.Call = c.Call.Return() + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockAgitationCampaignBecomeALegendCall) Do(f func()) *MockAgitationCampaignBecomeALegendCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockAgitationCampaignBecomeALegendCall) DoAndReturn(f func()) *MockAgitationCampaignBecomeALegendCall { + c.Call = c.Call.DoAndReturn(f) + return c +} diff --git a/mockgen/internal/tests/import_mode/projectiles/projectiles.go b/mockgen/internal/tests/import_mode/projectiles/projectiles.go new file mode 100644 index 0000000..5942230 --- /dev/null +++ b/mockgen/internal/tests/import_mode/projectiles/projectiles.go @@ -0,0 +1,30 @@ +package projectiles + +type Bullet struct{} + +func (b Bullet) Speed() int { + return 600 +} + +func (b Bullet) FlightRange() int { + return 500 +} + +func (b Bullet) Explosive() bool { + return false +} + +type Missle struct { +} + +func (m Missle) Speed() int { + return 200 +} + +func (m Missle) FlightRange() int { + return 800 +} + +func (m Missle) Explosive() bool { + return true +} diff --git a/mockgen/internal/tests/import_mode/stratagems/interfaces.go b/mockgen/internal/tests/import_mode/stratagems/interfaces.go new file mode 100644 index 0000000..65c6088 --- /dev/null +++ b/mockgen/internal/tests/import_mode/stratagems/interfaces.go @@ -0,0 +1,14 @@ +package stratagems + +import ( + "time" +) + +type Stratagem interface { + Call() error + Timeout() time.Duration +} + +type StratagemCarrier interface { + AvailableStratagems() []Stratagem +} diff --git a/mockgen/internal/tests/mock_name/mocks/post_service.go b/mockgen/internal/tests/mock_name/mocks/post_service.go index d1dcc6d..34fa0c7 100644 --- a/mockgen/internal/tests/mock_name/mocks/post_service.go +++ b/mockgen/internal/tests/mock_name/mocks/post_service.go @@ -46,18 +46,18 @@ func (m *PostServiceMock) ISGOMOCK() struct{} { } // Create mocks base method. -func (m *PostServiceMock) Create(arg0, arg1 string, arg2 *user.User) (*post.Post, error) { +func (m *PostServiceMock) Create(title, body string, author *user.User) (*post.Post, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Create", arg0, arg1, arg2) + ret := m.ctrl.Call(m, "Create", title, body, author) ret0, _ := ret[0].(*post.Post) ret1, _ := ret[1].(error) return ret0, ret1 } // Create indicates an expected call of Create. -func (mr *PostServiceMockMockRecorder) Create(arg0, arg1, arg2 any) *PostServiceMockCreateCall { +func (mr *PostServiceMockMockRecorder) Create(title, body, author any) *PostServiceMockCreateCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*PostServiceMock)(nil).Create), arg0, arg1, arg2) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*PostServiceMock)(nil).Create), title, body, author) return &PostServiceMockCreateCall{Call: call} } diff --git a/mockgen/internal/tests/mock_name/mocks/user_service.go b/mockgen/internal/tests/mock_name/mocks/user_service.go index 8842eae..02c06b5 100644 --- a/mockgen/internal/tests/mock_name/mocks/user_service.go +++ b/mockgen/internal/tests/mock_name/mocks/user_service.go @@ -45,18 +45,18 @@ func (m *UserServiceMock) ISGOMOCK() struct{} { } // Create mocks base method. -func (m *UserServiceMock) Create(arg0 string) (*user.User, error) { +func (m *UserServiceMock) Create(name string) (*user.User, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Create", arg0) + ret := m.ctrl.Call(m, "Create", name) ret0, _ := ret[0].(*user.User) ret1, _ := ret[1].(error) return ret0, ret1 } // Create indicates an expected call of Create. -func (mr *UserServiceMockMockRecorder) Create(arg0 any) *UserServiceMockCreateCall { +func (mr *UserServiceMockMockRecorder) Create(name any) *UserServiceMockCreateCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*UserServiceMock)(nil).Create), arg0) + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Create", reflect.TypeOf((*UserServiceMock)(nil).Create), name) return &UserServiceMockCreateCall{Call: call} } diff --git a/mockgen/internal/tests/sanitization/mockout/mock.go b/mockgen/internal/tests/sanitization/mockout/mock.go index 8e130b9..51dd274 100644 --- a/mockgen/internal/tests/sanitization/mockout/mock.go +++ b/mockgen/internal/tests/sanitization/mockout/mock.go @@ -45,13 +45,13 @@ func (m *MockAnyMock) ISGOMOCK() struct{} { } // Do mocks base method. -func (m *MockAnyMock) Do(arg0 *any0.Any, arg1 int) { +func (m *MockAnyMock) Do(a *any0.Any, b int) { m.ctrl.T.Helper() - m.ctrl.Call(m, "Do", arg0, arg1) + m.ctrl.Call(m, "Do", a, b) } // Do indicates an expected call of Do. -func (mr *MockAnyMockMockRecorder) Do(arg0, arg1 any) *gomock.Call { +func (mr *MockAnyMockMockRecorder) Do(a, b any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Do", reflect.TypeOf((*MockAnyMock)(nil).Do), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Do", reflect.TypeOf((*MockAnyMock)(nil).Do), a, b) } diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index 5d57868..ca5022d 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -104,7 +104,8 @@ func main() { log.Fatalf("Parse package name failed: %v", err) } } - pkg, err = reflectMode(packageName, interfaces) + parser := importModeParser{} + pkg, err = parser.parsePackage(packageName, interfaces) } if err != nil { log.Fatalf("Loading input failed: %v", err) diff --git a/mockgen/reflect.go b/mockgen/reflect.go deleted file mode 100644 index ca80ebb..0000000 --- a/mockgen/reflect.go +++ /dev/null @@ -1,256 +0,0 @@ -// Copyright 2012 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -// This file contains the model construction by reflection. - -import ( - "bytes" - "encoding/gob" - "flag" - "fmt" - "go/build" - "io" - "log" - "os" - "os/exec" - "path/filepath" - "runtime" - "strings" - "text/template" - - "go.uber.org/mock/mockgen/model" -) - -var ( - progOnly = flag.Bool("prog_only", false, "(reflect mode) Only generate the reflection program; write it to stdout and exit.") - execOnly = flag.String("exec_only", "", "(reflect mode) If set, execute this reflection program.") - buildFlags = flag.String("build_flags", "", "(reflect mode) Additional flags for go build.") -) - -// reflectMode generates mocks via reflection on an interface. -func reflectMode(importPath string, symbols []string) (*model.Package, error) { - if *execOnly != "" { - return run(*execOnly) - } - - program, err := writeProgram(importPath, symbols) - if err != nil { - return nil, err - } - - if *progOnly { - if _, err := os.Stdout.Write(program); err != nil { - return nil, err - } - os.Exit(0) - } - - wd, _ := os.Getwd() - - // Try to run the reflection program in the current working directory. - if p, err := runInDir(program, wd); err == nil { - return p, nil - } - - // Try to run the program in the same directory as the input package. - if p, err := build.Import(importPath, wd, build.FindOnly); err == nil { - dir := p.Dir - if p, err := runInDir(program, dir); err == nil { - return p, nil - } - } - - // Try to run it in a standard temp directory. - return runInDir(program, "") -} - -func writeProgram(importPath string, symbols []string) ([]byte, error) { - var program bytes.Buffer - data := reflectData{ - ImportPath: importPath, - Symbols: symbols, - } - if err := reflectProgram.Execute(&program, &data); err != nil { - return nil, err - } - return program.Bytes(), nil -} - -// run the given program and parse the output as a model.Package. -func run(program string) (*model.Package, error) { - f, err := os.CreateTemp("", "") - if err != nil { - return nil, err - } - - filename := f.Name() - defer os.Remove(filename) - if err := f.Close(); err != nil { - return nil, err - } - - // Run the program. - cmd := exec.Command(program, "-output", filename) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - if err := cmd.Run(); err != nil { - return nil, err - } - - f, err = os.Open(filename) - if err != nil { - return nil, err - } - - // Process output. - var pkg model.Package - if err := gob.NewDecoder(f).Decode(&pkg); err != nil { - return nil, err - } - - if err := f.Close(); err != nil { - return nil, err - } - - return &pkg, nil -} - -// runInDir writes the given program into the given dir, runs it there, and -// parses the output as a model.Package. -func runInDir(program []byte, dir string) (*model.Package, error) { - // We use TempDir instead of TempFile so we can control the filename. - tmpDir, err := os.MkdirTemp(dir, "gomock_reflect_") - if err != nil { - return nil, err - } - defer func() { - if err := os.RemoveAll(tmpDir); err != nil { - log.Printf("failed to remove temp directory: %s", err) - } - }() - const progSource = "prog.go" - var progBinary = "prog.bin" - if runtime.GOOS == "windows" { - // Windows won't execute a program unless it has a ".exe" suffix. - progBinary += ".exe" - } - - if err := os.WriteFile(filepath.Join(tmpDir, progSource), program, 0600); err != nil { - return nil, err - } - - cmdArgs := []string{} - cmdArgs = append(cmdArgs, "build") - if *buildFlags != "" { - cmdArgs = append(cmdArgs, strings.Split(*buildFlags, " ")...) - } - cmdArgs = append(cmdArgs, "-o", progBinary, progSource) - - // Build the program. - buf := bytes.NewBuffer(nil) - cmd := exec.Command("go", cmdArgs...) - cmd.Dir = tmpDir - cmd.Stdout = os.Stdout - cmd.Stderr = io.MultiWriter(os.Stderr, buf) - if err := cmd.Run(); err != nil { - sErr := buf.String() - if strings.Contains(sErr, `cannot find package "."`) && - strings.Contains(sErr, "go.uber.org/mock/mockgen/model") { - fmt.Fprint(os.Stderr, "Please reference the steps in the README to fix this error:\n\thttps://go.uber.org/mock#reflect-vendoring-error.\n") - return nil, err - } - return nil, err - } - - return run(filepath.Join(tmpDir, progBinary)) -} - -type reflectData struct { - ImportPath string - Symbols []string -} - -// This program reflects on an interface value, and prints the -// gob encoding of a model.Package to standard output. -// JSON doesn't work because of the model.Type interface. -var reflectProgram = template.Must(template.New("program").Parse(` -// Code generated by MockGen. DO NOT EDIT. -package main - -import ( - "encoding/gob" - "flag" - "fmt" - "os" - "path" - "reflect" - - "go.uber.org/mock/mockgen/model" - - pkg_ {{printf "%q" .ImportPath}} -) - -var output = flag.String("output", "", "The output file name, or empty to use stdout.") - -func main() { - flag.Parse() - - its := []struct{ - sym string - typ reflect.Type - }{ - {{range .Symbols}} - { {{printf "%q" .}}, reflect.TypeOf((*pkg_.{{.}})(nil)).Elem()}, - {{end}} - } - pkg := &model.Package{ - // NOTE: This behaves contrary to documented behaviour if the - // package name is not the final component of the import path. - // The reflect package doesn't expose the package name, though. - Name: path.Base({{printf "%q" .ImportPath}}), - } - - for _, it := range its { - intf, err := model.InterfaceFromInterfaceType(it.typ) - if err != nil { - fmt.Fprintf(os.Stderr, "Reflection: %v\n", err) - os.Exit(1) - } - intf.Name = it.sym - pkg.Interfaces = append(pkg.Interfaces, intf) - } - - outfile := os.Stdout - if len(*output) != 0 { - var err error - outfile, err = os.Create(*output) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to open output file %q", *output) - } - defer func() { - if err := outfile.Close(); err != nil { - fmt.Fprintf(os.Stderr, "failed to close output file %q", *output) - os.Exit(1) - } - }() - } - - if err := gob.NewEncoder(outfile).Encode(pkg); err != nil { - fmt.Fprintf(os.Stderr, "gob encode: %v\n", err) - os.Exit(1) - } -} -`)) diff --git a/sample/concurrent/mock/concurrent_mock.go b/sample/concurrent/mock/concurrent_mock.go index cc74e54..17c0862 100644 --- a/sample/concurrent/mock/concurrent_mock.go +++ b/sample/concurrent/mock/concurrent_mock.go @@ -44,15 +44,15 @@ func (m *MockMath) ISGOMOCK() struct{} { } // Sum mocks base method. -func (m *MockMath) Sum(arg0, arg1 int) int { +func (m *MockMath) Sum(a, b int) int { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Sum", arg0, arg1) + ret := m.ctrl.Call(m, "Sum", a, b) ret0, _ := ret[0].(int) return ret0 } // Sum indicates an expected call of Sum. -func (mr *MockMathMockRecorder) Sum(arg0, arg1 any) *gomock.Call { +func (mr *MockMathMockRecorder) Sum(a, b any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sum", reflect.TypeOf((*MockMath)(nil).Sum), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sum", reflect.TypeOf((*MockMath)(nil).Sum), a, b) } diff --git a/sample/mock_user_test.go b/sample/mock_user_test.go index 4025a9d..8d70f85 100644 --- a/sample/mock_user_test.go +++ b/sample/mock_user_test.go @@ -67,15 +67,15 @@ func (mr *MockIndexMockRecorder) Anon(arg0 any) *gomock.Call { } // Chan mocks base method. -func (m *MockIndex) Chan(arg0 chan int, arg1 chan<- hash.Hash) { +func (m *MockIndex) Chan(a chan int, b chan<- hash.Hash) { m.ctrl.T.Helper() - m.ctrl.Call(m, "Chan", arg0, arg1) + m.ctrl.Call(m, "Chan", a, b) } // Chan indicates an expected call of Chan. -func (mr *MockIndexMockRecorder) Chan(arg0, arg1 any) *gomock.Call { +func (mr *MockIndexMockRecorder) Chan(a, b any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Chan", reflect.TypeOf((*MockIndex)(nil).Chan), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Chan", reflect.TypeOf((*MockIndex)(nil).Chan), a, b) } // ConcreteRet mocks base method. @@ -93,19 +93,19 @@ func (mr *MockIndexMockRecorder) ConcreteRet() *gomock.Call { } // Ellip mocks base method. -func (m *MockIndex) Ellip(arg0 string, arg1 ...any) { +func (m *MockIndex) Ellip(fmt string, args ...any) { m.ctrl.T.Helper() - varargs := []any{arg0} - for _, a := range arg1 { + varargs := []any{fmt} + for _, a := range args { varargs = append(varargs, a) } m.ctrl.Call(m, "Ellip", varargs...) } // Ellip indicates an expected call of Ellip. -func (mr *MockIndexMockRecorder) Ellip(arg0 any, arg1 ...any) *gomock.Call { +func (mr *MockIndexMockRecorder) Ellip(fmt any, args ...any) *gomock.Call { mr.mock.ctrl.T.Helper() - varargs := append([]any{arg0}, arg1...) + varargs := append([]any{fmt}, args...) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ellip", reflect.TypeOf((*MockIndex)(nil).Ellip), varargs...) } @@ -174,56 +174,56 @@ func (mr *MockIndexMockRecorder) ForeignTwo(arg0 any) *gomock.Call { } // Func mocks base method. -func (m *MockIndex) Func(arg0 func(http.Request) (int, bool)) { +func (m *MockIndex) Func(f func(http.Request) (int, bool)) { m.ctrl.T.Helper() - m.ctrl.Call(m, "Func", arg0) + m.ctrl.Call(m, "Func", f) } // Func indicates an expected call of Func. -func (mr *MockIndexMockRecorder) Func(arg0 any) *gomock.Call { +func (mr *MockIndexMockRecorder) Func(f any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Func", reflect.TypeOf((*MockIndex)(nil).Func), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Func", reflect.TypeOf((*MockIndex)(nil).Func), f) } // Get mocks base method. -func (m *MockIndex) Get(arg0 string) any { +func (m *MockIndex) Get(key string) any { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Get", arg0) + ret := m.ctrl.Call(m, "Get", key) ret0, _ := ret[0].(any) return ret0 } // Get indicates an expected call of Get. -func (mr *MockIndexMockRecorder) Get(arg0 any) *gomock.Call { +func (mr *MockIndexMockRecorder) Get(key any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockIndex)(nil).Get), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockIndex)(nil).Get), key) } // GetTwo mocks base method. -func (m *MockIndex) GetTwo(arg0, arg1 string) (any, any) { +func (m *MockIndex) GetTwo(key1, key2 string) (any, any) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTwo", arg0, arg1) + ret := m.ctrl.Call(m, "GetTwo", key1, key2) ret0, _ := ret[0].(any) ret1, _ := ret[1].(any) return ret0, ret1 } // GetTwo indicates an expected call of GetTwo. -func (mr *MockIndexMockRecorder) GetTwo(arg0, arg1 any) *gomock.Call { +func (mr *MockIndexMockRecorder) GetTwo(key1, key2 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTwo", reflect.TypeOf((*MockIndex)(nil).GetTwo), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTwo", reflect.TypeOf((*MockIndex)(nil).GetTwo), key1, key2) } // Map mocks base method. -func (m *MockIndex) Map(arg0 map[int]hash.Hash) { +func (m *MockIndex) Map(a map[int]hash.Hash) { m.ctrl.T.Helper() - m.ctrl.Call(m, "Map", arg0) + m.ctrl.Call(m, "Map", a) } // Map indicates an expected call of Map. -func (mr *MockIndexMockRecorder) Map(arg0 any) *gomock.Call { +func (mr *MockIndexMockRecorder) Map(a any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Map", reflect.TypeOf((*MockIndex)(nil).Map), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Map", reflect.TypeOf((*MockIndex)(nil).Map), a) } // NillableRet mocks base method. @@ -255,89 +255,89 @@ func (mr *MockIndexMockRecorder) Other() *gomock.Call { } // Ptr mocks base method. -func (m *MockIndex) Ptr(arg0 *int) { +func (m *MockIndex) Ptr(arg *int) { m.ctrl.T.Helper() - m.ctrl.Call(m, "Ptr", arg0) + m.ctrl.Call(m, "Ptr", arg) } // Ptr indicates an expected call of Ptr. -func (mr *MockIndexMockRecorder) Ptr(arg0 any) *gomock.Call { +func (mr *MockIndexMockRecorder) Ptr(arg any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ptr", reflect.TypeOf((*MockIndex)(nil).Ptr), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ptr", reflect.TypeOf((*MockIndex)(nil).Ptr), arg) } // Put mocks base method. -func (m *MockIndex) Put(arg0 string, arg1 any) { +func (m *MockIndex) Put(key string, value any) { m.ctrl.T.Helper() - m.ctrl.Call(m, "Put", arg0, arg1) + m.ctrl.Call(m, "Put", key, value) } // Put indicates an expected call of Put. -func (mr *MockIndexMockRecorder) Put(arg0, arg1 any) *gomock.Call { +func (mr *MockIndexMockRecorder) Put(key, value any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockIndex)(nil).Put), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockIndex)(nil).Put), key, value) } // Slice mocks base method. -func (m *MockIndex) Slice(arg0 []int, arg1 []byte) [3]int { +func (m *MockIndex) Slice(a []int, b []byte) [3]int { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Slice", arg0, arg1) + ret := m.ctrl.Call(m, "Slice", a, b) ret0, _ := ret[0].([3]int) return ret0 } // Slice indicates an expected call of Slice. -func (mr *MockIndexMockRecorder) Slice(arg0, arg1 any) *gomock.Call { +func (mr *MockIndexMockRecorder) Slice(a, b any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Slice", reflect.TypeOf((*MockIndex)(nil).Slice), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Slice", reflect.TypeOf((*MockIndex)(nil).Slice), a, b) } // Struct mocks base method. -func (m *MockIndex) Struct(arg0 struct{}) { +func (m *MockIndex) Struct(a struct{}) { m.ctrl.T.Helper() - m.ctrl.Call(m, "Struct", arg0) + m.ctrl.Call(m, "Struct", a) } // Struct indicates an expected call of Struct. -func (mr *MockIndexMockRecorder) Struct(arg0 any) *gomock.Call { +func (mr *MockIndexMockRecorder) Struct(a any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Struct", reflect.TypeOf((*MockIndex)(nil).Struct), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Struct", reflect.TypeOf((*MockIndex)(nil).Struct), a) } // StructChan mocks base method. -func (m *MockIndex) StructChan(arg0 chan struct{}) { +func (m *MockIndex) StructChan(a chan struct{}) { m.ctrl.T.Helper() - m.ctrl.Call(m, "StructChan", arg0) + m.ctrl.Call(m, "StructChan", a) } // StructChan indicates an expected call of StructChan. -func (mr *MockIndexMockRecorder) StructChan(arg0 any) *gomock.Call { +func (mr *MockIndexMockRecorder) StructChan(a any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StructChan", reflect.TypeOf((*MockIndex)(nil).StructChan), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StructChan", reflect.TypeOf((*MockIndex)(nil).StructChan), a) } // Summary mocks base method. -func (m *MockIndex) Summary(arg0 *bytes.Buffer, arg1 io.Writer) { +func (m *MockIndex) Summary(buf *bytes.Buffer, w io.Writer) { m.ctrl.T.Helper() - m.ctrl.Call(m, "Summary", arg0, arg1) + m.ctrl.Call(m, "Summary", buf, w) } // Summary indicates an expected call of Summary. -func (mr *MockIndexMockRecorder) Summary(arg0, arg1 any) *gomock.Call { +func (mr *MockIndexMockRecorder) Summary(buf, w any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Summary", reflect.TypeOf((*MockIndex)(nil).Summary), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Summary", reflect.TypeOf((*MockIndex)(nil).Summary), buf, w) } // Templates mocks base method. -func (m *MockIndex) Templates(arg0 template.CSS, arg1 template0.FuncMap) { +func (m *MockIndex) Templates(a template.CSS, b template0.FuncMap) { m.ctrl.T.Helper() - m.ctrl.Call(m, "Templates", arg0, arg1) + m.ctrl.Call(m, "Templates", a, b) } // Templates indicates an expected call of Templates. -func (mr *MockIndexMockRecorder) Templates(arg0, arg1 any) *gomock.Call { +func (mr *MockIndexMockRecorder) Templates(a, b any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Templates", reflect.TypeOf((*MockIndex)(nil).Templates), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Templates", reflect.TypeOf((*MockIndex)(nil).Templates), a, b) } // MockEmbed is a mock of Embed interface. @@ -395,15 +395,15 @@ func (mr *MockEmbedMockRecorder) ForeignEmbeddedMethod() *gomock.Call { } // ImplicitPackage mocks base method. -func (m *MockEmbed) ImplicitPackage(arg0 string, arg1 imp1.ImpT, arg2 []imp1.ImpT, arg3 *imp1.ImpT, arg4 chan imp1.ImpT) { +func (m *MockEmbed) ImplicitPackage(s string, t imp1.ImpT, st []imp1.ImpT, pt *imp1.ImpT, ct chan imp1.ImpT) { m.ctrl.T.Helper() - m.ctrl.Call(m, "ImplicitPackage", arg0, arg1, arg2, arg3, arg4) + m.ctrl.Call(m, "ImplicitPackage", s, t, st, pt, ct) } // ImplicitPackage indicates an expected call of ImplicitPackage. -func (mr *MockEmbedMockRecorder) ImplicitPackage(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { +func (mr *MockEmbedMockRecorder) ImplicitPackage(s, t, st, pt, ct any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImplicitPackage", reflect.TypeOf((*MockEmbed)(nil).ImplicitPackage), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ImplicitPackage", reflect.TypeOf((*MockEmbed)(nil).ImplicitPackage), s, t, st, pt, ct) } // RegularMethod mocks base method. From 2b8cc4c248d02b2e3e063d1786f8fb3f702ed941 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Wed, 28 Aug 2024 19:55:57 +0300 Subject: [PATCH 02/16] tests has been reworked --- mockgen/import_mode_test.go | 207 ++- .../internal/tests/import_mode/cars/cars.go | 44 + .../internal/tests/import_mode/fuel/fuel.go | 18 + .../internal/tests/import_mode/guns/guns.go | 49 - .../internal/tests/import_mode/interfaces.go | 81 +- .../tests/import_mode/mock/interfaces.go | 1259 +++++++++-------- .../tests/import_mode/mock/interfaces_test.go | 41 + .../import_mode/projectiles/projectiles.go | 30 - .../import_mode/stratagems/interfaces.go | 14 - 9 files changed, 911 insertions(+), 832 deletions(-) create mode 100644 mockgen/internal/tests/import_mode/cars/cars.go create mode 100644 mockgen/internal/tests/import_mode/fuel/fuel.go delete mode 100644 mockgen/internal/tests/import_mode/guns/guns.go create mode 100644 mockgen/internal/tests/import_mode/mock/interfaces_test.go delete mode 100644 mockgen/internal/tests/import_mode/projectiles/projectiles.go delete mode 100644 mockgen/internal/tests/import_mode/stratagems/interfaces.go diff --git a/mockgen/import_mode_test.go b/mockgen/import_mode_test.go index 8c893aa..e1151a3 100644 --- a/mockgen/import_mode_test.go +++ b/mockgen/import_mode_test.go @@ -30,18 +30,18 @@ func Test_importModeParser_parsePackage(t *testing.T) { name: "error: interface does not exists", args: args{ packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", - ifaces: []string{"ImmortalHelldiver"}, + ifaces: []string{"Alien"}, }, - expectedErr: "failed to extract interfaces from package: interface ImmortalHelldiver does not exists", + expectedErr: "failed to extract interfaces from package: interface Alien does not exists", }, { name: "error: search for struct instead of interface", args: args{ packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", - ifaces: []string{"Enemy"}, + ifaces: []string{"Work"}, }, expectedErr: "failed to extract interfaces from package: failed to parse interface: " + - "Enemy is not an interface. it is a struct{Name string; Fraction string; Hp int}", + "Work is not an interface. it is a struct{Name string}", }, { name: "error: search for constraint instead of interface", @@ -56,17 +56,49 @@ func Test_importModeParser_parsePackage(t *testing.T) { name: "success: simple interface", args: args{ packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", - ifaces: []string{"DemocracyFan"}, + ifaces: []string{"Food"}, }, expected: &model.Package{ Name: "import_mode", PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", Interfaces: []*model.Interface{ { - Name: "DemocracyFan", + Name: "Food", Methods: []*model.Method{ - {Name: "ILoveDemocracy"}, - {Name: "YouWillNeverDestroyOurWayOfLife"}, + { + Name: "Calories", + Out: []*model.Parameter{ + {Type: model.PredeclaredType("int")}, + }, + }, + }, + }, + }, + }, + }, + { + name: "success: interface with variadic args", + args: args{ + packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + ifaces: []string{"Eater"}, + }, + expected: &model.Package{ + Name: "import_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Interfaces: []*model.Interface{ + { + Name: "Eater", + Methods: []*model.Method{ + { + Name: "Eat", + Variadic: &model.Parameter{ + Name: "foods", + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Type: "Food", + }, + }, + }, }, }, }, @@ -76,67 +108,62 @@ func Test_importModeParser_parsePackage(t *testing.T) { name: "success: interface with generic", args: args{ packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", - ifaces: []string{"Shooter"}, + ifaces: []string{"Car"}, }, expected: &model.Package{ Name: "import_mode", PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", Interfaces: []*model.Interface{ { - Name: "Shooter", + Name: "Car", Methods: []*model.Method{ { - Name: "Gun", + Name: "Brand", Out: []*model.Parameter{ - {Type: &model.NamedType{Type: "GunType"}}, + {Type: model.PredeclaredType("string")}, }, }, { - Name: "Reload", + Name: "FuelTank", Out: []*model.Parameter{ - {Type: model.PredeclaredType("bool")}, + { + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode/cars", + Type: "FuelTank", + TypeParams: &model.TypeParametersType{ + TypeParameters: []model.Type{ + &model.NamedType{ + Type: "FuelType", + }, + }, + }, + }, + }, }, }, { - Name: "Shoot", + Name: "Refuel", In: []*model.Parameter{ - {Name: "times", Type: model.PredeclaredType("int")}, + { + Name: "fuel", + Type: &model.NamedType{Type: "FuelType"}, + }, + { + Name: "volume", + Type: model.PredeclaredType("int"), + }, }, Out: []*model.Parameter{ - {Type: model.PredeclaredType("bool")}, {Type: &model.NamedType{Type: "error"}}, }, - Variadic: &model.Parameter{ - Name: "targets", - Type: &model.PointerType{ - Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", - Type: "Enemy", - }, - }, - }, }, }, TypeParams: []*model.Parameter{ { - Name: "ProjectileType", + Name: "FuelType", Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", - Type: "Projectile", - }, - }, - { - Name: "GunType", - Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", - Type: "Gun", - TypeParams: &model.TypeParametersType{ - TypeParameters: []model.Type{ - &model.NamedType{ - Type: "ProjectileType", - }, - }, - }, + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode/fuel", + Type: "Fuel", }, }, }, @@ -148,72 +175,120 @@ func Test_importModeParser_parsePackage(t *testing.T) { name: "success: interface with embedded interfaces", args: args{ packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", - ifaces: []string{"Helldiver"}, + ifaces: []string{"Animal"}, }, expected: &model.Package{ Name: "import_mode", PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", Interfaces: []*model.Interface{ { - Name: "Helldiver", + Name: "Animal", Methods: []*model.Method{ + {Name: "Breathe"}, { - Name: "AvailableStratagems", - Out: []*model.Parameter{ + Name: "Eat", + Variadic: &model.Parameter{ + Name: "foods", + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Type: "Food", + }, + }, + }, + { + Name: "Sleep", + In: []*model.Parameter{ { - Type: &model.ArrayType{ - Len: -1, - Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode/stratagems", - Type: "Stratagem", - }, + Name: "duration", + Type: &model.NamedType{ + Package: "time", + Type: "Duration", }, }, }, }, - {Name: "ILoveDemocracy"}, - {Name: "YouWillNeverDestroyOurWayOfLife"}, }, }, }, }, }, { - name: "success: alias to interface", + name: "success: subtype of interface", args: args{ packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", - ifaces: []string{"SuperEarthCitizen"}, + ifaces: []string{"Primate"}, }, expected: &model.Package{ Name: "import_mode", PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", Interfaces: []*model.Interface{ { - Name: "SuperEarthCitizen", + Name: "Primate", Methods: []*model.Method{ - {Name: "ILoveDemocracy"}, - {Name: "YouWillNeverDestroyOurWayOfLife"}, + {Name: "Breathe"}, + { + Name: "Eat", + Variadic: &model.Parameter{ + Name: "foods", + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Type: "Food", + }, + }, + }, + { + Name: "Sleep", + In: []*model.Parameter{ + { + Name: "duration", + Type: &model.NamedType{ + Package: "time", + Type: "Duration", + }, + }, + }, + }, }, }, }, }, }, { - name: "success: embedded anonymous interface", + name: "success: alias to interface", args: args{ packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", - ifaces: []string{"AgitationCampaign"}, + ifaces: []string{"Human"}, }, expected: &model.Package{ Name: "import_mode", PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", Interfaces: []*model.Interface{ { - Name: "AgitationCampaign", + Name: "Human", Methods: []*model.Method{ - {Name: "BecomeAHelldiver"}, - {Name: "BecomeAHero"}, - {Name: "BecomeALegend"}, + {Name: "Breathe"}, + { + Name: "Eat", + Variadic: &model.Parameter{ + Name: "foods", + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Type: "Food", + }, + }, + }, + { + Name: "Sleep", + In: []*model.Parameter{ + { + Name: "duration", + Type: &model.NamedType{ + Package: "time", + Type: "Duration", + }, + }, + }, + }, }, }, }, diff --git a/mockgen/internal/tests/import_mode/cars/cars.go b/mockgen/internal/tests/import_mode/cars/cars.go new file mode 100644 index 0000000..289812b --- /dev/null +++ b/mockgen/internal/tests/import_mode/cars/cars.go @@ -0,0 +1,44 @@ +package cars + +import ( + "go.uber.org/mock/mockgen/internal/tests/import_mode/fuel" +) + +type FuelTank[FuelType fuel.Fuel] struct { + Fuel FuelType + Capacity int +} + +type HyundaiSolaris struct{} + +func (HyundaiSolaris) Refuel(fuel.Gasoline, int) error { + return nil +} + +func (HyundaiSolaris) Brand() string { + return "Hyundai" +} + +func (HyundaiSolaris) FuelTank() FuelTank[fuel.Gasoline] { + return FuelTank[fuel.Gasoline]{ + Fuel: fuel.Gasoline{}, + Capacity: 50, + } +} + +type FordF150 struct{} + +func (FordF150) Brand() string { + return "Ford" +} + +func (FordF150) Refuel(fuel.Diesel, int) error { + return nil +} + +func (FordF150) FuelTank() FuelTank[fuel.Diesel] { + return FuelTank[fuel.Diesel]{ + Fuel: fuel.Diesel{}, + Capacity: 136, + } +} diff --git a/mockgen/internal/tests/import_mode/fuel/fuel.go b/mockgen/internal/tests/import_mode/fuel/fuel.go new file mode 100644 index 0000000..818d3f1 --- /dev/null +++ b/mockgen/internal/tests/import_mode/fuel/fuel.go @@ -0,0 +1,18 @@ +package fuel + +type Fuel interface { + EnergyCapacity() int + Diesel | Gasoline +} + +type Diesel struct{} + +func (Diesel) EnergyCapacity() int { + return 48 +} + +type Gasoline struct{} + +func (Gasoline) EnergyCapacity() int { + return 46 +} diff --git a/mockgen/internal/tests/import_mode/guns/guns.go b/mockgen/internal/tests/import_mode/guns/guns.go deleted file mode 100644 index 4f62927..0000000 --- a/mockgen/internal/tests/import_mode/guns/guns.go +++ /dev/null @@ -1,49 +0,0 @@ -package guns - -import ( - "go.uber.org/mock/mockgen/internal/tests/import_mode/projectiles" -) - -type Rifle struct { - ammoSize int -} - -func (r *Rifle) Shoot(times int) []projectiles.Bullet { - currentAmmo := r.ammoSize - r.ammoSize = min(0, currentAmmo-times) - - return make([]projectiles.Bullet, min(currentAmmo, times)) -} - -func (r *Rifle) Ammo() int { - return r.ammoSize -} - -type RocketLauncher struct { - loaded bool -} - -func (r *RocketLauncher) Shoot(times int) []projectiles.Missle { - if r.loaded { - r.loaded = false - return make([]projectiles.Missle, 1) - } - - return nil -} - -func (r *RocketLauncher) Ammo() int { - if r.loaded { - return 1 - } - - return 0 -} - -func min(a, b int) int { - if a < b { - return a - } - - return b -} diff --git a/mockgen/internal/tests/import_mode/interfaces.go b/mockgen/internal/tests/import_mode/interfaces.go index 75271b5..87ef1de 100644 --- a/mockgen/internal/tests/import_mode/interfaces.go +++ b/mockgen/internal/tests/import_mode/interfaces.go @@ -1,72 +1,59 @@ package import_mode -// This package is used for unit testing of import_mode.go. -// All the entities described here are inspired by the video game Helldivers 2 - -//go:generate mockgen -typed -package=mock -destination=mock/interfaces.go . DemocracyFan,SuperEarthCitizen,Projectile,Gun,Shooter,HelldiverRifleShooter,HelldiverRocketMan,PotentialTraitor,AgitationCampaign +//go:generate mockgen -typed -package=mock -destination=mock/interfaces.go . Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,PromotionCampaign import ( - "go.uber.org/mock/mockgen/internal/tests/import_mode/guns" - "go.uber.org/mock/mockgen/internal/tests/import_mode/projectiles" - . "go.uber.org/mock/mockgen/internal/tests/import_mode/stratagems" + "time" + + "go.uber.org/mock/mockgen/internal/tests/import_mode/cars" + "go.uber.org/mock/mockgen/internal/tests/import_mode/fuel" ) -type DemocracyFan interface { - ILoveDemocracy() - YouWillNeverDestroyOurWayOfLife() +type Food interface { + Calories() int } -type SuperEarthCitizen DemocracyFan - -type Projectile interface { - Speed() int - FlightRange() int - Explosive() bool +type Eater interface { + Eat(foods ...Food) } -type Gun[ProjectileType Projectile] interface { - Shoot(times int) []ProjectileType - Ammo() int +type Animal interface { + Eater + Breathe() + Sleep(duration time.Duration) } -type Shooter[ProjectileType Projectile, GunType Gun[ProjectileType]] interface { - Gun() GunType - Shoot(times int, targets ...*Enemy) (bool, error) - Reload() bool -} +type Primate Animal -type Helldiver interface { - DemocracyFan - StratagemCarrier -} +type Human = Primate -type HelldiverRifleShooter interface { - Helldiver - Shooter[projectiles.Bullet, *guns.Rifle] +type Car[FuelType fuel.Fuel] interface { + Brand() string + FuelTank() cars.FuelTank[FuelType] + Refuel(fuel FuelType, volume int) error } -type HelldiverRocketMan interface { - Helldiver - Shooter[projectiles.Missle, *guns.RocketLauncher] +type Driver[FuelType fuel.Fuel, CarType Car[FuelType]] interface { + Wroom() error + Drive(car CarType) } -type PotentialTraitor interface { - StratagemCarrier - Shooter[projectiles.Bullet, *guns.Rifle] +type UrbanResident interface { + Human + Driver[fuel.Gasoline, cars.HyundaiSolaris] + Do(work *Work) error + LivesInACity() } -type AgitationCampaign interface { - interface { - BecomeAHero() - BecomeALegend() - BecomeAHelldiver() - } +type Farmer interface { + Human + Driver[fuel.Diesel, cars.FordF150] + Do(work *Work) error + LivesInAVillage() } -type Enemy struct { - Name string - Fraction string - Hp int +type Work struct { + Name string } type Counter interface { diff --git a/mockgen/internal/tests/import_mode/mock/interfaces.go b/mockgen/internal/tests/import_mode/mock/interfaces.go index 9687585..86cb45f 100644 --- a/mockgen/internal/tests/import_mode/mock/interfaces.go +++ b/mockgen/internal/tests/import_mode/mock/interfaces.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: go.uber.org/mock/mockgen/internal/tests/import_mode (interfaces: DemocracyFan,SuperEarthCitizen,Projectile,Gun,Shooter,HelldiverRifleShooter,HelldiverRocketMan,PotentialTraitor,AgitationCampaign) +// Source: go.uber.org/mock/mockgen/internal/tests/import_mode (interfaces: Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,PromotionCampaign) // // Generated by this command: // -// mockgen -typed -package=mock -destination=mock/interfaces.go . DemocracyFan,SuperEarthCitizen,Projectile,Gun,Shooter,HelldiverRifleShooter,HelldiverRocketMan,PotentialTraitor,AgitationCampaign +// mockgen -typed -package=mock -destination=mock/interfaces.go . Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,PromotionCampaign // // Package mock is a generated GoMock package. @@ -11,1441 +11,1448 @@ package mock import ( reflect "reflect" + time "time" gomock "go.uber.org/mock/gomock" import_mode "go.uber.org/mock/mockgen/internal/tests/import_mode" - guns "go.uber.org/mock/mockgen/internal/tests/import_mode/guns" - stratagems "go.uber.org/mock/mockgen/internal/tests/import_mode/stratagems" + cars "go.uber.org/mock/mockgen/internal/tests/import_mode/cars" + fuel "go.uber.org/mock/mockgen/internal/tests/import_mode/fuel" ) -// MockDemocracyFan is a mock of DemocracyFan interface. -type MockDemocracyFan struct { +// MockFood is a mock of Food interface. +type MockFood struct { ctrl *gomock.Controller - recorder *MockDemocracyFanMockRecorder + recorder *MockFoodMockRecorder } -// MockDemocracyFanMockRecorder is the mock recorder for MockDemocracyFan. -type MockDemocracyFanMockRecorder struct { - mock *MockDemocracyFan +// MockFoodMockRecorder is the mock recorder for MockFood. +type MockFoodMockRecorder struct { + mock *MockFood } -// NewMockDemocracyFan creates a new mock instance. -func NewMockDemocracyFan(ctrl *gomock.Controller) *MockDemocracyFan { - mock := &MockDemocracyFan{ctrl: ctrl} - mock.recorder = &MockDemocracyFanMockRecorder{mock} +// NewMockFood creates a new mock instance. +func NewMockFood(ctrl *gomock.Controller) *MockFood { + mock := &MockFood{ctrl: ctrl} + mock.recorder = &MockFoodMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockDemocracyFan) EXPECT() *MockDemocracyFanMockRecorder { +func (m *MockFood) EXPECT() *MockFoodMockRecorder { return m.recorder } // ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockDemocracyFan) ISGOMOCK() struct{} { +func (m *MockFood) ISGOMOCK() struct{} { return struct{}{} } -// ILoveDemocracy mocks base method. -func (m *MockDemocracyFan) ILoveDemocracy() { +// Calories mocks base method. +func (m *MockFood) Calories() int { m.ctrl.T.Helper() - m.ctrl.Call(m, "ILoveDemocracy") + ret := m.ctrl.Call(m, "Calories") + ret0, _ := ret[0].(int) + return ret0 } -// ILoveDemocracy indicates an expected call of ILoveDemocracy. -func (mr *MockDemocracyFanMockRecorder) ILoveDemocracy() *MockDemocracyFanILoveDemocracyCall { +// Calories indicates an expected call of Calories. +func (mr *MockFoodMockRecorder) Calories() *MockFoodCaloriesCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ILoveDemocracy", reflect.TypeOf((*MockDemocracyFan)(nil).ILoveDemocracy)) - return &MockDemocracyFanILoveDemocracyCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Calories", reflect.TypeOf((*MockFood)(nil).Calories)) + return &MockFoodCaloriesCall{Call: call} } -// MockDemocracyFanILoveDemocracyCall wrap *gomock.Call -type MockDemocracyFanILoveDemocracyCall struct { +// MockFoodCaloriesCall wrap *gomock.Call +type MockFoodCaloriesCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockDemocracyFanILoveDemocracyCall) Return() *MockDemocracyFanILoveDemocracyCall { - c.Call = c.Call.Return() +func (c *MockFoodCaloriesCall) Return(arg0 int) *MockFoodCaloriesCall { + c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockDemocracyFanILoveDemocracyCall) Do(f func()) *MockDemocracyFanILoveDemocracyCall { +func (c *MockFoodCaloriesCall) Do(f func() int) *MockFoodCaloriesCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockDemocracyFanILoveDemocracyCall) DoAndReturn(f func()) *MockDemocracyFanILoveDemocracyCall { +func (c *MockFoodCaloriesCall) DoAndReturn(f func() int) *MockFoodCaloriesCall { c.Call = c.Call.DoAndReturn(f) return c } -// YouWillNeverDestroyOurWayOfLife mocks base method. -func (m *MockDemocracyFan) YouWillNeverDestroyOurWayOfLife() { +// MockEater is a mock of Eater interface. +type MockEater struct { + ctrl *gomock.Controller + recorder *MockEaterMockRecorder +} + +// MockEaterMockRecorder is the mock recorder for MockEater. +type MockEaterMockRecorder struct { + mock *MockEater +} + +// NewMockEater creates a new mock instance. +func NewMockEater(ctrl *gomock.Controller) *MockEater { + mock := &MockEater{ctrl: ctrl} + mock.recorder = &MockEaterMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEater) EXPECT() *MockEaterMockRecorder { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockEater) ISGOMOCK() struct{} { + return struct{}{} +} + +// Eat mocks base method. +func (m *MockEater) Eat(foods ...import_mode.Food) { m.ctrl.T.Helper() - m.ctrl.Call(m, "YouWillNeverDestroyOurWayOfLife") + varargs := []any{} + for _, a := range foods { + varargs = append(varargs, a) + } + m.ctrl.Call(m, "Eat", varargs...) } -// YouWillNeverDestroyOurWayOfLife indicates an expected call of YouWillNeverDestroyOurWayOfLife. -func (mr *MockDemocracyFanMockRecorder) YouWillNeverDestroyOurWayOfLife() *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall { +// Eat indicates an expected call of Eat. +func (mr *MockEaterMockRecorder) Eat(foods ...any) *MockEaterEatCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "YouWillNeverDestroyOurWayOfLife", reflect.TypeOf((*MockDemocracyFan)(nil).YouWillNeverDestroyOurWayOfLife)) - return &MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eat", reflect.TypeOf((*MockEater)(nil).Eat), foods...) + return &MockEaterEatCall{Call: call} } -// MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall wrap *gomock.Call -type MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall struct { +// MockEaterEatCall wrap *gomock.Call +type MockEaterEatCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall) Return() *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall { +func (c *MockEaterEatCall) Return() *MockEaterEatCall { c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall) Do(f func()) *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall { +func (c *MockEaterEatCall) Do(f func(...import_mode.Food)) *MockEaterEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall) DoAndReturn(f func()) *MockDemocracyFanYouWillNeverDestroyOurWayOfLifeCall { +func (c *MockEaterEatCall) DoAndReturn(f func(...import_mode.Food)) *MockEaterEatCall { c.Call = c.Call.DoAndReturn(f) return c } -// MockSuperEarthCitizen is a mock of SuperEarthCitizen interface. -type MockSuperEarthCitizen struct { +// MockAnimal is a mock of Animal interface. +type MockAnimal struct { ctrl *gomock.Controller - recorder *MockSuperEarthCitizenMockRecorder + recorder *MockAnimalMockRecorder } -// MockSuperEarthCitizenMockRecorder is the mock recorder for MockSuperEarthCitizen. -type MockSuperEarthCitizenMockRecorder struct { - mock *MockSuperEarthCitizen +// MockAnimalMockRecorder is the mock recorder for MockAnimal. +type MockAnimalMockRecorder struct { + mock *MockAnimal } -// NewMockSuperEarthCitizen creates a new mock instance. -func NewMockSuperEarthCitizen(ctrl *gomock.Controller) *MockSuperEarthCitizen { - mock := &MockSuperEarthCitizen{ctrl: ctrl} - mock.recorder = &MockSuperEarthCitizenMockRecorder{mock} +// NewMockAnimal creates a new mock instance. +func NewMockAnimal(ctrl *gomock.Controller) *MockAnimal { + mock := &MockAnimal{ctrl: ctrl} + mock.recorder = &MockAnimalMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockSuperEarthCitizen) EXPECT() *MockSuperEarthCitizenMockRecorder { +func (m *MockAnimal) EXPECT() *MockAnimalMockRecorder { return m.recorder } // ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockSuperEarthCitizen) ISGOMOCK() struct{} { +func (m *MockAnimal) ISGOMOCK() struct{} { return struct{}{} } -// ILoveDemocracy mocks base method. -func (m *MockSuperEarthCitizen) ILoveDemocracy() { +// Breathe mocks base method. +func (m *MockAnimal) Breathe() { m.ctrl.T.Helper() - m.ctrl.Call(m, "ILoveDemocracy") + m.ctrl.Call(m, "Breathe") } -// ILoveDemocracy indicates an expected call of ILoveDemocracy. -func (mr *MockSuperEarthCitizenMockRecorder) ILoveDemocracy() *MockSuperEarthCitizenILoveDemocracyCall { +// Breathe indicates an expected call of Breathe. +func (mr *MockAnimalMockRecorder) Breathe() *MockAnimalBreatheCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ILoveDemocracy", reflect.TypeOf((*MockSuperEarthCitizen)(nil).ILoveDemocracy)) - return &MockSuperEarthCitizenILoveDemocracyCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Breathe", reflect.TypeOf((*MockAnimal)(nil).Breathe)) + return &MockAnimalBreatheCall{Call: call} } -// MockSuperEarthCitizenILoveDemocracyCall wrap *gomock.Call -type MockSuperEarthCitizenILoveDemocracyCall struct { +// MockAnimalBreatheCall wrap *gomock.Call +type MockAnimalBreatheCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockSuperEarthCitizenILoveDemocracyCall) Return() *MockSuperEarthCitizenILoveDemocracyCall { +func (c *MockAnimalBreatheCall) Return() *MockAnimalBreatheCall { c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockSuperEarthCitizenILoveDemocracyCall) Do(f func()) *MockSuperEarthCitizenILoveDemocracyCall { +func (c *MockAnimalBreatheCall) Do(f func()) *MockAnimalBreatheCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockSuperEarthCitizenILoveDemocracyCall) DoAndReturn(f func()) *MockSuperEarthCitizenILoveDemocracyCall { +func (c *MockAnimalBreatheCall) DoAndReturn(f func()) *MockAnimalBreatheCall { c.Call = c.Call.DoAndReturn(f) return c } -// YouWillNeverDestroyOurWayOfLife mocks base method. -func (m *MockSuperEarthCitizen) YouWillNeverDestroyOurWayOfLife() { +// Eat mocks base method. +func (m *MockAnimal) Eat(foods ...import_mode.Food) { m.ctrl.T.Helper() - m.ctrl.Call(m, "YouWillNeverDestroyOurWayOfLife") + varargs := []any{} + for _, a := range foods { + varargs = append(varargs, a) + } + m.ctrl.Call(m, "Eat", varargs...) } -// YouWillNeverDestroyOurWayOfLife indicates an expected call of YouWillNeverDestroyOurWayOfLife. -func (mr *MockSuperEarthCitizenMockRecorder) YouWillNeverDestroyOurWayOfLife() *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall { +// Eat indicates an expected call of Eat. +func (mr *MockAnimalMockRecorder) Eat(foods ...any) *MockAnimalEatCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "YouWillNeverDestroyOurWayOfLife", reflect.TypeOf((*MockSuperEarthCitizen)(nil).YouWillNeverDestroyOurWayOfLife)) - return &MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eat", reflect.TypeOf((*MockAnimal)(nil).Eat), foods...) + return &MockAnimalEatCall{Call: call} } -// MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall wrap *gomock.Call -type MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall struct { +// MockAnimalEatCall wrap *gomock.Call +type MockAnimalEatCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall) Return() *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall { +func (c *MockAnimalEatCall) Return() *MockAnimalEatCall { c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall) Do(f func()) *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall { +func (c *MockAnimalEatCall) Do(f func(...import_mode.Food)) *MockAnimalEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall) DoAndReturn(f func()) *MockSuperEarthCitizenYouWillNeverDestroyOurWayOfLifeCall { +func (c *MockAnimalEatCall) DoAndReturn(f func(...import_mode.Food)) *MockAnimalEatCall { c.Call = c.Call.DoAndReturn(f) return c } -// MockProjectile is a mock of Projectile interface. -type MockProjectile struct { - ctrl *gomock.Controller - recorder *MockProjectileMockRecorder -} - -// MockProjectileMockRecorder is the mock recorder for MockProjectile. -type MockProjectileMockRecorder struct { - mock *MockProjectile -} - -// NewMockProjectile creates a new mock instance. -func NewMockProjectile(ctrl *gomock.Controller) *MockProjectile { - mock := &MockProjectile{ctrl: ctrl} - mock.recorder = &MockProjectileMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockProjectile) EXPECT() *MockProjectileMockRecorder { - return m.recorder -} - -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockProjectile) ISGOMOCK() struct{} { - return struct{}{} -} - -// Explosive mocks base method. -func (m *MockProjectile) Explosive() bool { +// Sleep mocks base method. +func (m *MockAnimal) Sleep(duration time.Duration) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Explosive") - ret0, _ := ret[0].(bool) - return ret0 + m.ctrl.Call(m, "Sleep", duration) } -// Explosive indicates an expected call of Explosive. -func (mr *MockProjectileMockRecorder) Explosive() *MockProjectileExplosiveCall { +// Sleep indicates an expected call of Sleep. +func (mr *MockAnimalMockRecorder) Sleep(duration any) *MockAnimalSleepCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Explosive", reflect.TypeOf((*MockProjectile)(nil).Explosive)) - return &MockProjectileExplosiveCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sleep", reflect.TypeOf((*MockAnimal)(nil).Sleep), duration) + return &MockAnimalSleepCall{Call: call} } -// MockProjectileExplosiveCall wrap *gomock.Call -type MockProjectileExplosiveCall struct { +// MockAnimalSleepCall wrap *gomock.Call +type MockAnimalSleepCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockProjectileExplosiveCall) Return(arg0 bool) *MockProjectileExplosiveCall { - c.Call = c.Call.Return(arg0) +func (c *MockAnimalSleepCall) Return() *MockAnimalSleepCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockProjectileExplosiveCall) Do(f func() bool) *MockProjectileExplosiveCall { +func (c *MockAnimalSleepCall) Do(f func(time.Duration)) *MockAnimalSleepCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockProjectileExplosiveCall) DoAndReturn(f func() bool) *MockProjectileExplosiveCall { +func (c *MockAnimalSleepCall) DoAndReturn(f func(time.Duration)) *MockAnimalSleepCall { c.Call = c.Call.DoAndReturn(f) return c } -// FlightRange mocks base method. -func (m *MockProjectile) FlightRange() int { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FlightRange") - ret0, _ := ret[0].(int) - return ret0 -} - -// FlightRange indicates an expected call of FlightRange. -func (mr *MockProjectileMockRecorder) FlightRange() *MockProjectileFlightRangeCall { - mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FlightRange", reflect.TypeOf((*MockProjectile)(nil).FlightRange)) - return &MockProjectileFlightRangeCall{Call: call} +// MockHuman is a mock of Human interface. +type MockHuman struct { + ctrl *gomock.Controller + recorder *MockHumanMockRecorder } -// MockProjectileFlightRangeCall wrap *gomock.Call -type MockProjectileFlightRangeCall struct { - *gomock.Call +// MockHumanMockRecorder is the mock recorder for MockHuman. +type MockHumanMockRecorder struct { + mock *MockHuman } -// Return rewrite *gomock.Call.Return -func (c *MockProjectileFlightRangeCall) Return(arg0 int) *MockProjectileFlightRangeCall { - c.Call = c.Call.Return(arg0) - return c +// NewMockHuman creates a new mock instance. +func NewMockHuman(ctrl *gomock.Controller) *MockHuman { + mock := &MockHuman{ctrl: ctrl} + mock.recorder = &MockHumanMockRecorder{mock} + return mock } -// Do rewrite *gomock.Call.Do -func (c *MockProjectileFlightRangeCall) Do(f func() int) *MockProjectileFlightRangeCall { - c.Call = c.Call.Do(f) - return c +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockHuman) EXPECT() *MockHumanMockRecorder { + return m.recorder } -// DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockProjectileFlightRangeCall) DoAndReturn(f func() int) *MockProjectileFlightRangeCall { - c.Call = c.Call.DoAndReturn(f) - return c +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockHuman) ISGOMOCK() struct{} { + return struct{}{} } -// Speed mocks base method. -func (m *MockProjectile) Speed() int { +// Breathe mocks base method. +func (m *MockHuman) Breathe() { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Speed") - ret0, _ := ret[0].(int) - return ret0 + m.ctrl.Call(m, "Breathe") } -// Speed indicates an expected call of Speed. -func (mr *MockProjectileMockRecorder) Speed() *MockProjectileSpeedCall { +// Breathe indicates an expected call of Breathe. +func (mr *MockHumanMockRecorder) Breathe() *MockHumanBreatheCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Speed", reflect.TypeOf((*MockProjectile)(nil).Speed)) - return &MockProjectileSpeedCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Breathe", reflect.TypeOf((*MockHuman)(nil).Breathe)) + return &MockHumanBreatheCall{Call: call} } -// MockProjectileSpeedCall wrap *gomock.Call -type MockProjectileSpeedCall struct { +// MockHumanBreatheCall wrap *gomock.Call +type MockHumanBreatheCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockProjectileSpeedCall) Return(arg0 int) *MockProjectileSpeedCall { - c.Call = c.Call.Return(arg0) +func (c *MockHumanBreatheCall) Return() *MockHumanBreatheCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockProjectileSpeedCall) Do(f func() int) *MockProjectileSpeedCall { +func (c *MockHumanBreatheCall) Do(f func()) *MockHumanBreatheCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockProjectileSpeedCall) DoAndReturn(f func() int) *MockProjectileSpeedCall { +func (c *MockHumanBreatheCall) DoAndReturn(f func()) *MockHumanBreatheCall { c.Call = c.Call.DoAndReturn(f) return c } -// MockGun is a mock of Gun interface. -type MockGun[ProjectileType import_mode.Projectile] struct { - ctrl *gomock.Controller - recorder *MockGunMockRecorder[ProjectileType] -} - -// MockGunMockRecorder is the mock recorder for MockGun. -type MockGunMockRecorder[ProjectileType import_mode.Projectile] struct { - mock *MockGun[ProjectileType] -} - -// NewMockGun creates a new mock instance. -func NewMockGun[ProjectileType import_mode.Projectile](ctrl *gomock.Controller) *MockGun[ProjectileType] { - mock := &MockGun[ProjectileType]{ctrl: ctrl} - mock.recorder = &MockGunMockRecorder[ProjectileType]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockGun[ProjectileType]) EXPECT() *MockGunMockRecorder[ProjectileType] { - return m.recorder -} - -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockGun[ProjectileType]) ISGOMOCK() struct{} { - return struct{}{} -} - -// Ammo mocks base method. -func (m *MockGun[ProjectileType]) Ammo() int { +// Eat mocks base method. +func (m *MockHuman) Eat(foods ...import_mode.Food) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Ammo") - ret0, _ := ret[0].(int) - return ret0 + varargs := []any{} + for _, a := range foods { + varargs = append(varargs, a) + } + m.ctrl.Call(m, "Eat", varargs...) } -// Ammo indicates an expected call of Ammo. -func (mr *MockGunMockRecorder[ProjectileType]) Ammo() *MockGunAmmoCall[ProjectileType] { +// Eat indicates an expected call of Eat. +func (mr *MockHumanMockRecorder) Eat(foods ...any) *MockHumanEatCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ammo", reflect.TypeOf((*MockGun[ProjectileType])(nil).Ammo)) - return &MockGunAmmoCall[ProjectileType]{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eat", reflect.TypeOf((*MockHuman)(nil).Eat), foods...) + return &MockHumanEatCall{Call: call} } -// MockGunAmmoCall wrap *gomock.Call -type MockGunAmmoCall[ProjectileType import_mode.Projectile] struct { +// MockHumanEatCall wrap *gomock.Call +type MockHumanEatCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockGunAmmoCall[ProjectileType]) Return(arg0 int) *MockGunAmmoCall[ProjectileType] { - c.Call = c.Call.Return(arg0) +func (c *MockHumanEatCall) Return() *MockHumanEatCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockGunAmmoCall[ProjectileType]) Do(f func() int) *MockGunAmmoCall[ProjectileType] { +func (c *MockHumanEatCall) Do(f func(...import_mode.Food)) *MockHumanEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockGunAmmoCall[ProjectileType]) DoAndReturn(f func() int) *MockGunAmmoCall[ProjectileType] { +func (c *MockHumanEatCall) DoAndReturn(f func(...import_mode.Food)) *MockHumanEatCall { c.Call = c.Call.DoAndReturn(f) return c } -// Shoot mocks base method. -func (m *MockGun[ProjectileType]) Shoot(times int) []ProjectileType { +// Sleep mocks base method. +func (m *MockHuman) Sleep(duration time.Duration) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Shoot", times) - ret0, _ := ret[0].([]ProjectileType) - return ret0 + m.ctrl.Call(m, "Sleep", duration) } -// Shoot indicates an expected call of Shoot. -func (mr *MockGunMockRecorder[ProjectileType]) Shoot(times any) *MockGunShootCall[ProjectileType] { +// Sleep indicates an expected call of Sleep. +func (mr *MockHumanMockRecorder) Sleep(duration any) *MockHumanSleepCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shoot", reflect.TypeOf((*MockGun[ProjectileType])(nil).Shoot), times) - return &MockGunShootCall[ProjectileType]{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sleep", reflect.TypeOf((*MockHuman)(nil).Sleep), duration) + return &MockHumanSleepCall{Call: call} } -// MockGunShootCall wrap *gomock.Call -type MockGunShootCall[ProjectileType import_mode.Projectile] struct { +// MockHumanSleepCall wrap *gomock.Call +type MockHumanSleepCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockGunShootCall[ProjectileType]) Return(arg0 []ProjectileType) *MockGunShootCall[ProjectileType] { - c.Call = c.Call.Return(arg0) +func (c *MockHumanSleepCall) Return() *MockHumanSleepCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockGunShootCall[ProjectileType]) Do(f func(int) []ProjectileType) *MockGunShootCall[ProjectileType] { +func (c *MockHumanSleepCall) Do(f func(time.Duration)) *MockHumanSleepCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockGunShootCall[ProjectileType]) DoAndReturn(f func(int) []ProjectileType) *MockGunShootCall[ProjectileType] { +func (c *MockHumanSleepCall) DoAndReturn(f func(time.Duration)) *MockHumanSleepCall { c.Call = c.Call.DoAndReturn(f) return c } -// MockShooter is a mock of Shooter interface. -type MockShooter[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]] struct { +// MockPrimate is a mock of Primate interface. +type MockPrimate struct { ctrl *gomock.Controller - recorder *MockShooterMockRecorder[ProjectileType, GunType] + recorder *MockPrimateMockRecorder } -// MockShooterMockRecorder is the mock recorder for MockShooter. -type MockShooterMockRecorder[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]] struct { - mock *MockShooter[ProjectileType, GunType] +// MockPrimateMockRecorder is the mock recorder for MockPrimate. +type MockPrimateMockRecorder struct { + mock *MockPrimate } -// NewMockShooter creates a new mock instance. -func NewMockShooter[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]](ctrl *gomock.Controller) *MockShooter[ProjectileType, GunType] { - mock := &MockShooter[ProjectileType, GunType]{ctrl: ctrl} - mock.recorder = &MockShooterMockRecorder[ProjectileType, GunType]{mock} +// NewMockPrimate creates a new mock instance. +func NewMockPrimate(ctrl *gomock.Controller) *MockPrimate { + mock := &MockPrimate{ctrl: ctrl} + mock.recorder = &MockPrimateMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockShooter[ProjectileType, GunType]) EXPECT() *MockShooterMockRecorder[ProjectileType, GunType] { +func (m *MockPrimate) EXPECT() *MockPrimateMockRecorder { return m.recorder } // ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockShooter[ProjectileType, GunType]) ISGOMOCK() struct{} { +func (m *MockPrimate) ISGOMOCK() struct{} { return struct{}{} } -// Gun mocks base method. -func (m *MockShooter[ProjectileType, GunType]) Gun() GunType { +// Breathe mocks base method. +func (m *MockPrimate) Breathe() { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Gun") - ret0, _ := ret[0].(GunType) - return ret0 + m.ctrl.Call(m, "Breathe") } -// Gun indicates an expected call of Gun. -func (mr *MockShooterMockRecorder[ProjectileType, GunType]) Gun() *MockShooterGunCall[ProjectileType, GunType] { +// Breathe indicates an expected call of Breathe. +func (mr *MockPrimateMockRecorder) Breathe() *MockPrimateBreatheCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Gun", reflect.TypeOf((*MockShooter[ProjectileType, GunType])(nil).Gun)) - return &MockShooterGunCall[ProjectileType, GunType]{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Breathe", reflect.TypeOf((*MockPrimate)(nil).Breathe)) + return &MockPrimateBreatheCall{Call: call} } -// MockShooterGunCall wrap *gomock.Call -type MockShooterGunCall[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]] struct { +// MockPrimateBreatheCall wrap *gomock.Call +type MockPrimateBreatheCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockShooterGunCall[ProjectileType, GunType]) Return(arg0 GunType) *MockShooterGunCall[ProjectileType, GunType] { - c.Call = c.Call.Return(arg0) +func (c *MockPrimateBreatheCall) Return() *MockPrimateBreatheCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockShooterGunCall[ProjectileType, GunType]) Do(f func() GunType) *MockShooterGunCall[ProjectileType, GunType] { +func (c *MockPrimateBreatheCall) Do(f func()) *MockPrimateBreatheCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockShooterGunCall[ProjectileType, GunType]) DoAndReturn(f func() GunType) *MockShooterGunCall[ProjectileType, GunType] { +func (c *MockPrimateBreatheCall) DoAndReturn(f func()) *MockPrimateBreatheCall { c.Call = c.Call.DoAndReturn(f) return c } -// Reload mocks base method. -func (m *MockShooter[ProjectileType, GunType]) Reload() bool { +// Eat mocks base method. +func (m *MockPrimate) Eat(foods ...import_mode.Food) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Reload") - ret0, _ := ret[0].(bool) - return ret0 + varargs := []any{} + for _, a := range foods { + varargs = append(varargs, a) + } + m.ctrl.Call(m, "Eat", varargs...) } -// Reload indicates an expected call of Reload. -func (mr *MockShooterMockRecorder[ProjectileType, GunType]) Reload() *MockShooterReloadCall[ProjectileType, GunType] { +// Eat indicates an expected call of Eat. +func (mr *MockPrimateMockRecorder) Eat(foods ...any) *MockPrimateEatCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reload", reflect.TypeOf((*MockShooter[ProjectileType, GunType])(nil).Reload)) - return &MockShooterReloadCall[ProjectileType, GunType]{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eat", reflect.TypeOf((*MockPrimate)(nil).Eat), foods...) + return &MockPrimateEatCall{Call: call} } -// MockShooterReloadCall wrap *gomock.Call -type MockShooterReloadCall[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]] struct { +// MockPrimateEatCall wrap *gomock.Call +type MockPrimateEatCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockShooterReloadCall[ProjectileType, GunType]) Return(arg0 bool) *MockShooterReloadCall[ProjectileType, GunType] { - c.Call = c.Call.Return(arg0) +func (c *MockPrimateEatCall) Return() *MockPrimateEatCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockShooterReloadCall[ProjectileType, GunType]) Do(f func() bool) *MockShooterReloadCall[ProjectileType, GunType] { +func (c *MockPrimateEatCall) Do(f func(...import_mode.Food)) *MockPrimateEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockShooterReloadCall[ProjectileType, GunType]) DoAndReturn(f func() bool) *MockShooterReloadCall[ProjectileType, GunType] { +func (c *MockPrimateEatCall) DoAndReturn(f func(...import_mode.Food)) *MockPrimateEatCall { c.Call = c.Call.DoAndReturn(f) return c } -// Shoot mocks base method. -func (m *MockShooter[ProjectileType, GunType]) Shoot(times int, targets ...*import_mode.Enemy) (bool, error) { +// Sleep mocks base method. +func (m *MockPrimate) Sleep(duration time.Duration) { m.ctrl.T.Helper() - varargs := []any{times} - for _, a := range targets { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Shoot", varargs...) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.Call(m, "Sleep", duration) } -// Shoot indicates an expected call of Shoot. -func (mr *MockShooterMockRecorder[ProjectileType, GunType]) Shoot(times any, targets ...any) *MockShooterShootCall[ProjectileType, GunType] { +// Sleep indicates an expected call of Sleep. +func (mr *MockPrimateMockRecorder) Sleep(duration any) *MockPrimateSleepCall { mr.mock.ctrl.T.Helper() - varargs := append([]any{times}, targets...) - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shoot", reflect.TypeOf((*MockShooter[ProjectileType, GunType])(nil).Shoot), varargs...) - return &MockShooterShootCall[ProjectileType, GunType]{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sleep", reflect.TypeOf((*MockPrimate)(nil).Sleep), duration) + return &MockPrimateSleepCall{Call: call} } -// MockShooterShootCall wrap *gomock.Call -type MockShooterShootCall[ProjectileType import_mode.Projectile, GunType import_mode.Gun[ProjectileType]] struct { +// MockPrimateSleepCall wrap *gomock.Call +type MockPrimateSleepCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockShooterShootCall[ProjectileType, GunType]) Return(arg0 bool, arg1 error) *MockShooterShootCall[ProjectileType, GunType] { - c.Call = c.Call.Return(arg0, arg1) +func (c *MockPrimateSleepCall) Return() *MockPrimateSleepCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockShooterShootCall[ProjectileType, GunType]) Do(f func(int, ...*import_mode.Enemy) (bool, error)) *MockShooterShootCall[ProjectileType, GunType] { +func (c *MockPrimateSleepCall) Do(f func(time.Duration)) *MockPrimateSleepCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockShooterShootCall[ProjectileType, GunType]) DoAndReturn(f func(int, ...*import_mode.Enemy) (bool, error)) *MockShooterShootCall[ProjectileType, GunType] { +func (c *MockPrimateSleepCall) DoAndReturn(f func(time.Duration)) *MockPrimateSleepCall { c.Call = c.Call.DoAndReturn(f) return c } -// MockHelldiverRifleShooter is a mock of HelldiverRifleShooter interface. -type MockHelldiverRifleShooter struct { +// MockCar is a mock of Car interface. +type MockCar[FuelType fuel.Fuel] struct { ctrl *gomock.Controller - recorder *MockHelldiverRifleShooterMockRecorder + recorder *MockCarMockRecorder[FuelType] } -// MockHelldiverRifleShooterMockRecorder is the mock recorder for MockHelldiverRifleShooter. -type MockHelldiverRifleShooterMockRecorder struct { - mock *MockHelldiverRifleShooter +// MockCarMockRecorder is the mock recorder for MockCar. +type MockCarMockRecorder[FuelType fuel.Fuel] struct { + mock *MockCar[FuelType] } -// NewMockHelldiverRifleShooter creates a new mock instance. -func NewMockHelldiverRifleShooter(ctrl *gomock.Controller) *MockHelldiverRifleShooter { - mock := &MockHelldiverRifleShooter{ctrl: ctrl} - mock.recorder = &MockHelldiverRifleShooterMockRecorder{mock} +// NewMockCar creates a new mock instance. +func NewMockCar[FuelType fuel.Fuel](ctrl *gomock.Controller) *MockCar[FuelType] { + mock := &MockCar[FuelType]{ctrl: ctrl} + mock.recorder = &MockCarMockRecorder[FuelType]{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockHelldiverRifleShooter) EXPECT() *MockHelldiverRifleShooterMockRecorder { +func (m *MockCar[FuelType]) EXPECT() *MockCarMockRecorder[FuelType] { return m.recorder } // ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockHelldiverRifleShooter) ISGOMOCK() struct{} { +func (m *MockCar[FuelType]) ISGOMOCK() struct{} { return struct{}{} } -// AvailableStratagems mocks base method. -func (m *MockHelldiverRifleShooter) AvailableStratagems() []stratagems.Stratagem { +// Brand mocks base method. +func (m *MockCar[FuelType]) Brand() string { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AvailableStratagems") - ret0, _ := ret[0].([]stratagems.Stratagem) + ret := m.ctrl.Call(m, "Brand") + ret0, _ := ret[0].(string) return ret0 } -// AvailableStratagems indicates an expected call of AvailableStratagems. -func (mr *MockHelldiverRifleShooterMockRecorder) AvailableStratagems() *MockHelldiverRifleShooterAvailableStratagemsCall { +// Brand indicates an expected call of Brand. +func (mr *MockCarMockRecorder[FuelType]) Brand() *MockCarBrandCall[FuelType] { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AvailableStratagems", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).AvailableStratagems)) - return &MockHelldiverRifleShooterAvailableStratagemsCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Brand", reflect.TypeOf((*MockCar[FuelType])(nil).Brand)) + return &MockCarBrandCall[FuelType]{Call: call} } -// MockHelldiverRifleShooterAvailableStratagemsCall wrap *gomock.Call -type MockHelldiverRifleShooterAvailableStratagemsCall struct { +// MockCarBrandCall wrap *gomock.Call +type MockCarBrandCall[FuelType fuel.Fuel] struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockHelldiverRifleShooterAvailableStratagemsCall) Return(arg0 []stratagems.Stratagem) *MockHelldiverRifleShooterAvailableStratagemsCall { +func (c *MockCarBrandCall[FuelType]) Return(arg0 string) *MockCarBrandCall[FuelType] { c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockHelldiverRifleShooterAvailableStratagemsCall) Do(f func() []stratagems.Stratagem) *MockHelldiverRifleShooterAvailableStratagemsCall { +func (c *MockCarBrandCall[FuelType]) Do(f func() string) *MockCarBrandCall[FuelType] { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRifleShooterAvailableStratagemsCall) DoAndReturn(f func() []stratagems.Stratagem) *MockHelldiverRifleShooterAvailableStratagemsCall { +func (c *MockCarBrandCall[FuelType]) DoAndReturn(f func() string) *MockCarBrandCall[FuelType] { c.Call = c.Call.DoAndReturn(f) return c } -// Gun mocks base method. -func (m *MockHelldiverRifleShooter) Gun() *guns.Rifle { +// FuelTank mocks base method. +func (m *MockCar[FuelType]) FuelTank() cars.FuelTank[FuelType] { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Gun") - ret0, _ := ret[0].(*guns.Rifle) + ret := m.ctrl.Call(m, "FuelTank") + ret0, _ := ret[0].(cars.FuelTank[FuelType]) return ret0 } -// Gun indicates an expected call of Gun. -func (mr *MockHelldiverRifleShooterMockRecorder) Gun() *MockHelldiverRifleShooterGunCall { +// FuelTank indicates an expected call of FuelTank. +func (mr *MockCarMockRecorder[FuelType]) FuelTank() *MockCarFuelTankCall[FuelType] { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Gun", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).Gun)) - return &MockHelldiverRifleShooterGunCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FuelTank", reflect.TypeOf((*MockCar[FuelType])(nil).FuelTank)) + return &MockCarFuelTankCall[FuelType]{Call: call} } -// MockHelldiverRifleShooterGunCall wrap *gomock.Call -type MockHelldiverRifleShooterGunCall struct { +// MockCarFuelTankCall wrap *gomock.Call +type MockCarFuelTankCall[FuelType fuel.Fuel] struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockHelldiverRifleShooterGunCall) Return(arg0 *guns.Rifle) *MockHelldiverRifleShooterGunCall { +func (c *MockCarFuelTankCall[FuelType]) Return(arg0 cars.FuelTank[FuelType]) *MockCarFuelTankCall[FuelType] { c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockHelldiverRifleShooterGunCall) Do(f func() *guns.Rifle) *MockHelldiverRifleShooterGunCall { +func (c *MockCarFuelTankCall[FuelType]) Do(f func() cars.FuelTank[FuelType]) *MockCarFuelTankCall[FuelType] { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRifleShooterGunCall) DoAndReturn(f func() *guns.Rifle) *MockHelldiverRifleShooterGunCall { +func (c *MockCarFuelTankCall[FuelType]) DoAndReturn(f func() cars.FuelTank[FuelType]) *MockCarFuelTankCall[FuelType] { c.Call = c.Call.DoAndReturn(f) return c } -// ILoveDemocracy mocks base method. -func (m *MockHelldiverRifleShooter) ILoveDemocracy() { +// Refuel mocks base method. +func (m *MockCar[FuelType]) Refuel(fuel FuelType, volume int) error { m.ctrl.T.Helper() - m.ctrl.Call(m, "ILoveDemocracy") + ret := m.ctrl.Call(m, "Refuel", fuel, volume) + ret0, _ := ret[0].(error) + return ret0 } -// ILoveDemocracy indicates an expected call of ILoveDemocracy. -func (mr *MockHelldiverRifleShooterMockRecorder) ILoveDemocracy() *MockHelldiverRifleShooterILoveDemocracyCall { +// Refuel indicates an expected call of Refuel. +func (mr *MockCarMockRecorder[FuelType]) Refuel(fuel, volume any) *MockCarRefuelCall[FuelType] { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ILoveDemocracy", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).ILoveDemocracy)) - return &MockHelldiverRifleShooterILoveDemocracyCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Refuel", reflect.TypeOf((*MockCar[FuelType])(nil).Refuel), fuel, volume) + return &MockCarRefuelCall[FuelType]{Call: call} } -// MockHelldiverRifleShooterILoveDemocracyCall wrap *gomock.Call -type MockHelldiverRifleShooterILoveDemocracyCall struct { +// MockCarRefuelCall wrap *gomock.Call +type MockCarRefuelCall[FuelType fuel.Fuel] struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockHelldiverRifleShooterILoveDemocracyCall) Return() *MockHelldiverRifleShooterILoveDemocracyCall { - c.Call = c.Call.Return() +func (c *MockCarRefuelCall[FuelType]) Return(arg0 error) *MockCarRefuelCall[FuelType] { + c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockHelldiverRifleShooterILoveDemocracyCall) Do(f func()) *MockHelldiverRifleShooterILoveDemocracyCall { +func (c *MockCarRefuelCall[FuelType]) Do(f func(FuelType, int) error) *MockCarRefuelCall[FuelType] { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRifleShooterILoveDemocracyCall) DoAndReturn(f func()) *MockHelldiverRifleShooterILoveDemocracyCall { +func (c *MockCarRefuelCall[FuelType]) DoAndReturn(f func(FuelType, int) error) *MockCarRefuelCall[FuelType] { c.Call = c.Call.DoAndReturn(f) return c } -// Reload mocks base method. -func (m *MockHelldiverRifleShooter) Reload() bool { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Reload") - ret0, _ := ret[0].(bool) - return ret0 -} - -// Reload indicates an expected call of Reload. -func (mr *MockHelldiverRifleShooterMockRecorder) Reload() *MockHelldiverRifleShooterReloadCall { - mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reload", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).Reload)) - return &MockHelldiverRifleShooterReloadCall{Call: call} +// MockDriver is a mock of Driver interface. +type MockDriver[FuelType fuel.Fuel, CarType import_mode.Car[FuelType]] struct { + ctrl *gomock.Controller + recorder *MockDriverMockRecorder[FuelType, CarType] } -// MockHelldiverRifleShooterReloadCall wrap *gomock.Call -type MockHelldiverRifleShooterReloadCall struct { - *gomock.Call +// MockDriverMockRecorder is the mock recorder for MockDriver. +type MockDriverMockRecorder[FuelType fuel.Fuel, CarType import_mode.Car[FuelType]] struct { + mock *MockDriver[FuelType, CarType] } -// Return rewrite *gomock.Call.Return -func (c *MockHelldiverRifleShooterReloadCall) Return(arg0 bool) *MockHelldiverRifleShooterReloadCall { - c.Call = c.Call.Return(arg0) - return c +// NewMockDriver creates a new mock instance. +func NewMockDriver[FuelType fuel.Fuel, CarType import_mode.Car[FuelType]](ctrl *gomock.Controller) *MockDriver[FuelType, CarType] { + mock := &MockDriver[FuelType, CarType]{ctrl: ctrl} + mock.recorder = &MockDriverMockRecorder[FuelType, CarType]{mock} + return mock } -// Do rewrite *gomock.Call.Do -func (c *MockHelldiverRifleShooterReloadCall) Do(f func() bool) *MockHelldiverRifleShooterReloadCall { - c.Call = c.Call.Do(f) - return c +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockDriver[FuelType, CarType]) EXPECT() *MockDriverMockRecorder[FuelType, CarType] { + return m.recorder } -// DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRifleShooterReloadCall) DoAndReturn(f func() bool) *MockHelldiverRifleShooterReloadCall { - c.Call = c.Call.DoAndReturn(f) - return c +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockDriver[FuelType, CarType]) ISGOMOCK() struct{} { + return struct{}{} } -// Shoot mocks base method. -func (m *MockHelldiverRifleShooter) Shoot(times int, targets ...*import_mode.Enemy) (bool, error) { +// Drive mocks base method. +func (m *MockDriver[FuelType, CarType]) Drive(car CarType) { m.ctrl.T.Helper() - varargs := []any{times} - for _, a := range targets { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Shoot", varargs...) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.Call(m, "Drive", car) } -// Shoot indicates an expected call of Shoot. -func (mr *MockHelldiverRifleShooterMockRecorder) Shoot(times any, targets ...any) *MockHelldiverRifleShooterShootCall { +// Drive indicates an expected call of Drive. +func (mr *MockDriverMockRecorder[FuelType, CarType]) Drive(car any) *MockDriverDriveCall[FuelType, CarType] { mr.mock.ctrl.T.Helper() - varargs := append([]any{times}, targets...) - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shoot", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).Shoot), varargs...) - return &MockHelldiverRifleShooterShootCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Drive", reflect.TypeOf((*MockDriver[FuelType, CarType])(nil).Drive), car) + return &MockDriverDriveCall[FuelType, CarType]{Call: call} } -// MockHelldiverRifleShooterShootCall wrap *gomock.Call -type MockHelldiverRifleShooterShootCall struct { +// MockDriverDriveCall wrap *gomock.Call +type MockDriverDriveCall[FuelType fuel.Fuel, CarType import_mode.Car[FuelType]] struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockHelldiverRifleShooterShootCall) Return(arg0 bool, arg1 error) *MockHelldiverRifleShooterShootCall { - c.Call = c.Call.Return(arg0, arg1) +func (c *MockDriverDriveCall[FuelType, CarType]) Return() *MockDriverDriveCall[FuelType, CarType] { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockHelldiverRifleShooterShootCall) Do(f func(int, ...*import_mode.Enemy) (bool, error)) *MockHelldiverRifleShooterShootCall { +func (c *MockDriverDriveCall[FuelType, CarType]) Do(f func(CarType)) *MockDriverDriveCall[FuelType, CarType] { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRifleShooterShootCall) DoAndReturn(f func(int, ...*import_mode.Enemy) (bool, error)) *MockHelldiverRifleShooterShootCall { +func (c *MockDriverDriveCall[FuelType, CarType]) DoAndReturn(f func(CarType)) *MockDriverDriveCall[FuelType, CarType] { c.Call = c.Call.DoAndReturn(f) return c } -// YouWillNeverDestroyOurWayOfLife mocks base method. -func (m *MockHelldiverRifleShooter) YouWillNeverDestroyOurWayOfLife() { +// Wroom mocks base method. +func (m *MockDriver[FuelType, CarType]) Wroom() error { m.ctrl.T.Helper() - m.ctrl.Call(m, "YouWillNeverDestroyOurWayOfLife") + ret := m.ctrl.Call(m, "Wroom") + ret0, _ := ret[0].(error) + return ret0 } -// YouWillNeverDestroyOurWayOfLife indicates an expected call of YouWillNeverDestroyOurWayOfLife. -func (mr *MockHelldiverRifleShooterMockRecorder) YouWillNeverDestroyOurWayOfLife() *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall { +// Wroom indicates an expected call of Wroom. +func (mr *MockDriverMockRecorder[FuelType, CarType]) Wroom() *MockDriverWroomCall[FuelType, CarType] { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "YouWillNeverDestroyOurWayOfLife", reflect.TypeOf((*MockHelldiverRifleShooter)(nil).YouWillNeverDestroyOurWayOfLife)) - return &MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Wroom", reflect.TypeOf((*MockDriver[FuelType, CarType])(nil).Wroom)) + return &MockDriverWroomCall[FuelType, CarType]{Call: call} } -// MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall wrap *gomock.Call -type MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall struct { +// MockDriverWroomCall wrap *gomock.Call +type MockDriverWroomCall[FuelType fuel.Fuel, CarType import_mode.Car[FuelType]] struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall) Return() *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall { - c.Call = c.Call.Return() +func (c *MockDriverWroomCall[FuelType, CarType]) Return(arg0 error) *MockDriverWroomCall[FuelType, CarType] { + c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall) Do(f func()) *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall { +func (c *MockDriverWroomCall[FuelType, CarType]) Do(f func() error) *MockDriverWroomCall[FuelType, CarType] { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall) DoAndReturn(f func()) *MockHelldiverRifleShooterYouWillNeverDestroyOurWayOfLifeCall { +func (c *MockDriverWroomCall[FuelType, CarType]) DoAndReturn(f func() error) *MockDriverWroomCall[FuelType, CarType] { c.Call = c.Call.DoAndReturn(f) return c } -// MockHelldiverRocketMan is a mock of HelldiverRocketMan interface. -type MockHelldiverRocketMan struct { +// MockUrbanResident is a mock of UrbanResident interface. +type MockUrbanResident struct { ctrl *gomock.Controller - recorder *MockHelldiverRocketManMockRecorder + recorder *MockUrbanResidentMockRecorder } -// MockHelldiverRocketManMockRecorder is the mock recorder for MockHelldiverRocketMan. -type MockHelldiverRocketManMockRecorder struct { - mock *MockHelldiverRocketMan +// MockUrbanResidentMockRecorder is the mock recorder for MockUrbanResident. +type MockUrbanResidentMockRecorder struct { + mock *MockUrbanResident } -// NewMockHelldiverRocketMan creates a new mock instance. -func NewMockHelldiverRocketMan(ctrl *gomock.Controller) *MockHelldiverRocketMan { - mock := &MockHelldiverRocketMan{ctrl: ctrl} - mock.recorder = &MockHelldiverRocketManMockRecorder{mock} +// NewMockUrbanResident creates a new mock instance. +func NewMockUrbanResident(ctrl *gomock.Controller) *MockUrbanResident { + mock := &MockUrbanResident{ctrl: ctrl} + mock.recorder = &MockUrbanResidentMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockHelldiverRocketMan) EXPECT() *MockHelldiverRocketManMockRecorder { +func (m *MockUrbanResident) EXPECT() *MockUrbanResidentMockRecorder { return m.recorder } // ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockHelldiverRocketMan) ISGOMOCK() struct{} { +func (m *MockUrbanResident) ISGOMOCK() struct{} { return struct{}{} } -// AvailableStratagems mocks base method. -func (m *MockHelldiverRocketMan) AvailableStratagems() []stratagems.Stratagem { +// Breathe mocks base method. +func (m *MockUrbanResident) Breathe() { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AvailableStratagems") - ret0, _ := ret[0].([]stratagems.Stratagem) - return ret0 + m.ctrl.Call(m, "Breathe") } -// AvailableStratagems indicates an expected call of AvailableStratagems. -func (mr *MockHelldiverRocketManMockRecorder) AvailableStratagems() *MockHelldiverRocketManAvailableStratagemsCall { +// Breathe indicates an expected call of Breathe. +func (mr *MockUrbanResidentMockRecorder) Breathe() *MockUrbanResidentBreatheCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AvailableStratagems", reflect.TypeOf((*MockHelldiverRocketMan)(nil).AvailableStratagems)) - return &MockHelldiverRocketManAvailableStratagemsCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Breathe", reflect.TypeOf((*MockUrbanResident)(nil).Breathe)) + return &MockUrbanResidentBreatheCall{Call: call} } -// MockHelldiverRocketManAvailableStratagemsCall wrap *gomock.Call -type MockHelldiverRocketManAvailableStratagemsCall struct { +// MockUrbanResidentBreatheCall wrap *gomock.Call +type MockUrbanResidentBreatheCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockHelldiverRocketManAvailableStratagemsCall) Return(arg0 []stratagems.Stratagem) *MockHelldiverRocketManAvailableStratagemsCall { - c.Call = c.Call.Return(arg0) +func (c *MockUrbanResidentBreatheCall) Return() *MockUrbanResidentBreatheCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockHelldiverRocketManAvailableStratagemsCall) Do(f func() []stratagems.Stratagem) *MockHelldiverRocketManAvailableStratagemsCall { +func (c *MockUrbanResidentBreatheCall) Do(f func()) *MockUrbanResidentBreatheCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRocketManAvailableStratagemsCall) DoAndReturn(f func() []stratagems.Stratagem) *MockHelldiverRocketManAvailableStratagemsCall { +func (c *MockUrbanResidentBreatheCall) DoAndReturn(f func()) *MockUrbanResidentBreatheCall { c.Call = c.Call.DoAndReturn(f) return c } -// Gun mocks base method. -func (m *MockHelldiverRocketMan) Gun() *guns.RocketLauncher { +// Do mocks base method. +func (m *MockUrbanResident) Do(work *import_mode.Work) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Gun") - ret0, _ := ret[0].(*guns.RocketLauncher) + ret := m.ctrl.Call(m, "Do", work) + ret0, _ := ret[0].(error) return ret0 } -// Gun indicates an expected call of Gun. -func (mr *MockHelldiverRocketManMockRecorder) Gun() *MockHelldiverRocketManGunCall { +// Do indicates an expected call of Do. +func (mr *MockUrbanResidentMockRecorder) Do(work any) *MockUrbanResidentDoCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Gun", reflect.TypeOf((*MockHelldiverRocketMan)(nil).Gun)) - return &MockHelldiverRocketManGunCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Do", reflect.TypeOf((*MockUrbanResident)(nil).Do), work) + return &MockUrbanResidentDoCall{Call: call} } -// MockHelldiverRocketManGunCall wrap *gomock.Call -type MockHelldiverRocketManGunCall struct { +// MockUrbanResidentDoCall wrap *gomock.Call +type MockUrbanResidentDoCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockHelldiverRocketManGunCall) Return(arg0 *guns.RocketLauncher) *MockHelldiverRocketManGunCall { +func (c *MockUrbanResidentDoCall) Return(arg0 error) *MockUrbanResidentDoCall { c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockHelldiverRocketManGunCall) Do(f func() *guns.RocketLauncher) *MockHelldiverRocketManGunCall { +func (c *MockUrbanResidentDoCall) Do(f func(*import_mode.Work) error) *MockUrbanResidentDoCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRocketManGunCall) DoAndReturn(f func() *guns.RocketLauncher) *MockHelldiverRocketManGunCall { +func (c *MockUrbanResidentDoCall) DoAndReturn(f func(*import_mode.Work) error) *MockUrbanResidentDoCall { c.Call = c.Call.DoAndReturn(f) return c } -// ILoveDemocracy mocks base method. -func (m *MockHelldiverRocketMan) ILoveDemocracy() { +// Drive mocks base method. +func (m *MockUrbanResident) Drive(car cars.HyundaiSolaris) { m.ctrl.T.Helper() - m.ctrl.Call(m, "ILoveDemocracy") + m.ctrl.Call(m, "Drive", car) } -// ILoveDemocracy indicates an expected call of ILoveDemocracy. -func (mr *MockHelldiverRocketManMockRecorder) ILoveDemocracy() *MockHelldiverRocketManILoveDemocracyCall { +// Drive indicates an expected call of Drive. +func (mr *MockUrbanResidentMockRecorder) Drive(car any) *MockUrbanResidentDriveCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ILoveDemocracy", reflect.TypeOf((*MockHelldiverRocketMan)(nil).ILoveDemocracy)) - return &MockHelldiverRocketManILoveDemocracyCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Drive", reflect.TypeOf((*MockUrbanResident)(nil).Drive), car) + return &MockUrbanResidentDriveCall{Call: call} } -// MockHelldiverRocketManILoveDemocracyCall wrap *gomock.Call -type MockHelldiverRocketManILoveDemocracyCall struct { +// MockUrbanResidentDriveCall wrap *gomock.Call +type MockUrbanResidentDriveCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockHelldiverRocketManILoveDemocracyCall) Return() *MockHelldiverRocketManILoveDemocracyCall { +func (c *MockUrbanResidentDriveCall) Return() *MockUrbanResidentDriveCall { c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockHelldiverRocketManILoveDemocracyCall) Do(f func()) *MockHelldiverRocketManILoveDemocracyCall { +func (c *MockUrbanResidentDriveCall) Do(f func(cars.HyundaiSolaris)) *MockUrbanResidentDriveCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRocketManILoveDemocracyCall) DoAndReturn(f func()) *MockHelldiverRocketManILoveDemocracyCall { +func (c *MockUrbanResidentDriveCall) DoAndReturn(f func(cars.HyundaiSolaris)) *MockUrbanResidentDriveCall { c.Call = c.Call.DoAndReturn(f) return c } -// Reload mocks base method. -func (m *MockHelldiverRocketMan) Reload() bool { +// Eat mocks base method. +func (m *MockUrbanResident) Eat(foods ...import_mode.Food) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Reload") - ret0, _ := ret[0].(bool) - return ret0 + varargs := []any{} + for _, a := range foods { + varargs = append(varargs, a) + } + m.ctrl.Call(m, "Eat", varargs...) } -// Reload indicates an expected call of Reload. -func (mr *MockHelldiverRocketManMockRecorder) Reload() *MockHelldiverRocketManReloadCall { +// Eat indicates an expected call of Eat. +func (mr *MockUrbanResidentMockRecorder) Eat(foods ...any) *MockUrbanResidentEatCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reload", reflect.TypeOf((*MockHelldiverRocketMan)(nil).Reload)) - return &MockHelldiverRocketManReloadCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eat", reflect.TypeOf((*MockUrbanResident)(nil).Eat), foods...) + return &MockUrbanResidentEatCall{Call: call} } -// MockHelldiverRocketManReloadCall wrap *gomock.Call -type MockHelldiverRocketManReloadCall struct { +// MockUrbanResidentEatCall wrap *gomock.Call +type MockUrbanResidentEatCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockHelldiverRocketManReloadCall) Return(arg0 bool) *MockHelldiverRocketManReloadCall { - c.Call = c.Call.Return(arg0) +func (c *MockUrbanResidentEatCall) Return() *MockUrbanResidentEatCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockHelldiverRocketManReloadCall) Do(f func() bool) *MockHelldiverRocketManReloadCall { +func (c *MockUrbanResidentEatCall) Do(f func(...import_mode.Food)) *MockUrbanResidentEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRocketManReloadCall) DoAndReturn(f func() bool) *MockHelldiverRocketManReloadCall { +func (c *MockUrbanResidentEatCall) DoAndReturn(f func(...import_mode.Food)) *MockUrbanResidentEatCall { c.Call = c.Call.DoAndReturn(f) return c } -// Shoot mocks base method. -func (m *MockHelldiverRocketMan) Shoot(times int, targets ...*import_mode.Enemy) (bool, error) { +// LivesInACity mocks base method. +func (m *MockUrbanResident) LivesInACity() { m.ctrl.T.Helper() - varargs := []any{times} - for _, a := range targets { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Shoot", varargs...) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.Call(m, "LivesInACity") } -// Shoot indicates an expected call of Shoot. -func (mr *MockHelldiverRocketManMockRecorder) Shoot(times any, targets ...any) *MockHelldiverRocketManShootCall { +// LivesInACity indicates an expected call of LivesInACity. +func (mr *MockUrbanResidentMockRecorder) LivesInACity() *MockUrbanResidentLivesInACityCall { mr.mock.ctrl.T.Helper() - varargs := append([]any{times}, targets...) - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shoot", reflect.TypeOf((*MockHelldiverRocketMan)(nil).Shoot), varargs...) - return &MockHelldiverRocketManShootCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LivesInACity", reflect.TypeOf((*MockUrbanResident)(nil).LivesInACity)) + return &MockUrbanResidentLivesInACityCall{Call: call} } -// MockHelldiverRocketManShootCall wrap *gomock.Call -type MockHelldiverRocketManShootCall struct { +// MockUrbanResidentLivesInACityCall wrap *gomock.Call +type MockUrbanResidentLivesInACityCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockHelldiverRocketManShootCall) Return(arg0 bool, arg1 error) *MockHelldiverRocketManShootCall { - c.Call = c.Call.Return(arg0, arg1) +func (c *MockUrbanResidentLivesInACityCall) Return() *MockUrbanResidentLivesInACityCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockHelldiverRocketManShootCall) Do(f func(int, ...*import_mode.Enemy) (bool, error)) *MockHelldiverRocketManShootCall { +func (c *MockUrbanResidentLivesInACityCall) Do(f func()) *MockUrbanResidentLivesInACityCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRocketManShootCall) DoAndReturn(f func(int, ...*import_mode.Enemy) (bool, error)) *MockHelldiverRocketManShootCall { +func (c *MockUrbanResidentLivesInACityCall) DoAndReturn(f func()) *MockUrbanResidentLivesInACityCall { c.Call = c.Call.DoAndReturn(f) return c } -// YouWillNeverDestroyOurWayOfLife mocks base method. -func (m *MockHelldiverRocketMan) YouWillNeverDestroyOurWayOfLife() { +// Sleep mocks base method. +func (m *MockUrbanResident) Sleep(duration time.Duration) { m.ctrl.T.Helper() - m.ctrl.Call(m, "YouWillNeverDestroyOurWayOfLife") + m.ctrl.Call(m, "Sleep", duration) } -// YouWillNeverDestroyOurWayOfLife indicates an expected call of YouWillNeverDestroyOurWayOfLife. -func (mr *MockHelldiverRocketManMockRecorder) YouWillNeverDestroyOurWayOfLife() *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall { +// Sleep indicates an expected call of Sleep. +func (mr *MockUrbanResidentMockRecorder) Sleep(duration any) *MockUrbanResidentSleepCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "YouWillNeverDestroyOurWayOfLife", reflect.TypeOf((*MockHelldiverRocketMan)(nil).YouWillNeverDestroyOurWayOfLife)) - return &MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sleep", reflect.TypeOf((*MockUrbanResident)(nil).Sleep), duration) + return &MockUrbanResidentSleepCall{Call: call} } -// MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall wrap *gomock.Call -type MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall struct { +// MockUrbanResidentSleepCall wrap *gomock.Call +type MockUrbanResidentSleepCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall) Return() *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall { +func (c *MockUrbanResidentSleepCall) Return() *MockUrbanResidentSleepCall { c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall) Do(f func()) *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall { +func (c *MockUrbanResidentSleepCall) Do(f func(time.Duration)) *MockUrbanResidentSleepCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockUrbanResidentSleepCall) DoAndReturn(f func(time.Duration)) *MockUrbanResidentSleepCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// Wroom mocks base method. +func (m *MockUrbanResident) Wroom() error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Wroom") + ret0, _ := ret[0].(error) + return ret0 +} + +// Wroom indicates an expected call of Wroom. +func (mr *MockUrbanResidentMockRecorder) Wroom() *MockUrbanResidentWroomCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Wroom", reflect.TypeOf((*MockUrbanResident)(nil).Wroom)) + return &MockUrbanResidentWroomCall{Call: call} +} + +// MockUrbanResidentWroomCall wrap *gomock.Call +type MockUrbanResidentWroomCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockUrbanResidentWroomCall) Return(arg0 error) *MockUrbanResidentWroomCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockUrbanResidentWroomCall) Do(f func() error) *MockUrbanResidentWroomCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall) DoAndReturn(f func()) *MockHelldiverRocketManYouWillNeverDestroyOurWayOfLifeCall { +func (c *MockUrbanResidentWroomCall) DoAndReturn(f func() error) *MockUrbanResidentWroomCall { c.Call = c.Call.DoAndReturn(f) return c } -// MockPotentialTraitor is a mock of PotentialTraitor interface. -type MockPotentialTraitor struct { +// MockFarmer is a mock of Farmer interface. +type MockFarmer struct { ctrl *gomock.Controller - recorder *MockPotentialTraitorMockRecorder + recorder *MockFarmerMockRecorder } -// MockPotentialTraitorMockRecorder is the mock recorder for MockPotentialTraitor. -type MockPotentialTraitorMockRecorder struct { - mock *MockPotentialTraitor +// MockFarmerMockRecorder is the mock recorder for MockFarmer. +type MockFarmerMockRecorder struct { + mock *MockFarmer } -// NewMockPotentialTraitor creates a new mock instance. -func NewMockPotentialTraitor(ctrl *gomock.Controller) *MockPotentialTraitor { - mock := &MockPotentialTraitor{ctrl: ctrl} - mock.recorder = &MockPotentialTraitorMockRecorder{mock} +// NewMockFarmer creates a new mock instance. +func NewMockFarmer(ctrl *gomock.Controller) *MockFarmer { + mock := &MockFarmer{ctrl: ctrl} + mock.recorder = &MockFarmerMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockPotentialTraitor) EXPECT() *MockPotentialTraitorMockRecorder { +func (m *MockFarmer) EXPECT() *MockFarmerMockRecorder { return m.recorder } // ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockPotentialTraitor) ISGOMOCK() struct{} { +func (m *MockFarmer) ISGOMOCK() struct{} { return struct{}{} } -// AvailableStratagems mocks base method. -func (m *MockPotentialTraitor) AvailableStratagems() []stratagems.Stratagem { +// Breathe mocks base method. +func (m *MockFarmer) Breathe() { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "AvailableStratagems") - ret0, _ := ret[0].([]stratagems.Stratagem) - return ret0 + m.ctrl.Call(m, "Breathe") } -// AvailableStratagems indicates an expected call of AvailableStratagems. -func (mr *MockPotentialTraitorMockRecorder) AvailableStratagems() *MockPotentialTraitorAvailableStratagemsCall { +// Breathe indicates an expected call of Breathe. +func (mr *MockFarmerMockRecorder) Breathe() *MockFarmerBreatheCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AvailableStratagems", reflect.TypeOf((*MockPotentialTraitor)(nil).AvailableStratagems)) - return &MockPotentialTraitorAvailableStratagemsCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Breathe", reflect.TypeOf((*MockFarmer)(nil).Breathe)) + return &MockFarmerBreatheCall{Call: call} } -// MockPotentialTraitorAvailableStratagemsCall wrap *gomock.Call -type MockPotentialTraitorAvailableStratagemsCall struct { +// MockFarmerBreatheCall wrap *gomock.Call +type MockFarmerBreatheCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockPotentialTraitorAvailableStratagemsCall) Return(arg0 []stratagems.Stratagem) *MockPotentialTraitorAvailableStratagemsCall { - c.Call = c.Call.Return(arg0) +func (c *MockFarmerBreatheCall) Return() *MockFarmerBreatheCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockPotentialTraitorAvailableStratagemsCall) Do(f func() []stratagems.Stratagem) *MockPotentialTraitorAvailableStratagemsCall { +func (c *MockFarmerBreatheCall) Do(f func()) *MockFarmerBreatheCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockPotentialTraitorAvailableStratagemsCall) DoAndReturn(f func() []stratagems.Stratagem) *MockPotentialTraitorAvailableStratagemsCall { +func (c *MockFarmerBreatheCall) DoAndReturn(f func()) *MockFarmerBreatheCall { c.Call = c.Call.DoAndReturn(f) return c } -// Gun mocks base method. -func (m *MockPotentialTraitor) Gun() *guns.Rifle { +// Do mocks base method. +func (m *MockFarmer) Do(work *import_mode.Work) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Gun") - ret0, _ := ret[0].(*guns.Rifle) + ret := m.ctrl.Call(m, "Do", work) + ret0, _ := ret[0].(error) return ret0 } -// Gun indicates an expected call of Gun. -func (mr *MockPotentialTraitorMockRecorder) Gun() *MockPotentialTraitorGunCall { +// Do indicates an expected call of Do. +func (mr *MockFarmerMockRecorder) Do(work any) *MockFarmerDoCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Gun", reflect.TypeOf((*MockPotentialTraitor)(nil).Gun)) - return &MockPotentialTraitorGunCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Do", reflect.TypeOf((*MockFarmer)(nil).Do), work) + return &MockFarmerDoCall{Call: call} } -// MockPotentialTraitorGunCall wrap *gomock.Call -type MockPotentialTraitorGunCall struct { +// MockFarmerDoCall wrap *gomock.Call +type MockFarmerDoCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockPotentialTraitorGunCall) Return(arg0 *guns.Rifle) *MockPotentialTraitorGunCall { +func (c *MockFarmerDoCall) Return(arg0 error) *MockFarmerDoCall { c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockPotentialTraitorGunCall) Do(f func() *guns.Rifle) *MockPotentialTraitorGunCall { +func (c *MockFarmerDoCall) Do(f func(*import_mode.Work) error) *MockFarmerDoCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockPotentialTraitorGunCall) DoAndReturn(f func() *guns.Rifle) *MockPotentialTraitorGunCall { +func (c *MockFarmerDoCall) DoAndReturn(f func(*import_mode.Work) error) *MockFarmerDoCall { c.Call = c.Call.DoAndReturn(f) return c } -// Reload mocks base method. -func (m *MockPotentialTraitor) Reload() bool { +// Drive mocks base method. +func (m *MockFarmer) Drive(car cars.FordF150) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Reload") - ret0, _ := ret[0].(bool) - return ret0 + m.ctrl.Call(m, "Drive", car) } -// Reload indicates an expected call of Reload. -func (mr *MockPotentialTraitorMockRecorder) Reload() *MockPotentialTraitorReloadCall { +// Drive indicates an expected call of Drive. +func (mr *MockFarmerMockRecorder) Drive(car any) *MockFarmerDriveCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reload", reflect.TypeOf((*MockPotentialTraitor)(nil).Reload)) - return &MockPotentialTraitorReloadCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Drive", reflect.TypeOf((*MockFarmer)(nil).Drive), car) + return &MockFarmerDriveCall{Call: call} } -// MockPotentialTraitorReloadCall wrap *gomock.Call -type MockPotentialTraitorReloadCall struct { +// MockFarmerDriveCall wrap *gomock.Call +type MockFarmerDriveCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockPotentialTraitorReloadCall) Return(arg0 bool) *MockPotentialTraitorReloadCall { - c.Call = c.Call.Return(arg0) +func (c *MockFarmerDriveCall) Return() *MockFarmerDriveCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockPotentialTraitorReloadCall) Do(f func() bool) *MockPotentialTraitorReloadCall { +func (c *MockFarmerDriveCall) Do(f func(cars.FordF150)) *MockFarmerDriveCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockPotentialTraitorReloadCall) DoAndReturn(f func() bool) *MockPotentialTraitorReloadCall { +func (c *MockFarmerDriveCall) DoAndReturn(f func(cars.FordF150)) *MockFarmerDriveCall { c.Call = c.Call.DoAndReturn(f) return c } -// Shoot mocks base method. -func (m *MockPotentialTraitor) Shoot(times int, targets ...*import_mode.Enemy) (bool, error) { +// Eat mocks base method. +func (m *MockFarmer) Eat(foods ...import_mode.Food) { m.ctrl.T.Helper() - varargs := []any{times} - for _, a := range targets { + varargs := []any{} + for _, a := range foods { varargs = append(varargs, a) } - ret := m.ctrl.Call(m, "Shoot", varargs...) - ret0, _ := ret[0].(bool) - ret1, _ := ret[1].(error) - return ret0, ret1 + m.ctrl.Call(m, "Eat", varargs...) } -// Shoot indicates an expected call of Shoot. -func (mr *MockPotentialTraitorMockRecorder) Shoot(times any, targets ...any) *MockPotentialTraitorShootCall { +// Eat indicates an expected call of Eat. +func (mr *MockFarmerMockRecorder) Eat(foods ...any) *MockFarmerEatCall { mr.mock.ctrl.T.Helper() - varargs := append([]any{times}, targets...) - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Shoot", reflect.TypeOf((*MockPotentialTraitor)(nil).Shoot), varargs...) - return &MockPotentialTraitorShootCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eat", reflect.TypeOf((*MockFarmer)(nil).Eat), foods...) + return &MockFarmerEatCall{Call: call} } -// MockPotentialTraitorShootCall wrap *gomock.Call -type MockPotentialTraitorShootCall struct { +// MockFarmerEatCall wrap *gomock.Call +type MockFarmerEatCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockPotentialTraitorShootCall) Return(arg0 bool, arg1 error) *MockPotentialTraitorShootCall { - c.Call = c.Call.Return(arg0, arg1) +func (c *MockFarmerEatCall) Return() *MockFarmerEatCall { + c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockPotentialTraitorShootCall) Do(f func(int, ...*import_mode.Enemy) (bool, error)) *MockPotentialTraitorShootCall { +func (c *MockFarmerEatCall) Do(f func(...import_mode.Food)) *MockFarmerEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockPotentialTraitorShootCall) DoAndReturn(f func(int, ...*import_mode.Enemy) (bool, error)) *MockPotentialTraitorShootCall { +func (c *MockFarmerEatCall) DoAndReturn(f func(...import_mode.Food)) *MockFarmerEatCall { c.Call = c.Call.DoAndReturn(f) return c } -// MockAgitationCampaign is a mock of AgitationCampaign interface. -type MockAgitationCampaign struct { - ctrl *gomock.Controller - recorder *MockAgitationCampaignMockRecorder +// LivesInAVillage mocks base method. +func (m *MockFarmer) LivesInAVillage() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "LivesInAVillage") } -// MockAgitationCampaignMockRecorder is the mock recorder for MockAgitationCampaign. -type MockAgitationCampaignMockRecorder struct { - mock *MockAgitationCampaign +// LivesInAVillage indicates an expected call of LivesInAVillage. +func (mr *MockFarmerMockRecorder) LivesInAVillage() *MockFarmerLivesInAVillageCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LivesInAVillage", reflect.TypeOf((*MockFarmer)(nil).LivesInAVillage)) + return &MockFarmerLivesInAVillageCall{Call: call} } -// NewMockAgitationCampaign creates a new mock instance. -func NewMockAgitationCampaign(ctrl *gomock.Controller) *MockAgitationCampaign { - mock := &MockAgitationCampaign{ctrl: ctrl} - mock.recorder = &MockAgitationCampaignMockRecorder{mock} - return mock +// MockFarmerLivesInAVillageCall wrap *gomock.Call +type MockFarmerLivesInAVillageCall struct { + *gomock.Call } -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockAgitationCampaign) EXPECT() *MockAgitationCampaignMockRecorder { - return m.recorder +// Return rewrite *gomock.Call.Return +func (c *MockFarmerLivesInAVillageCall) Return() *MockFarmerLivesInAVillageCall { + c.Call = c.Call.Return() + return c } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockAgitationCampaign) ISGOMOCK() struct{} { - return struct{}{} +// Do rewrite *gomock.Call.Do +func (c *MockFarmerLivesInAVillageCall) Do(f func()) *MockFarmerLivesInAVillageCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockFarmerLivesInAVillageCall) DoAndReturn(f func()) *MockFarmerLivesInAVillageCall { + c.Call = c.Call.DoAndReturn(f) + return c } -// BecomeAHelldiver mocks base method. -func (m *MockAgitationCampaign) BecomeAHelldiver() { +// Sleep mocks base method. +func (m *MockFarmer) Sleep(duration time.Duration) { m.ctrl.T.Helper() - m.ctrl.Call(m, "BecomeAHelldiver") + m.ctrl.Call(m, "Sleep", duration) } -// BecomeAHelldiver indicates an expected call of BecomeAHelldiver. -func (mr *MockAgitationCampaignMockRecorder) BecomeAHelldiver() *MockAgitationCampaignBecomeAHelldiverCall { +// Sleep indicates an expected call of Sleep. +func (mr *MockFarmerMockRecorder) Sleep(duration any) *MockFarmerSleepCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BecomeAHelldiver", reflect.TypeOf((*MockAgitationCampaign)(nil).BecomeAHelldiver)) - return &MockAgitationCampaignBecomeAHelldiverCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sleep", reflect.TypeOf((*MockFarmer)(nil).Sleep), duration) + return &MockFarmerSleepCall{Call: call} } -// MockAgitationCampaignBecomeAHelldiverCall wrap *gomock.Call -type MockAgitationCampaignBecomeAHelldiverCall struct { +// MockFarmerSleepCall wrap *gomock.Call +type MockFarmerSleepCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockAgitationCampaignBecomeAHelldiverCall) Return() *MockAgitationCampaignBecomeAHelldiverCall { +func (c *MockFarmerSleepCall) Return() *MockFarmerSleepCall { c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockAgitationCampaignBecomeAHelldiverCall) Do(f func()) *MockAgitationCampaignBecomeAHelldiverCall { +func (c *MockFarmerSleepCall) Do(f func(time.Duration)) *MockFarmerSleepCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockAgitationCampaignBecomeAHelldiverCall) DoAndReturn(f func()) *MockAgitationCampaignBecomeAHelldiverCall { +func (c *MockFarmerSleepCall) DoAndReturn(f func(time.Duration)) *MockFarmerSleepCall { c.Call = c.Call.DoAndReturn(f) return c } -// BecomeAHero mocks base method. -func (m *MockAgitationCampaign) BecomeAHero() { +// Wroom mocks base method. +func (m *MockFarmer) Wroom() error { m.ctrl.T.Helper() - m.ctrl.Call(m, "BecomeAHero") + ret := m.ctrl.Call(m, "Wroom") + ret0, _ := ret[0].(error) + return ret0 } -// BecomeAHero indicates an expected call of BecomeAHero. -func (mr *MockAgitationCampaignMockRecorder) BecomeAHero() *MockAgitationCampaignBecomeAHeroCall { +// Wroom indicates an expected call of Wroom. +func (mr *MockFarmerMockRecorder) Wroom() *MockFarmerWroomCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BecomeAHero", reflect.TypeOf((*MockAgitationCampaign)(nil).BecomeAHero)) - return &MockAgitationCampaignBecomeAHeroCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Wroom", reflect.TypeOf((*MockFarmer)(nil).Wroom)) + return &MockFarmerWroomCall{Call: call} } -// MockAgitationCampaignBecomeAHeroCall wrap *gomock.Call -type MockAgitationCampaignBecomeAHeroCall struct { +// MockFarmerWroomCall wrap *gomock.Call +type MockFarmerWroomCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockAgitationCampaignBecomeAHeroCall) Return() *MockAgitationCampaignBecomeAHeroCall { - c.Call = c.Call.Return() +func (c *MockFarmerWroomCall) Return(arg0 error) *MockFarmerWroomCall { + c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockAgitationCampaignBecomeAHeroCall) Do(f func()) *MockAgitationCampaignBecomeAHeroCall { +func (c *MockFarmerWroomCall) Do(f func() error) *MockFarmerWroomCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockAgitationCampaignBecomeAHeroCall) DoAndReturn(f func()) *MockAgitationCampaignBecomeAHeroCall { +func (c *MockFarmerWroomCall) DoAndReturn(f func() error) *MockFarmerWroomCall { c.Call = c.Call.DoAndReturn(f) return c } -// BecomeALegend mocks base method. -func (m *MockAgitationCampaign) BecomeALegend() { +// MockPromotionCampaign is a mock of PromotionCampaign interface. +type MockPromotionCampaign struct { + ctrl *gomock.Controller + recorder *MockPromotionCampaignMockRecorder +} + +// MockPromotionCampaignMockRecorder is the mock recorder for MockPromotionCampaign. +type MockPromotionCampaignMockRecorder struct { + mock *MockPromotionCampaign +} + +// NewMockPromotionCampaign creates a new mock instance. +func NewMockPromotionCampaign(ctrl *gomock.Controller) *MockPromotionCampaign { + mock := &MockPromotionCampaign{ctrl: ctrl} + mock.recorder = &MockPromotionCampaignMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockPromotionCampaign) EXPECT() *MockPromotionCampaignMockRecorder { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockPromotionCampaign) ISGOMOCK() struct{} { + return struct{}{} +} + +// YouMustBuyOurCar mocks base method. +func (m *MockPromotionCampaign) YouMustBuyOurCar() { m.ctrl.T.Helper() - m.ctrl.Call(m, "BecomeALegend") + m.ctrl.Call(m, "YouMustBuyOurCar") } -// BecomeALegend indicates an expected call of BecomeALegend. -func (mr *MockAgitationCampaignMockRecorder) BecomeALegend() *MockAgitationCampaignBecomeALegendCall { +// YouMustBuyOurCar indicates an expected call of YouMustBuyOurCar. +func (mr *MockPromotionCampaignMockRecorder) YouMustBuyOurCar() *MockPromotionCampaignYouMustBuyOurCarCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BecomeALegend", reflect.TypeOf((*MockAgitationCampaign)(nil).BecomeALegend)) - return &MockAgitationCampaignBecomeALegendCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "YouMustBuyOurCar", reflect.TypeOf((*MockPromotionCampaign)(nil).YouMustBuyOurCar)) + return &MockPromotionCampaignYouMustBuyOurCarCall{Call: call} } -// MockAgitationCampaignBecomeALegendCall wrap *gomock.Call -type MockAgitationCampaignBecomeALegendCall struct { +// MockPromotionCampaignYouMustBuyOurCarCall wrap *gomock.Call +type MockPromotionCampaignYouMustBuyOurCarCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockAgitationCampaignBecomeALegendCall) Return() *MockAgitationCampaignBecomeALegendCall { +func (c *MockPromotionCampaignYouMustBuyOurCarCall) Return() *MockPromotionCampaignYouMustBuyOurCarCall { c.Call = c.Call.Return() return c } // Do rewrite *gomock.Call.Do -func (c *MockAgitationCampaignBecomeALegendCall) Do(f func()) *MockAgitationCampaignBecomeALegendCall { +func (c *MockPromotionCampaignYouMustBuyOurCarCall) Do(f func()) *MockPromotionCampaignYouMustBuyOurCarCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockAgitationCampaignBecomeALegendCall) DoAndReturn(f func()) *MockAgitationCampaignBecomeALegendCall { +func (c *MockPromotionCampaignYouMustBuyOurCarCall) DoAndReturn(f func()) *MockPromotionCampaignYouMustBuyOurCarCall { c.Call = c.Call.DoAndReturn(f) return c } diff --git a/mockgen/internal/tests/import_mode/mock/interfaces_test.go b/mockgen/internal/tests/import_mode/mock/interfaces_test.go new file mode 100644 index 0000000..2d4a8ef --- /dev/null +++ b/mockgen/internal/tests/import_mode/mock/interfaces_test.go @@ -0,0 +1,41 @@ +package mock + +import ( + "testing" + + "go.uber.org/mock/gomock" + "go.uber.org/mock/mockgen/internal/tests/import_mode" + "go.uber.org/mock/mockgen/internal/tests/import_mode/cars" + "go.uber.org/mock/mockgen/internal/tests/import_mode/fuel" +) + +// checks, that mocks implement interfaces in compile-time. +// If something breaks, the tests will not be compiled. + +var food import_mode.Food = &MockFood{} + +var eater import_mode.Eater = &MockEater{} + +var animal import_mode.Animal = &MockAnimal{} + +var human import_mode.Human = &MockHuman{} + +var primate import_mode.Primate = &MockPrimate{} + +var car import_mode.Car[fuel.Gasoline] = &MockCar[fuel.Gasoline]{} + +var driver import_mode.Driver[fuel.Gasoline, cars.HyundaiSolaris] = &MockDriver[fuel.Gasoline, cars.HyundaiSolaris]{} + +var urbanResident import_mode.UrbanResident = &MockUrbanResident{} + +var farmer import_mode.Farmer = &MockFarmer{} + +func TestInterfaces(t *testing.T) { + ctrl := gomock.NewController(t) + + mock := NewMockFarmer(ctrl) + mock.EXPECT().Breathe() + + farmer := import_mode.Farmer(mock) + farmer.Breathe() +} diff --git a/mockgen/internal/tests/import_mode/projectiles/projectiles.go b/mockgen/internal/tests/import_mode/projectiles/projectiles.go deleted file mode 100644 index 5942230..0000000 --- a/mockgen/internal/tests/import_mode/projectiles/projectiles.go +++ /dev/null @@ -1,30 +0,0 @@ -package projectiles - -type Bullet struct{} - -func (b Bullet) Speed() int { - return 600 -} - -func (b Bullet) FlightRange() int { - return 500 -} - -func (b Bullet) Explosive() bool { - return false -} - -type Missle struct { -} - -func (m Missle) Speed() int { - return 200 -} - -func (m Missle) FlightRange() int { - return 800 -} - -func (m Missle) Explosive() bool { - return true -} diff --git a/mockgen/internal/tests/import_mode/stratagems/interfaces.go b/mockgen/internal/tests/import_mode/stratagems/interfaces.go deleted file mode 100644 index 65c6088..0000000 --- a/mockgen/internal/tests/import_mode/stratagems/interfaces.go +++ /dev/null @@ -1,14 +0,0 @@ -package stratagems - -import ( - "time" -) - -type Stratagem interface { - Call() error - Timeout() time.Duration -} - -type StratagemCarrier interface { - AvailableStratagems() []Stratagem -} From 0643be93f513d9953f75356bba744061d61e6fa3 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Wed, 28 Aug 2024 20:47:04 +0300 Subject: [PATCH 03/16] review changes: * added detailed parsing error * error more succinct * removed call of iface.Complete() * renamed checkInterfaceIsNotConstraint -> isConstraint * reduced nesting at parse named segment * add_generate_directive test fixed after I accidentally changed it early --- mockgen/import_mode.go | 102 +++++++++++------- mockgen/import_mode_test.go | 10 +- .../tests/add_generate_directive/mock.go | 4 +- .../internal/tests/import_mode/interfaces.go | 2 +- .../tests/import_mode/mock/interfaces.go | 68 +----------- 5 files changed, 74 insertions(+), 112 deletions(-) diff --git a/mockgen/import_mode.go b/mockgen/import_mode.go index 9298cb6..8b519c1 100644 --- a/mockgen/import_mode.go +++ b/mockgen/import_mode.go @@ -20,12 +20,12 @@ func (p *importModeParser) parsePackage(packageName string, ifaces []string) (*m pkg, err := p.loadPackage(packageName) if err != nil { - return nil, fmt.Errorf("failed to load package: %w", err) + return nil, fmt.Errorf("load package: %w", err) } interfaces, err := p.extractInterfacesFromPackage(pkg, ifaces) if err != nil { - return nil, fmt.Errorf("failed to extract interfaces from package: %w", err) + return nil, fmt.Errorf("extract interfaces from package: %w", err) } return &model.Package{ @@ -47,13 +47,13 @@ func (p *importModeParser) loadPackage(packageName string) (*packages.Package, e dirName := "mockgen_" + p.generateSalt() err := os.Mkdir(dirName, 0755) if err != nil { - return nil, fmt.Errorf("failed to create temp dir for fake package: %w", err) + return nil, fmt.Errorf("create temp dir for fake package: %w", err) } defer os.RemoveAll(dirName) err = os.WriteFile(dirName+"/main.go", []byte(fmt.Sprintf(fakeFileTemplate, packageName)), 0666) if err != nil { - return nil, fmt.Errorf("failed to write fake main.go: %w", err) + return nil, fmt.Errorf("write fake main.go: %w", err) } fileSet := token.NewFileSet() @@ -65,7 +65,7 @@ func (p *importModeParser) loadPackage(packageName string) (*packages.Package, e } pkgs, err := packages.Load(cfg) if err != nil { - return nil, fmt.Errorf("failed to load packages: %w", err) + return nil, fmt.Errorf("load packages: %w", err) } if len(pkgs) != 1 { @@ -102,7 +102,7 @@ func (p *importModeParser) extractInterfacesFromPackage(pkg *packages.Package, i modelIface, err := p.parseInterface(obj) if err != nil { - return nil, fmt.Errorf("failed to parse interface: %w", err) + return nil, newParseTypeError("parse interface", obj.String(), err) } interfaces[i] = modelIface @@ -122,9 +122,7 @@ func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, e return nil, fmt.Errorf("%s is not an interface. it is a %s", obj.Name(), obj.Type().Underlying().String()) } - iface = iface.Complete() - - if !p.checkInterfaceIsNotConstraint(iface) { + if p.isConstraint(iface) { return nil, fmt.Errorf("interface %s is a constraint", obj.Name()) } @@ -138,7 +136,7 @@ func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, e modelFunc, err := p.parseFunc(typedMethod) if err != nil { - return nil, fmt.Errorf("failed to parse method: %w", err) + return nil, newParseTypeError("parse method", typedMethod.String(), err) } methods[i] = &model.Method{ @@ -156,7 +154,7 @@ func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, e param := named.TypeParams().At(i) typeParam, err := p.parseConstraint(param) if err != nil { - return nil, fmt.Errorf("failed to parse type parameter: %w", err) + return nil, newParseTypeError("parse type parameter", param.String(), err) } typeParams[i] = &model.Parameter{Name: param.Obj().Name(), Type: typeParam} @@ -166,15 +164,15 @@ func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, e return &model.Interface{Name: obj.Name(), Methods: methods, TypeParams: typeParams}, nil } -func (o *importModeParser) checkInterfaceIsNotConstraint(t *types.Interface) bool { +func (o *importModeParser) isConstraint(t *types.Interface) bool { for i := 0; i < t.NumEmbeddeds(); i++ { embed := t.EmbeddedType(i) if _, ok := embed.Underlying().(*types.Interface); !ok { - return false + return true } } - return true + return false } func (p *importModeParser) parseType(t types.Type) (model.Type, error) { @@ -182,13 +180,13 @@ func (p *importModeParser) parseType(t types.Type) (model.Type, error) { case *types.Array: elementType, err := p.parseType(t.Elem()) if err != nil { - return nil, fmt.Errorf("failed to parse array type: %w", err) + return nil, newParseTypeError("parse array type", t.Elem().String(), err) } return &model.ArrayType{Len: int(t.Len()), Type: elementType}, nil case *types.Slice: elementType, err := p.parseType(t.Elem()) if err != nil { - return nil, fmt.Errorf("failed to parse array type: %w", err) + return nil, newParseTypeError("parse slice type", t.Elem().String(), err) } return &model.ArrayType{Len: -1, Type: elementType}, nil @@ -203,37 +201,41 @@ func (p *importModeParser) parseType(t types.Type) (model.Type, error) { chanType, err := p.parseType(t.Elem()) if err != nil { - return nil, fmt.Errorf("failed to parse chan type: %w", err) + return nil, newParseTypeError("parse chan type", t.Elem().String(), err) } return &model.ChanType{Dir: dir, Type: chanType}, nil case *types.Signature: sig, err := p.parseFunc(t) if err != nil { - return nil, fmt.Errorf("failed to parse signature: %w", err) + return nil, newParseTypeError("parse signature", t.String(), err) } return sig, nil case *types.Named: - var typeParams *model.TypeParametersType - if t.TypeArgs() != nil { - typeParams = &model.TypeParametersType{TypeParameters: make([]model.Type, t.TypeArgs().Len())} - for i := 0; i < t.TypeArgs().Len(); i++ { - typeParam := t.TypeArgs().At(i) - typedParam, err := p.parseType(typeParam) - if err != nil { - return nil, fmt.Errorf("failed to parse type parameter: %w", err) - } - - typeParams.TypeParameters[i] = typedParam - } - } - var pkg string if t.Obj().Pkg() != nil { pkg = t.Obj().Pkg().Path() } + if t.TypeArgs() == nil { + return &model.NamedType{ + Package: pkg, + Type: t.Obj().Name(), + }, nil + } + + typeParams := &model.TypeParametersType{TypeParameters: make([]model.Type, t.TypeArgs().Len())} + for i := 0; i < t.TypeArgs().Len(); i++ { + typeParam := t.TypeArgs().At(i) + typedParam, err := p.parseType(typeParam) + if err != nil { + return nil, newParseTypeError("parse type parameter", typeParam.String(), err) + } + + typeParams.TypeParameters[i] = typedParam + } + return &model.NamedType{ Package: pkg, Type: t.Obj().Name(), @@ -248,18 +250,18 @@ func (p *importModeParser) parseType(t types.Type) (model.Type, error) { case *types.Map: key, err := p.parseType(t.Key()) if err != nil { - return nil, fmt.Errorf("failed to parse map key type: %w", err) + return nil, newParseTypeError("parse map key", t.Key().String(), err) } value, err := p.parseType(t.Elem()) if err != nil { - return nil, fmt.Errorf("failed to parse map value type: %w", err) + return nil, newParseTypeError("parse map value", t.Elem().String(), err) } return &model.MapType{Key: key, Value: value}, nil case *types.Pointer: valueType, err := p.parseType(t.Elem()) if err != nil { - return nil, fmt.Errorf("failed to parse pointer type: %w", err) + return nil, newParseTypeError("parse pointer type", t.Elem().String(), err) } return &model.PointerType{Type: valueType}, nil @@ -291,7 +293,7 @@ func (p *importModeParser) parseFunc(sig *types.Signature) (*model.FuncType, err if isVariadicParam { sliceType, ok := param.Type().(*types.Slice) if !ok { - return nil, fmt.Errorf("variadic parameter is not a slice") + return nil, newParseTypeError("variadic parameter is not a slice", param.String(), nil) } parseType = sliceType.Elem() @@ -299,7 +301,7 @@ func (p *importModeParser) parseFunc(sig *types.Signature) (*model.FuncType, err paramType, err := p.parseType(parseType) if err != nil { - return nil, fmt.Errorf("failed to parse parameter type: %w", err) + return nil, newParseTypeError("parse parameter type", parseType.String(), err) } modelParameter := &model.Parameter{Type: paramType, Name: param.Name()} @@ -321,7 +323,7 @@ func (p *importModeParser) parseFunc(sig *types.Signature) (*model.FuncType, err resultType, err := p.parseType(result.Type()) if err != nil { - return nil, fmt.Errorf("failed to parse result type: %w", err) + return nil, newParseTypeError("parse result type", result.Type().String(), err) } results[i] = &model.Parameter{Type: resultType, Name: result.Name()} @@ -345,8 +347,30 @@ func (p *importModeParser) parseConstraint(t *types.TypeParam) (model.Type, erro typeParam, err := p.parseType(t.Constraint()) if err != nil { - return nil, fmt.Errorf("failed to parse type parameter: %w", err) + return nil, newParseTypeError("parse constraint type", t.Constraint().String(), err) } return typeParam, nil } + +type parseTypeError struct { + message string + typeString string + error error +} + +func newParseTypeError(message string, typeString string, error error) *parseTypeError { + return &parseTypeError{typeString: typeString, error: error, message: message} +} + +func (p parseTypeError) Error() string { + if p.error != nil { + return fmt.Sprintf("%s: error parsing %s: %s", p.message, p.typeString, p.error) + } + + return fmt.Sprintf("%s: error parsing type %s", p.message, p.typeString) +} + +func (p parseTypeError) Unwrap() error { + return p.error +} diff --git a/mockgen/import_mode_test.go b/mockgen/import_mode_test.go index e1151a3..bd452cc 100644 --- a/mockgen/import_mode_test.go +++ b/mockgen/import_mode_test.go @@ -24,7 +24,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { packageName: "", ifaces: []string{"ImmortalHelldiver"}, }, - expectedErr: "failed to load package: package not found", + expectedErr: "load package: package not found", }, { name: "error: interface does not exists", @@ -32,7 +32,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", ifaces: []string{"Alien"}, }, - expectedErr: "failed to extract interfaces from package: interface Alien does not exists", + expectedErr: "extract interfaces from package: interface Alien does not exists", }, { name: "error: search for struct instead of interface", @@ -40,7 +40,8 @@ func Test_importModeParser_parsePackage(t *testing.T) { packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", ifaces: []string{"Work"}, }, - expectedErr: "failed to extract interfaces from package: failed to parse interface: " + + expectedErr: "extract interfaces from package: parse interface: " + + "error parsing type go.uber.org/mock/mockgen/internal/tests/import_mode.Work struct{Name string}: " + "Work is not an interface. it is a struct{Name string}", }, { @@ -49,7 +50,8 @@ func Test_importModeParser_parsePackage(t *testing.T) { packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", ifaces: []string{"Counter"}, }, - expectedErr: "failed to extract interfaces from package: failed to parse interface: " + + expectedErr: "extract interfaces from package: parse interface: " + + "error parsing type go.uber.org/mock/mockgen/internal/tests/import_mode.Counter interface{int}: " + "interface Counter is a constraint", }, { diff --git a/mockgen/internal/tests/add_generate_directive/mock.go b/mockgen/internal/tests/add_generate_directive/mock.go index 142afb5..1baa626 100644 --- a/mockgen/internal/tests/add_generate_directive/mock.go +++ b/mockgen/internal/tests/add_generate_directive/mock.go @@ -3,7 +3,7 @@ // // Generated by this command: // -// ___package_mode -write_generate_directive -destination mock.go -package add_generate_directive . Foo +// mockgen -write_generate_directive -destination mock.go -package add_generate_directive . Foo // // Package add_generate_directive is a generated GoMock package. @@ -15,7 +15,7 @@ import ( gomock "go.uber.org/mock/gomock" ) -//go:generate /Users/tulzke/Library/Caches/JetBrains/GoLand2023.3/tmp/GoLand/___package_mode -write_generate_directive -destination mock.go -package add_generate_directive . Foo +//go:generate mockgen -write_generate_directive -destination mock.go -package add_generate_directive . Foo // MockFoo is a mock of Foo interface. type MockFoo struct { diff --git a/mockgen/internal/tests/import_mode/interfaces.go b/mockgen/internal/tests/import_mode/interfaces.go index 87ef1de..b562262 100644 --- a/mockgen/internal/tests/import_mode/interfaces.go +++ b/mockgen/internal/tests/import_mode/interfaces.go @@ -1,6 +1,6 @@ package import_mode -//go:generate mockgen -typed -package=mock -destination=mock/interfaces.go . Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,PromotionCampaign +//go:generate mockgen -typed -package=mock -destination=mock/interfaces.go . Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer import ( "time" diff --git a/mockgen/internal/tests/import_mode/mock/interfaces.go b/mockgen/internal/tests/import_mode/mock/interfaces.go index 86cb45f..69f051e 100644 --- a/mockgen/internal/tests/import_mode/mock/interfaces.go +++ b/mockgen/internal/tests/import_mode/mock/interfaces.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: go.uber.org/mock/mockgen/internal/tests/import_mode (interfaces: Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,PromotionCampaign) +// Source: go.uber.org/mock/mockgen/internal/tests/import_mode (interfaces: Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer) // // Generated by this command: // -// mockgen -typed -package=mock -destination=mock/interfaces.go . Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,PromotionCampaign +// mockgen -typed -package=mock -destination=mock/interfaces.go . Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer // // Package mock is a generated GoMock package. @@ -1392,67 +1392,3 @@ func (c *MockFarmerWroomCall) DoAndReturn(f func() error) *MockFarmerWroomCall { c.Call = c.Call.DoAndReturn(f) return c } - -// MockPromotionCampaign is a mock of PromotionCampaign interface. -type MockPromotionCampaign struct { - ctrl *gomock.Controller - recorder *MockPromotionCampaignMockRecorder -} - -// MockPromotionCampaignMockRecorder is the mock recorder for MockPromotionCampaign. -type MockPromotionCampaignMockRecorder struct { - mock *MockPromotionCampaign -} - -// NewMockPromotionCampaign creates a new mock instance. -func NewMockPromotionCampaign(ctrl *gomock.Controller) *MockPromotionCampaign { - mock := &MockPromotionCampaign{ctrl: ctrl} - mock.recorder = &MockPromotionCampaignMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockPromotionCampaign) EXPECT() *MockPromotionCampaignMockRecorder { - return m.recorder -} - -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockPromotionCampaign) ISGOMOCK() struct{} { - return struct{}{} -} - -// YouMustBuyOurCar mocks base method. -func (m *MockPromotionCampaign) YouMustBuyOurCar() { - m.ctrl.T.Helper() - m.ctrl.Call(m, "YouMustBuyOurCar") -} - -// YouMustBuyOurCar indicates an expected call of YouMustBuyOurCar. -func (mr *MockPromotionCampaignMockRecorder) YouMustBuyOurCar() *MockPromotionCampaignYouMustBuyOurCarCall { - mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "YouMustBuyOurCar", reflect.TypeOf((*MockPromotionCampaign)(nil).YouMustBuyOurCar)) - return &MockPromotionCampaignYouMustBuyOurCarCall{Call: call} -} - -// MockPromotionCampaignYouMustBuyOurCarCall wrap *gomock.Call -type MockPromotionCampaignYouMustBuyOurCarCall struct { - *gomock.Call -} - -// Return rewrite *gomock.Call.Return -func (c *MockPromotionCampaignYouMustBuyOurCarCall) Return() *MockPromotionCampaignYouMustBuyOurCarCall { - c.Call = c.Call.Return() - return c -} - -// Do rewrite *gomock.Call.Do -func (c *MockPromotionCampaignYouMustBuyOurCarCall) Do(f func()) *MockPromotionCampaignYouMustBuyOurCarCall { - c.Call = c.Call.Do(f) - return c -} - -// DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockPromotionCampaignYouMustBuyOurCarCall) DoAndReturn(f func()) *MockPromotionCampaignYouMustBuyOurCarCall { - c.Call = c.Call.DoAndReturn(f) - return c -} From 703a35f27ceff294bbb05694f1a0770c880e9308 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Wed, 28 Aug 2024 20:50:06 +0300 Subject: [PATCH 04/16] fixed misprint in the error --- mockgen/import_mode.go | 2 +- mockgen/import_mode_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mockgen/import_mode.go b/mockgen/import_mode.go index 8b519c1..8d8b81e 100644 --- a/mockgen/import_mode.go +++ b/mockgen/import_mode.go @@ -97,7 +97,7 @@ func (p *importModeParser) extractInterfacesFromPackage(pkg *packages.Package, i for i, iface := range ifaces { obj := pkg.Types.Scope().Lookup(iface) if obj == nil { - return nil, fmt.Errorf("interface %s does not exists", iface) + return nil, fmt.Errorf("interface %s does not exist", iface) } modelIface, err := p.parseInterface(obj) diff --git a/mockgen/import_mode_test.go b/mockgen/import_mode_test.go index bd452cc..4a3c638 100644 --- a/mockgen/import_mode_test.go +++ b/mockgen/import_mode_test.go @@ -27,12 +27,12 @@ func Test_importModeParser_parsePackage(t *testing.T) { expectedErr: "load package: package not found", }, { - name: "error: interface does not exists", + name: "error: interface does not exist", args: args{ packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", ifaces: []string{"Alien"}, }, - expectedErr: "extract interfaces from package: interface Alien does not exists", + expectedErr: "extract interfaces from package: interface Alien does not exist", }, { name: "error: search for struct instead of interface", From 02bca6a5b6844b6f49cdf951af3bc3b773275861 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Mon, 9 Sep 2024 20:05:03 +0300 Subject: [PATCH 05/16] added types.Unalias call --- mockgen/import_mode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mockgen/import_mode.go b/mockgen/import_mode.go index 8d8b81e..386c02c 100644 --- a/mockgen/import_mode.go +++ b/mockgen/import_mode.go @@ -112,7 +112,7 @@ func (p *importModeParser) extractInterfacesFromPackage(pkg *packages.Package, i } func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, error) { - named, ok := obj.Type().(*types.Named) + named, ok := types.Unalias(obj.Type()).(*types.Named) if !ok { return nil, fmt.Errorf("%s is not an interface. it is a %s", obj.Name(), obj.Type().Underlying().String()) } From 07d869b4018d2a61194ddadcb4247d397c339b38 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Thu, 12 Sep 2024 13:25:50 +0300 Subject: [PATCH 06/16] review: * go updated up to 1.23 for correct aliases support * loading of package was changed from fake package to direct load by pattern * types.Alias added to same case as types.Named * added test case for interface containing aliases in parameters and returns --- go.mod | 2 +- mockgen/import_mode.go | 67 +++++------ mockgen/import_mode_test.go | 59 +++++++++- mockgen/internal/tests/generics/go.mod | 2 +- .../tests/generics/import_mode/mock_test.go | 2 +- .../internal/tests/import_mode/interfaces.go | 9 +- .../tests/import_mode/mock/interfaces.go | 108 +++++++++++++++++- mockgen/internal/tests/typed/go.mod | 2 +- 8 files changed, 199 insertions(+), 52 deletions(-) diff --git a/go.mod b/go.mod index 46ce2f8..e5f84bd 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module go.uber.org/mock -go 1.19 +go 1.23 require ( github.com/stretchr/testify v1.9.0 diff --git a/mockgen/import_mode.go b/mockgen/import_mode.go index 386c02c..2878b0a 100644 --- a/mockgen/import_mode.go +++ b/mockgen/import_mode.go @@ -1,11 +1,10 @@ package main import ( + "errors" "fmt" - "go/token" "go/types" "math/rand" - "os" "go.uber.org/mock/mockgen/model" "golang.org/x/tools/go/packages" @@ -36,34 +35,10 @@ func (p *importModeParser) parsePackage(packageName string, ifaces []string) (*m } func (p *importModeParser) loadPackage(packageName string) (*packages.Package, error) { - const fakeFileTemplate = ` - package main - - import ( - "%s" - ) - ` - - dirName := "mockgen_" + p.generateSalt() - err := os.Mkdir(dirName, 0755) - if err != nil { - return nil, fmt.Errorf("create temp dir for fake package: %w", err) - } - defer os.RemoveAll(dirName) - - err = os.WriteFile(dirName+"/main.go", []byte(fmt.Sprintf(fakeFileTemplate, packageName)), 0666) - if err != nil { - return nil, fmt.Errorf("write fake main.go: %w", err) - } - - fileSet := token.NewFileSet() - cfg := &packages.Config{ Mode: packages.NeedDeps | packages.NeedImports | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedEmbedFiles, - Dir: dirName, - Fset: fileSet, } - pkgs, err := packages.Load(cfg) + pkgs, err := packages.Load(cfg, packageName) if err != nil { return nil, fmt.Errorf("load packages: %w", err) } @@ -72,13 +47,16 @@ func (p *importModeParser) loadPackage(packageName string) (*packages.Package, e return nil, fmt.Errorf("packages length must be 1: %d", len(pkgs)) } - pkg := pkgs[0] - searchedPkg, ok := pkg.Imports[packageName] - if !ok { - return nil, fmt.Errorf("package %s not found", packageName) + if len(pkgs[0].Errors) > 0 { + errs := make([]error, len(pkgs[0].Errors)) + for i, err := range pkgs[0].Errors { + errs[i] = err + } + + return nil, errors.Join(errs...) } - return searchedPkg, nil + return pkgs[0], nil } func (p *importModeParser) generateSalt() string { @@ -212,22 +190,23 @@ func (p *importModeParser) parseType(t types.Type) (model.Type, error) { } return sig, nil - case *types.Named: + case *types.Named, *types.Alias: + named := t.(namedType) var pkg string - if t.Obj().Pkg() != nil { - pkg = t.Obj().Pkg().Path() + if named.Obj().Pkg() != nil { + pkg = named.Obj().Pkg().Path() } - if t.TypeArgs() == nil { + if named.TypeArgs() == nil { return &model.NamedType{ Package: pkg, - Type: t.Obj().Name(), + Type: named.Obj().Name(), }, nil } - typeParams := &model.TypeParametersType{TypeParameters: make([]model.Type, t.TypeArgs().Len())} - for i := 0; i < t.TypeArgs().Len(); i++ { - typeParam := t.TypeArgs().At(i) + typeParams := &model.TypeParametersType{TypeParameters: make([]model.Type, named.TypeArgs().Len())} + for i := 0; i < named.TypeArgs().Len(); i++ { + typeParam := named.TypeArgs().At(i) typedParam, err := p.parseType(typeParam) if err != nil { return nil, newParseTypeError("parse type parameter", typeParam.String(), err) @@ -238,7 +217,7 @@ func (p *importModeParser) parseType(t types.Type) (model.Type, error) { return &model.NamedType{ Package: pkg, - Type: t.Obj().Name(), + Type: named.Obj().Name(), TypeParams: typeParams, }, nil case *types.Interface: @@ -374,3 +353,9 @@ func (p parseTypeError) Error() string { func (p parseTypeError) Unwrap() error { return p.error } + +// namedType is an interface for combining Named and Alias +type namedType interface { + Obj() *types.TypeName + TypeArgs() *types.TypeList +} diff --git a/mockgen/import_mode_test.go b/mockgen/import_mode_test.go index 4a3c638..e79d102 100644 --- a/mockgen/import_mode_test.go +++ b/mockgen/import_mode_test.go @@ -21,10 +21,10 @@ func Test_importModeParser_parsePackage(t *testing.T) { { name: "error: no found package", args: args{ - packageName: "", - ifaces: []string{"ImmortalHelldiver"}, + packageName: "foo/bar/another_package", + ifaces: []string{"Human"}, }, - expectedErr: "load package: package not found", + expectedErr: "load package: -: package foo/bar/another_package is not in std", }, { name: "error: interface does not exist", @@ -296,6 +296,57 @@ func Test_importModeParser_parsePackage(t *testing.T) { }, }, }, + { + name: "success: interfaces with aliases in params and returns", + args: args{ + packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + ifaces: []string{"Earth"}, + }, + expected: &model.Package{ + Name: "import_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Interfaces: []*model.Interface{ + { + Name: "Earth", + Methods: []*model.Method{ + { + Name: "GiveBirth", + In: []*model.Parameter{ + { + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Type: "HumansCount", + }, + }, + }, + Out: []*model.Parameter{ + { + Type: &model.ArrayType{ + Len: -1, // slice + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Type: "Human", + }, + }, + }, + }, + }, + { + Name: "HumanPopulation", + Out: []*model.Parameter{ + { + Type: &model.NamedType{ + Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Type: "HumansCount", + }, + }, + }, + }, + }, + }, + }, + }, + }, } for _, tt := range tests { @@ -304,7 +355,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { actual, err := parser.parsePackage(tt.args.packageName, tt.args.ifaces) if tt.expectedErr != "" { - assert.EqualError(t, err, tt.expectedErr) + assert.ErrorContains(t, err, tt.expectedErr) } else { assert.NoError(t, err) } diff --git a/mockgen/internal/tests/generics/go.mod b/mockgen/internal/tests/generics/go.mod index cffe722..aa647e9 100644 --- a/mockgen/internal/tests/generics/go.mod +++ b/mockgen/internal/tests/generics/go.mod @@ -1,6 +1,6 @@ module go.uber.org/mock/mockgen/internal/tests/generics -go 1.19 +go 1.23 replace go.uber.org/mock => ../../../.. diff --git a/mockgen/internal/tests/generics/import_mode/mock_test.go b/mockgen/internal/tests/generics/import_mode/mock_test.go index 23546b6..040da9d 100644 --- a/mockgen/internal/tests/generics/import_mode/mock_test.go +++ b/mockgen/internal/tests/generics/import_mode/mock_test.go @@ -3,7 +3,7 @@ // // Generated by this command: // -// ___1package_mode --destination=import_mode/mock_test.go --package=import_mode . Bar,Universe,MilkyWay,SolarSystem,Earth,Water +// mockgen --destination=import_mode/mock_test.go --package=import_mode . Bar,Universe,MilkyWay,SolarSystem,Earth,Water // // Package import_mode is a generated GoMock package. diff --git a/mockgen/internal/tests/import_mode/interfaces.go b/mockgen/internal/tests/import_mode/interfaces.go index b562262..2c23bad 100644 --- a/mockgen/internal/tests/import_mode/interfaces.go +++ b/mockgen/internal/tests/import_mode/interfaces.go @@ -1,6 +1,6 @@ package import_mode -//go:generate mockgen -typed -package=mock -destination=mock/interfaces.go . Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer +//go:generate mockgen -typed -package=mock -destination=mock/interfaces.go . Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,Earth import ( "time" @@ -59,3 +59,10 @@ type Work struct { type Counter interface { int } + +type HumansCount = int + +type Earth interface { + GiveBirth(HumansCount) []Human + HumanPopulation() HumansCount +} diff --git a/mockgen/internal/tests/import_mode/mock/interfaces.go b/mockgen/internal/tests/import_mode/mock/interfaces.go index 69f051e..d39f1b3 100644 --- a/mockgen/internal/tests/import_mode/mock/interfaces.go +++ b/mockgen/internal/tests/import_mode/mock/interfaces.go @@ -1,9 +1,9 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: go.uber.org/mock/mockgen/internal/tests/import_mode (interfaces: Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer) +// Source: go.uber.org/mock/mockgen/internal/tests/import_mode (interfaces: Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,Earth) // // Generated by this command: // -// mockgen -typed -package=mock -destination=mock/interfaces.go . Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer +// mockgen -typed -package=mock -destination=mock/interfaces.go . Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,Earth // // Package mock is a generated GoMock package. @@ -1392,3 +1392,107 @@ func (c *MockFarmerWroomCall) DoAndReturn(f func() error) *MockFarmerWroomCall { c.Call = c.Call.DoAndReturn(f) return c } + +// MockEarth is a mock of Earth interface. +type MockEarth struct { + ctrl *gomock.Controller + recorder *MockEarthMockRecorder +} + +// MockEarthMockRecorder is the mock recorder for MockEarth. +type MockEarthMockRecorder struct { + mock *MockEarth +} + +// NewMockEarth creates a new mock instance. +func NewMockEarth(ctrl *gomock.Controller) *MockEarth { + mock := &MockEarth{ctrl: ctrl} + mock.recorder = &MockEarthMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEarth) EXPECT() *MockEarthMockRecorder { + return m.recorder +} + +// ISGOMOCK indicates that this struct is a gomock mock. +func (m *MockEarth) ISGOMOCK() struct{} { + return struct{}{} +} + +// GiveBirth mocks base method. +func (m *MockEarth) GiveBirth(arg0 import_mode.HumansCount) []import_mode.Human { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GiveBirth", arg0) + ret0, _ := ret[0].([]import_mode.Human) + return ret0 +} + +// GiveBirth indicates an expected call of GiveBirth. +func (mr *MockEarthMockRecorder) GiveBirth(arg0 any) *MockEarthGiveBirthCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GiveBirth", reflect.TypeOf((*MockEarth)(nil).GiveBirth), arg0) + return &MockEarthGiveBirthCall{Call: call} +} + +// MockEarthGiveBirthCall wrap *gomock.Call +type MockEarthGiveBirthCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockEarthGiveBirthCall) Return(arg0 []import_mode.Human) *MockEarthGiveBirthCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockEarthGiveBirthCall) Do(f func(import_mode.HumansCount) []import_mode.Human) *MockEarthGiveBirthCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockEarthGiveBirthCall) DoAndReturn(f func(import_mode.HumansCount) []import_mode.Human) *MockEarthGiveBirthCall { + c.Call = c.Call.DoAndReturn(f) + return c +} + +// HumanPopulation mocks base method. +func (m *MockEarth) HumanPopulation() import_mode.HumansCount { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HumanPopulation") + ret0, _ := ret[0].(import_mode.HumansCount) + return ret0 +} + +// HumanPopulation indicates an expected call of HumanPopulation. +func (mr *MockEarthMockRecorder) HumanPopulation() *MockEarthHumanPopulationCall { + mr.mock.ctrl.T.Helper() + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HumanPopulation", reflect.TypeOf((*MockEarth)(nil).HumanPopulation)) + return &MockEarthHumanPopulationCall{Call: call} +} + +// MockEarthHumanPopulationCall wrap *gomock.Call +type MockEarthHumanPopulationCall struct { + *gomock.Call +} + +// Return rewrite *gomock.Call.Return +func (c *MockEarthHumanPopulationCall) Return(arg0 import_mode.HumansCount) *MockEarthHumanPopulationCall { + c.Call = c.Call.Return(arg0) + return c +} + +// Do rewrite *gomock.Call.Do +func (c *MockEarthHumanPopulationCall) Do(f func() import_mode.HumansCount) *MockEarthHumanPopulationCall { + c.Call = c.Call.Do(f) + return c +} + +// DoAndReturn rewrite *gomock.Call.DoAndReturn +func (c *MockEarthHumanPopulationCall) DoAndReturn(f func() import_mode.HumansCount) *MockEarthHumanPopulationCall { + c.Call = c.Call.DoAndReturn(f) + return c +} diff --git a/mockgen/internal/tests/typed/go.mod b/mockgen/internal/tests/typed/go.mod index 67403cf..d6642c9 100644 --- a/mockgen/internal/tests/typed/go.mod +++ b/mockgen/internal/tests/typed/go.mod @@ -1,6 +1,6 @@ module go.uber.org/mock/mockgen/internal/tests/typed -go 1.19 +go 1.23 replace go.uber.org/mock => ../../../.. From c6307514e5357dcf514a49c61bc499a1436789d2 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Tue, 24 Sep 2024 20:10:35 +0300 Subject: [PATCH 07/16] review changes: * changed errors formatting with less details * regenerated mocks --- mockgen/import_mode.go | 6 +- mockgen/import_mode_test.go | 6 +- .../tests/import_mode/mock/interfaces.go | 60 ++++--------------- 3 files changed, 16 insertions(+), 56 deletions(-) diff --git a/mockgen/import_mode.go b/mockgen/import_mode.go index 2878b0a..98d8094 100644 --- a/mockgen/import_mode.go +++ b/mockgen/import_mode.go @@ -80,7 +80,7 @@ func (p *importModeParser) extractInterfacesFromPackage(pkg *packages.Package, i modelIface, err := p.parseInterface(obj) if err != nil { - return nil, newParseTypeError("parse interface", obj.String(), err) + return nil, newParseTypeError("parse interface", obj.Name(), err) } interfaces[i] = modelIface @@ -92,12 +92,12 @@ func (p *importModeParser) extractInterfacesFromPackage(pkg *packages.Package, i func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, error) { named, ok := types.Unalias(obj.Type()).(*types.Named) if !ok { - return nil, fmt.Errorf("%s is not an interface. it is a %s", obj.Name(), obj.Type().Underlying().String()) + return nil, fmt.Errorf("%s is not an interface. it is a %T", obj.Name(), obj.Type().Underlying()) } iface, ok := named.Underlying().(*types.Interface) if !ok { - return nil, fmt.Errorf("%s is not an interface. it is a %s", obj.Name(), obj.Type().Underlying().String()) + return nil, fmt.Errorf("%s is not an interface. it is a %T", obj.Name(), obj.Type().Underlying()) } if p.isConstraint(iface) { diff --git a/mockgen/import_mode_test.go b/mockgen/import_mode_test.go index e79d102..0e0268e 100644 --- a/mockgen/import_mode_test.go +++ b/mockgen/import_mode_test.go @@ -41,8 +41,8 @@ func Test_importModeParser_parsePackage(t *testing.T) { ifaces: []string{"Work"}, }, expectedErr: "extract interfaces from package: parse interface: " + - "error parsing type go.uber.org/mock/mockgen/internal/tests/import_mode.Work struct{Name string}: " + - "Work is not an interface. it is a struct{Name string}", + "error parsing Work: " + + "Work is not an interface. it is a *types.Struct", }, { name: "error: search for constraint instead of interface", @@ -51,7 +51,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { ifaces: []string{"Counter"}, }, expectedErr: "extract interfaces from package: parse interface: " + - "error parsing type go.uber.org/mock/mockgen/internal/tests/import_mode.Counter interface{int}: " + + "error parsing Counter: " + "interface Counter is a constraint", }, { diff --git a/mockgen/internal/tests/import_mode/mock/interfaces.go b/mockgen/internal/tests/import_mode/mock/interfaces.go index d39f1b3..770de9c 100644 --- a/mockgen/internal/tests/import_mode/mock/interfaces.go +++ b/mockgen/internal/tests/import_mode/mock/interfaces.go @@ -23,6 +23,7 @@ import ( type MockFood struct { ctrl *gomock.Controller recorder *MockFoodMockRecorder + isgomock struct{} } // MockFoodMockRecorder is the mock recorder for MockFood. @@ -42,11 +43,6 @@ func (m *MockFood) EXPECT() *MockFoodMockRecorder { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockFood) ISGOMOCK() struct{} { - return struct{}{} -} - // Calories mocks base method. func (m *MockFood) Calories() int { m.ctrl.T.Helper() @@ -89,6 +85,7 @@ func (c *MockFoodCaloriesCall) DoAndReturn(f func() int) *MockFoodCaloriesCall { type MockEater struct { ctrl *gomock.Controller recorder *MockEaterMockRecorder + isgomock struct{} } // MockEaterMockRecorder is the mock recorder for MockEater. @@ -108,11 +105,6 @@ func (m *MockEater) EXPECT() *MockEaterMockRecorder { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockEater) ISGOMOCK() struct{} { - return struct{}{} -} - // Eat mocks base method. func (m *MockEater) Eat(foods ...import_mode.Food) { m.ctrl.T.Helper() @@ -157,6 +149,7 @@ func (c *MockEaterEatCall) DoAndReturn(f func(...import_mode.Food)) *MockEaterEa type MockAnimal struct { ctrl *gomock.Controller recorder *MockAnimalMockRecorder + isgomock struct{} } // MockAnimalMockRecorder is the mock recorder for MockAnimal. @@ -176,11 +169,6 @@ func (m *MockAnimal) EXPECT() *MockAnimalMockRecorder { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockAnimal) ISGOMOCK() struct{} { - return struct{}{} -} - // Breathe mocks base method. func (m *MockAnimal) Breathe() { m.ctrl.T.Helper() @@ -297,6 +285,7 @@ func (c *MockAnimalSleepCall) DoAndReturn(f func(time.Duration)) *MockAnimalSlee type MockHuman struct { ctrl *gomock.Controller recorder *MockHumanMockRecorder + isgomock struct{} } // MockHumanMockRecorder is the mock recorder for MockHuman. @@ -316,11 +305,6 @@ func (m *MockHuman) EXPECT() *MockHumanMockRecorder { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockHuman) ISGOMOCK() struct{} { - return struct{}{} -} - // Breathe mocks base method. func (m *MockHuman) Breathe() { m.ctrl.T.Helper() @@ -437,6 +421,7 @@ func (c *MockHumanSleepCall) DoAndReturn(f func(time.Duration)) *MockHumanSleepC type MockPrimate struct { ctrl *gomock.Controller recorder *MockPrimateMockRecorder + isgomock struct{} } // MockPrimateMockRecorder is the mock recorder for MockPrimate. @@ -456,11 +441,6 @@ func (m *MockPrimate) EXPECT() *MockPrimateMockRecorder { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockPrimate) ISGOMOCK() struct{} { - return struct{}{} -} - // Breathe mocks base method. func (m *MockPrimate) Breathe() { m.ctrl.T.Helper() @@ -577,6 +557,7 @@ func (c *MockPrimateSleepCall) DoAndReturn(f func(time.Duration)) *MockPrimateSl type MockCar[FuelType fuel.Fuel] struct { ctrl *gomock.Controller recorder *MockCarMockRecorder[FuelType] + isgomock struct{} } // MockCarMockRecorder is the mock recorder for MockCar. @@ -596,11 +577,6 @@ func (m *MockCar[FuelType]) EXPECT() *MockCarMockRecorder[FuelType] { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockCar[FuelType]) ISGOMOCK() struct{} { - return struct{}{} -} - // Brand mocks base method. func (m *MockCar[FuelType]) Brand() string { m.ctrl.T.Helper() @@ -719,6 +695,7 @@ func (c *MockCarRefuelCall[FuelType]) DoAndReturn(f func(FuelType, int) error) * type MockDriver[FuelType fuel.Fuel, CarType import_mode.Car[FuelType]] struct { ctrl *gomock.Controller recorder *MockDriverMockRecorder[FuelType, CarType] + isgomock struct{} } // MockDriverMockRecorder is the mock recorder for MockDriver. @@ -738,11 +715,6 @@ func (m *MockDriver[FuelType, CarType]) EXPECT() *MockDriverMockRecorder[FuelTyp return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockDriver[FuelType, CarType]) ISGOMOCK() struct{} { - return struct{}{} -} - // Drive mocks base method. func (m *MockDriver[FuelType, CarType]) Drive(car CarType) { m.ctrl.T.Helper() @@ -821,6 +793,7 @@ func (c *MockDriverWroomCall[FuelType, CarType]) DoAndReturn(f func() error) *Mo type MockUrbanResident struct { ctrl *gomock.Controller recorder *MockUrbanResidentMockRecorder + isgomock struct{} } // MockUrbanResidentMockRecorder is the mock recorder for MockUrbanResident. @@ -840,11 +813,6 @@ func (m *MockUrbanResident) EXPECT() *MockUrbanResidentMockRecorder { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockUrbanResident) ISGOMOCK() struct{} { - return struct{}{} -} - // Breathe mocks base method. func (m *MockUrbanResident) Breathe() { m.ctrl.T.Helper() @@ -1109,6 +1077,7 @@ func (c *MockUrbanResidentWroomCall) DoAndReturn(f func() error) *MockUrbanResid type MockFarmer struct { ctrl *gomock.Controller recorder *MockFarmerMockRecorder + isgomock struct{} } // MockFarmerMockRecorder is the mock recorder for MockFarmer. @@ -1128,11 +1097,6 @@ func (m *MockFarmer) EXPECT() *MockFarmerMockRecorder { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockFarmer) ISGOMOCK() struct{} { - return struct{}{} -} - // Breathe mocks base method. func (m *MockFarmer) Breathe() { m.ctrl.T.Helper() @@ -1397,6 +1361,7 @@ func (c *MockFarmerWroomCall) DoAndReturn(f func() error) *MockFarmerWroomCall { type MockEarth struct { ctrl *gomock.Controller recorder *MockEarthMockRecorder + isgomock struct{} } // MockEarthMockRecorder is the mock recorder for MockEarth. @@ -1416,11 +1381,6 @@ func (m *MockEarth) EXPECT() *MockEarthMockRecorder { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockEarth) ISGOMOCK() struct{} { - return struct{}{} -} - // GiveBirth mocks base method. func (m *MockEarth) GiveBirth(arg0 import_mode.HumansCount) []import_mode.Human { m.ctrl.T.Helper() From c5cd86f7dc6136066d7294c49d9b26edc4d93f67 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Tue, 24 Sep 2024 20:19:32 +0300 Subject: [PATCH 08/16] regenerated mock --- .../import_mode/mock_external_mock.go | 56 +++++++------------ .../tests/generics/import_mode/mock_test.go | 36 ++---------- 2 files changed, 26 insertions(+), 66 deletions(-) diff --git a/mockgen/internal/tests/generics/import_mode/mock_external_mock.go b/mockgen/internal/tests/generics/import_mode/mock_external_mock.go index 0766384..a2bdea9 100644 --- a/mockgen/internal/tests/generics/import_mode/mock_external_mock.go +++ b/mockgen/internal/tests/generics/import_mode/mock_external_mock.go @@ -23,6 +23,7 @@ import ( type MockExternalConstraint[I constraints.Integer, F any] struct { ctrl *gomock.Controller recorder *MockExternalConstraintMockRecorder[I, F] + isgomock struct{} } // MockExternalConstraintMockRecorder is the mock recorder for MockExternalConstraint. @@ -42,11 +43,6 @@ func (m *MockExternalConstraint[I, F]) EXPECT() *MockExternalConstraintMockRecor return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockExternalConstraint[I, F]) ISGOMOCK() struct{} { - return struct{}{} -} - // Eight mocks base method. func (m *MockExternalConstraint[I, F]) Eight(arg0 F) other.Two[I, F] { m.ctrl.T.Helper() @@ -202,17 +198,17 @@ func (mr *MockExternalConstraintMockRecorder[I, F]) Three(arg0 any) *gomock.Call } // Twelve mocks base method. -func (m *MockExternalConstraint[I, F]) Twelve(arg0 context.Context) <-chan []I { +func (m *MockExternalConstraint[I, F]) Twelve(ctx context.Context) <-chan []I { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Twelve", arg0) + ret := m.ctrl.Call(m, "Twelve", ctx) ret0, _ := ret[0].(<-chan []I) return ret0 } // Twelve indicates an expected call of Twelve. -func (mr *MockExternalConstraintMockRecorder[I, F]) Twelve(arg0 any) *gomock.Call { +func (mr *MockExternalConstraintMockRecorder[I, F]) Twelve(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Twelve), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Twelve), ctx) } // Two mocks base method. @@ -233,6 +229,7 @@ func (mr *MockExternalConstraintMockRecorder[I, F]) Two(arg0 any) *gomock.Call { type MockEmbeddingIface[T constraints.Integer, R constraints.Float] struct { ctrl *gomock.Controller recorder *MockEmbeddingIfaceMockRecorder[T, R] + isgomock struct{} } // MockEmbeddingIfaceMockRecorder is the mock recorder for MockEmbeddingIface. @@ -252,11 +249,6 @@ func (m *MockEmbeddingIface[T, R]) EXPECT() *MockEmbeddingIfaceMockRecorder[T, R return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockEmbeddingIface[T, R]) ISGOMOCK() struct{} { - return struct{}{} -} - // Eight mocks base method. func (m *MockEmbeddingIface[T, R]) Eight(arg0 R) other.Two[T, R] { m.ctrl.T.Helper() @@ -382,18 +374,18 @@ func (mr *MockEmbeddingIfaceMockRecorder[T, R]) One(arg0 any) *gomock.Call { } // Read mocks base method. -func (m *MockEmbeddingIface[T, R]) Read(arg0 []byte) (int, error) { +func (m *MockEmbeddingIface[T, R]) Read(p []byte) (int, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Read", arg0) + ret := m.ctrl.Call(m, "Read", p) ret0, _ := ret[0].(int) ret1, _ := ret[1].(error) return ret0, ret1 } // Read indicates an expected call of Read. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Read(arg0 any) *gomock.Call { +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Read(p any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Read), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Read), p) } // Second mocks base method. @@ -497,17 +489,17 @@ func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Three(arg0 any) *gomock.Call { } // Twelve mocks base method. -func (m *MockEmbeddingIface[T, R]) Twelve(arg0 context.Context) <-chan []T { +func (m *MockEmbeddingIface[T, R]) Twelve(ctx context.Context) <-chan []T { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Twelve", arg0) + ret := m.ctrl.Call(m, "Twelve", ctx) ret0, _ := ret[0].(<-chan []T) return ret0 } // Twelve indicates an expected call of Twelve. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Twelve(arg0 any) *gomock.Call { +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Twelve(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Twelve), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Twelve), ctx) } // Two mocks base method. @@ -542,6 +534,7 @@ func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Water(arg0 any) *gomock.Call { type MockGenerator[T any] struct { ctrl *gomock.Controller recorder *MockGeneratorMockRecorder[T] + isgomock struct{} } // MockGeneratorMockRecorder is the mock recorder for MockGenerator. @@ -561,11 +554,6 @@ func (m *MockGenerator[T]) EXPECT() *MockGeneratorMockRecorder[T] { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockGenerator[T]) ISGOMOCK() struct{} { - return struct{}{} -} - // Generate mocks base method. func (m *MockGenerator[T]) Generate() T { m.ctrl.T.Helper() @@ -584,6 +572,7 @@ func (mr *MockGeneratorMockRecorder[T]) Generate() *gomock.Call { type MockGroup[T generics.Generator[any]] struct { ctrl *gomock.Controller recorder *MockGroupMockRecorder[T] + isgomock struct{} } // MockGroupMockRecorder is the mock recorder for MockGroup. @@ -603,21 +592,16 @@ func (m *MockGroup[T]) EXPECT() *MockGroupMockRecorder[T] { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockGroup[T]) ISGOMOCK() struct{} { - return struct{}{} -} - // Join mocks base method. -func (m *MockGroup[T]) Join(arg0 context.Context) []T { +func (m *MockGroup[T]) Join(ctx context.Context) []T { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Join", arg0) + ret := m.ctrl.Call(m, "Join", ctx) ret0, _ := ret[0].([]T) return ret0 } // Join indicates an expected call of Join. -func (mr *MockGroupMockRecorder[T]) Join(arg0 any) *gomock.Call { +func (mr *MockGroupMockRecorder[T]) Join(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Join", reflect.TypeOf((*MockGroup[T])(nil).Join), arg0) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Join", reflect.TypeOf((*MockGroup[T])(nil).Join), ctx) } diff --git a/mockgen/internal/tests/generics/import_mode/mock_test.go b/mockgen/internal/tests/generics/import_mode/mock_test.go index 040da9d..da9d200 100644 --- a/mockgen/internal/tests/generics/import_mode/mock_test.go +++ b/mockgen/internal/tests/generics/import_mode/mock_test.go @@ -22,6 +22,7 @@ import ( type MockBar[T any, R any] struct { ctrl *gomock.Controller recorder *MockBarMockRecorder[T, R] + isgomock struct{} } // MockBarMockRecorder is the mock recorder for MockBar. @@ -41,11 +42,6 @@ func (m *MockBar[T, R]) EXPECT() *MockBarMockRecorder[T, R] { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockBar[T, R]) ISGOMOCK() struct{} { - return struct{}{} -} - // Eight mocks base method. func (m *MockBar[T, R]) Eight(arg0 T) other.Two[T, R] { m.ctrl.T.Helper() @@ -320,6 +316,7 @@ func (mr *MockBarMockRecorder[T, R]) Two(arg0 any) *gomock.Call { type MockUniverse[T constraints.Signed] struct { ctrl *gomock.Controller recorder *MockUniverseMockRecorder[T] + isgomock struct{} } // MockUniverseMockRecorder is the mock recorder for MockUniverse. @@ -339,11 +336,6 @@ func (m *MockUniverse[T]) EXPECT() *MockUniverseMockRecorder[T] { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockUniverse[T]) ISGOMOCK() struct{} { - return struct{}{} -} - // Water mocks base method. func (m *MockUniverse[T]) Water(arg0 T) []T { m.ctrl.T.Helper() @@ -362,6 +354,7 @@ func (mr *MockUniverseMockRecorder[T]) Water(arg0 any) *gomock.Call { type MockMilkyWay[R constraints.Integer] struct { ctrl *gomock.Controller recorder *MockMilkyWayMockRecorder[R] + isgomock struct{} } // MockMilkyWayMockRecorder is the mock recorder for MockMilkyWay. @@ -381,11 +374,6 @@ func (m *MockMilkyWay[R]) EXPECT() *MockMilkyWayMockRecorder[R] { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockMilkyWay[R]) ISGOMOCK() struct{} { - return struct{}{} -} - // Water mocks base method. func (m *MockMilkyWay[R]) Water(arg0 R) []R { m.ctrl.T.Helper() @@ -404,6 +392,7 @@ func (mr *MockMilkyWayMockRecorder[R]) Water(arg0 any) *gomock.Call { type MockSolarSystem[T constraints.Ordered] struct { ctrl *gomock.Controller recorder *MockSolarSystemMockRecorder[T] + isgomock struct{} } // MockSolarSystemMockRecorder is the mock recorder for MockSolarSystem. @@ -423,11 +412,6 @@ func (m *MockSolarSystem[T]) EXPECT() *MockSolarSystemMockRecorder[T] { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockSolarSystem[T]) ISGOMOCK() struct{} { - return struct{}{} -} - // Water mocks base method. func (m *MockSolarSystem[T]) Water(arg0 T) []T { m.ctrl.T.Helper() @@ -446,6 +430,7 @@ func (mr *MockSolarSystemMockRecorder[T]) Water(arg0 any) *gomock.Call { type MockEarth[R any] struct { ctrl *gomock.Controller recorder *MockEarthMockRecorder[R] + isgomock struct{} } // MockEarthMockRecorder is the mock recorder for MockEarth. @@ -465,11 +450,6 @@ func (m *MockEarth[R]) EXPECT() *MockEarthMockRecorder[R] { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockEarth[R]) ISGOMOCK() struct{} { - return struct{}{} -} - // Water mocks base method. func (m *MockEarth[R]) Water(arg0 R) []R { m.ctrl.T.Helper() @@ -488,6 +468,7 @@ func (mr *MockEarthMockRecorder[R]) Water(arg0 any) *gomock.Call { type MockWater[R any, C generics.UnsignedInteger] struct { ctrl *gomock.Controller recorder *MockWaterMockRecorder[R, C] + isgomock struct{} } // MockWaterMockRecorder is the mock recorder for MockWater. @@ -507,11 +488,6 @@ func (m *MockWater[R, C]) EXPECT() *MockWaterMockRecorder[R, C] { return m.recorder } -// ISGOMOCK indicates that this struct is a gomock mock. -func (m *MockWater[R, C]) ISGOMOCK() struct{} { - return struct{}{} -} - // Fish mocks base method. func (m *MockWater[R, C]) Fish(arg0 R) []C { m.ctrl.T.Helper() From 08f7db9e87792408d12676d6060dfe68fa3d1474 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Tue, 24 Sep 2024 20:23:04 +0300 Subject: [PATCH 09/16] changed test for compatibility with type aliases --- ci/test.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci/test.sh b/ci/test.sh index 27092bd..9dd1fb8 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -1,6 +1,9 @@ #!/bin/bash # This script is used to ensure that the go.mod file is up to date. +# Compatibility for Go 1.22 +export GODEBUG=gotypesalias=1 + set -euo pipefail for i in $(find $PWD -name go.mod); do From 5b309e71898eb7e051a296777da3044632147db6 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Thu, 26 Sep 2024 20:14:19 +0300 Subject: [PATCH 10/16] review changes: * fixed type conversion for support go1.22 * simplified loops by using range * removed unused method "generateSalt" * renamed method of test interface: GiveBirth -> AddHumans --- mockgen/import_mode.go | 67 +++++++------------ mockgen/import_mode_test.go | 2 +- .../internal/tests/import_mode/interfaces.go | 2 +- .../tests/import_mode/mock/interfaces.go | 24 +++---- 4 files changed, 40 insertions(+), 55 deletions(-) diff --git a/mockgen/import_mode.go b/mockgen/import_mode.go index 98d8094..77b11fa 100644 --- a/mockgen/import_mode.go +++ b/mockgen/import_mode.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "go/types" - "math/rand" "go.uber.org/mock/mockgen/model" "golang.org/x/tools/go/packages" @@ -59,17 +58,6 @@ func (p *importModeParser) loadPackage(packageName string) (*packages.Package, e return pkgs[0], nil } -func (p *importModeParser) generateSalt() string { - var numbers = []byte("0123456789") - - result := make([]byte, 8) - for i := range result { - result[i] = numbers[rand.Intn(len(numbers))] - } - - return string(result) -} - func (p *importModeParser) extractInterfacesFromPackage(pkg *packages.Package, ifaces []string) ([]*model.Interface, error) { interfaces := make([]*model.Interface, len(ifaces)) for i, iface := range ifaces { @@ -105,7 +93,7 @@ func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, e } methods := make([]*model.Method, iface.NumMethods()) - for i := 0; i < iface.NumMethods(); i++ { + for i := range iface.NumMethods() { method := iface.Method(i) typedMethod, ok := method.Type().(*types.Signature) if !ok { @@ -125,25 +113,26 @@ func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, e } } - var typeParams []*model.Parameter - if named.TypeParams() != nil { - typeParams = make([]*model.Parameter, named.TypeParams().Len()) - for i := 0; i < named.TypeParams().Len(); i++ { - param := named.TypeParams().At(i) - typeParam, err := p.parseConstraint(param) - if err != nil { - return nil, newParseTypeError("parse type parameter", param.String(), err) - } + if named.TypeParams() == nil { + return &model.Interface{Name: obj.Name(), Methods: methods}, nil + } - typeParams[i] = &model.Parameter{Name: param.Obj().Name(), Type: typeParam} + typeParams := make([]*model.Parameter, named.TypeParams().Len()) + for i := range named.TypeParams().Len() { + param := named.TypeParams().At(i) + typeParam, err := p.parseConstraint(param) + if err != nil { + return nil, newParseTypeError("parse type parameter", param.String(), err) } + + typeParams[i] = &model.Parameter{Name: param.Obj().Name(), Type: typeParam} } return &model.Interface{Name: obj.Name(), Methods: methods, TypeParams: typeParams}, nil } func (o *importModeParser) isConstraint(t *types.Interface) bool { - for i := 0; i < t.NumEmbeddeds(); i++ { + for i := range t.NumEmbeddeds() { embed := t.EmbeddedType(i) if _, ok := embed.Underlying().(*types.Interface); !ok { return true @@ -191,22 +180,24 @@ func (p *importModeParser) parseType(t types.Type) (model.Type, error) { return sig, nil case *types.Named, *types.Alias: - named := t.(namedType) + object := t.(interface{ Obj() *types.TypeName }) var pkg string - if named.Obj().Pkg() != nil { - pkg = named.Obj().Pkg().Path() + if object.Obj().Pkg() != nil { + pkg = object.Obj().Pkg().Path() } - if named.TypeArgs() == nil { + // TypeArgs method not available for aliases in go1.22 + genericType, ok := t.(interface{ TypeArgs() *types.TypeList }) + if !ok || genericType.TypeArgs() == nil { return &model.NamedType{ Package: pkg, - Type: named.Obj().Name(), + Type: object.Obj().Name(), }, nil } - typeParams := &model.TypeParametersType{TypeParameters: make([]model.Type, named.TypeArgs().Len())} - for i := 0; i < named.TypeArgs().Len(); i++ { - typeParam := named.TypeArgs().At(i) + typeParams := &model.TypeParametersType{TypeParameters: make([]model.Type, genericType.TypeArgs().Len())} + for i := range genericType.TypeArgs().Len() { + typeParam := genericType.TypeArgs().At(i) typedParam, err := p.parseType(typeParam) if err != nil { return nil, newParseTypeError("parse type parameter", typeParam.String(), err) @@ -217,7 +208,7 @@ func (p *importModeParser) parseType(t types.Type) (model.Type, error) { return &model.NamedType{ Package: pkg, - Type: named.Obj().Name(), + Type: object.Obj().Name(), TypeParams: typeParams, }, nil case *types.Interface: @@ -264,7 +255,7 @@ func (p *importModeParser) parseType(t types.Type) (model.Type, error) { func (p *importModeParser) parseFunc(sig *types.Signature) (*model.FuncType, error) { var variadic *model.Parameter params := make([]*model.Parameter, 0, sig.Params().Len()) - for i := 0; i < sig.Params().Len(); i++ { + for i := range sig.Params().Len() { param := sig.Params().At(i) isVariadicParam := i == sig.Params().Len()-1 && sig.Variadic() @@ -297,7 +288,7 @@ func (p *importModeParser) parseFunc(sig *types.Signature) (*model.FuncType, err } results := make([]*model.Parameter, sig.Results().Len()) - for i := 0; i < sig.Results().Len(); i++ { + for i := range sig.Results().Len() { result := sig.Results().At(i) resultType, err := p.parseType(result.Type()) @@ -353,9 +344,3 @@ func (p parseTypeError) Error() string { func (p parseTypeError) Unwrap() error { return p.error } - -// namedType is an interface for combining Named and Alias -type namedType interface { - Obj() *types.TypeName - TypeArgs() *types.TypeList -} diff --git a/mockgen/import_mode_test.go b/mockgen/import_mode_test.go index 0e0268e..99cd7ba 100644 --- a/mockgen/import_mode_test.go +++ b/mockgen/import_mode_test.go @@ -310,7 +310,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { Name: "Earth", Methods: []*model.Method{ { - Name: "GiveBirth", + Name: "AddHumans", In: []*model.Parameter{ { Type: &model.NamedType{ diff --git a/mockgen/internal/tests/import_mode/interfaces.go b/mockgen/internal/tests/import_mode/interfaces.go index 2c23bad..b3087aa 100644 --- a/mockgen/internal/tests/import_mode/interfaces.go +++ b/mockgen/internal/tests/import_mode/interfaces.go @@ -63,6 +63,6 @@ type Counter interface { type HumansCount = int type Earth interface { - GiveBirth(HumansCount) []Human + AddHumans(HumansCount) []Human HumanPopulation() HumansCount } diff --git a/mockgen/internal/tests/import_mode/mock/interfaces.go b/mockgen/internal/tests/import_mode/mock/interfaces.go index 770de9c..d99ecbf 100644 --- a/mockgen/internal/tests/import_mode/mock/interfaces.go +++ b/mockgen/internal/tests/import_mode/mock/interfaces.go @@ -1381,40 +1381,40 @@ func (m *MockEarth) EXPECT() *MockEarthMockRecorder { return m.recorder } -// GiveBirth mocks base method. -func (m *MockEarth) GiveBirth(arg0 import_mode.HumansCount) []import_mode.Human { +// AddHumans mocks base method. +func (m *MockEarth) AddHumans(arg0 import_mode.HumansCount) []import_mode.Human { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GiveBirth", arg0) + ret := m.ctrl.Call(m, "AddHumans", arg0) ret0, _ := ret[0].([]import_mode.Human) return ret0 } -// GiveBirth indicates an expected call of GiveBirth. -func (mr *MockEarthMockRecorder) GiveBirth(arg0 any) *MockEarthGiveBirthCall { +// AddHumans indicates an expected call of AddHumans. +func (mr *MockEarthMockRecorder) AddHumans(arg0 any) *MockEarthAddHumansCall { mr.mock.ctrl.T.Helper() - call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GiveBirth", reflect.TypeOf((*MockEarth)(nil).GiveBirth), arg0) - return &MockEarthGiveBirthCall{Call: call} + call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddHumans", reflect.TypeOf((*MockEarth)(nil).AddHumans), arg0) + return &MockEarthAddHumansCall{Call: call} } -// MockEarthGiveBirthCall wrap *gomock.Call -type MockEarthGiveBirthCall struct { +// MockEarthAddHumansCall wrap *gomock.Call +type MockEarthAddHumansCall struct { *gomock.Call } // Return rewrite *gomock.Call.Return -func (c *MockEarthGiveBirthCall) Return(arg0 []import_mode.Human) *MockEarthGiveBirthCall { +func (c *MockEarthAddHumansCall) Return(arg0 []import_mode.Human) *MockEarthAddHumansCall { c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockEarthGiveBirthCall) Do(f func(import_mode.HumansCount) []import_mode.Human) *MockEarthGiveBirthCall { +func (c *MockEarthAddHumansCall) Do(f func(import_mode.HumansCount) []import_mode.Human) *MockEarthAddHumansCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockEarthGiveBirthCall) DoAndReturn(f func(import_mode.HumansCount) []import_mode.Human) *MockEarthGiveBirthCall { +func (c *MockEarthAddHumansCall) DoAndReturn(f func(import_mode.HumansCount) []import_mode.Human) *MockEarthAddHumansCall { c.Call = c.Call.DoAndReturn(f) return c } From 6fc5cf52532ae29633fd0a6a79c9fee22a94c005 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Fri, 27 Sep 2024 19:51:47 +0300 Subject: [PATCH 11/16] behavior changed to default in go1.22 without GODEBUG features --- ci/test.sh | 3 --- mockgen/import_mode_test.go | 12 +++-------- .../tests/import_mode/mock/interfaces.go | 20 +++++++++---------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/ci/test.sh b/ci/test.sh index 9dd1fb8..27092bd 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -1,9 +1,6 @@ #!/bin/bash # This script is used to ensure that the go.mod file is up to date. -# Compatibility for Go 1.22 -export GODEBUG=gotypesalias=1 - set -euo pipefail for i in $(find $PWD -name go.mod); do diff --git a/mockgen/import_mode_test.go b/mockgen/import_mode_test.go index 99cd7ba..c5df56a 100644 --- a/mockgen/import_mode_test.go +++ b/mockgen/import_mode_test.go @@ -313,10 +313,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { Name: "AddHumans", In: []*model.Parameter{ { - Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", - Type: "HumansCount", - }, + Type: model.PredeclaredType("int"), }, }, Out: []*model.Parameter{ @@ -325,7 +322,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { Len: -1, // slice Type: &model.NamedType{ Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", - Type: "Human", + Type: "Primate", }, }, }, @@ -335,10 +332,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { Name: "HumanPopulation", Out: []*model.Parameter{ { - Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", - Type: "HumansCount", - }, + Type: model.PredeclaredType("int"), }, }, }, diff --git a/mockgen/internal/tests/import_mode/mock/interfaces.go b/mockgen/internal/tests/import_mode/mock/interfaces.go index d99ecbf..0279d21 100644 --- a/mockgen/internal/tests/import_mode/mock/interfaces.go +++ b/mockgen/internal/tests/import_mode/mock/interfaces.go @@ -1382,10 +1382,10 @@ func (m *MockEarth) EXPECT() *MockEarthMockRecorder { } // AddHumans mocks base method. -func (m *MockEarth) AddHumans(arg0 import_mode.HumansCount) []import_mode.Human { +func (m *MockEarth) AddHumans(arg0 int) []import_mode.Primate { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddHumans", arg0) - ret0, _ := ret[0].([]import_mode.Human) + ret0, _ := ret[0].([]import_mode.Primate) return ret0 } @@ -1402,28 +1402,28 @@ type MockEarthAddHumansCall struct { } // Return rewrite *gomock.Call.Return -func (c *MockEarthAddHumansCall) Return(arg0 []import_mode.Human) *MockEarthAddHumansCall { +func (c *MockEarthAddHumansCall) Return(arg0 []import_mode.Primate) *MockEarthAddHumansCall { c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockEarthAddHumansCall) Do(f func(import_mode.HumansCount) []import_mode.Human) *MockEarthAddHumansCall { +func (c *MockEarthAddHumansCall) Do(f func(int) []import_mode.Primate) *MockEarthAddHumansCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockEarthAddHumansCall) DoAndReturn(f func(import_mode.HumansCount) []import_mode.Human) *MockEarthAddHumansCall { +func (c *MockEarthAddHumansCall) DoAndReturn(f func(int) []import_mode.Primate) *MockEarthAddHumansCall { c.Call = c.Call.DoAndReturn(f) return c } // HumanPopulation mocks base method. -func (m *MockEarth) HumanPopulation() import_mode.HumansCount { +func (m *MockEarth) HumanPopulation() int { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "HumanPopulation") - ret0, _ := ret[0].(import_mode.HumansCount) + ret0, _ := ret[0].(int) return ret0 } @@ -1440,19 +1440,19 @@ type MockEarthHumanPopulationCall struct { } // Return rewrite *gomock.Call.Return -func (c *MockEarthHumanPopulationCall) Return(arg0 import_mode.HumansCount) *MockEarthHumanPopulationCall { +func (c *MockEarthHumanPopulationCall) Return(arg0 int) *MockEarthHumanPopulationCall { c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockEarthHumanPopulationCall) Do(f func() import_mode.HumansCount) *MockEarthHumanPopulationCall { +func (c *MockEarthHumanPopulationCall) Do(f func() int) *MockEarthHumanPopulationCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockEarthHumanPopulationCall) DoAndReturn(f func() import_mode.HumansCount) *MockEarthHumanPopulationCall { +func (c *MockEarthHumanPopulationCall) DoAndReturn(f func() int) *MockEarthHumanPopulationCall { c.Call = c.Call.DoAndReturn(f) return c } From 69210e9badcc1aacba501d26e5c40b3ff79de2d9 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Fri, 27 Sep 2024 22:15:18 +0300 Subject: [PATCH 12/16] import mode renamed to package mode in: * tests * help message * README.md --- README.md | 17 +- mockgen/internal/tests/generics/generics.go | 2 +- .../generics/import_mode/import_mode_test.go | 23 - .../import_mode/mock_external_mock.go | 607 ------------------ .../mock_test.go | 6 +- .../tests/import_mode/mock/interfaces_test.go | 41 -- .../cars/cars.go | 2 +- .../fuel/fuel.go | 0 .../interfaces.go | 6 +- .../mock/interfaces.go | 76 +-- .../package_mode/mock/interfaces_test.go | 41 ++ mockgen/mockgen.go | 21 +- mockgen/{import_mode.go => package_mode.go} | 18 +- ...port_mode_test.go => package_mode_test.go} | 66 +- 14 files changed, 145 insertions(+), 781 deletions(-) delete mode 100644 mockgen/internal/tests/generics/import_mode/import_mode_test.go delete mode 100644 mockgen/internal/tests/generics/import_mode/mock_external_mock.go rename mockgen/internal/tests/generics/{import_mode => package_mode}/mock_test.go (98%) delete mode 100644 mockgen/internal/tests/import_mode/mock/interfaces_test.go rename mockgen/internal/tests/{import_mode => package_mode}/cars/cars.go (91%) rename mockgen/internal/tests/{import_mode => package_mode}/fuel/fuel.go (100%) rename mockgen/internal/tests/{import_mode => package_mode}/interfaces.go (87%) rename mockgen/internal/tests/{import_mode => package_mode}/mock/interfaces.go (92%) create mode 100644 mockgen/internal/tests/package_mode/mock/interfaces_test.go rename mockgen/{import_mode.go => package_mode.go} (91%) rename mockgen/{import_mode_test.go => package_mode_test.go} (76%) diff --git a/README.md b/README.md index 7f8b414..2a5f4fb 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ export PATH=$PATH:$(go env GOPATH)/bin ## Running mockgen -`mockgen` has two modes of operation: source and reflect. +`mockgen` has two modes of operation: source and package. ### Source mode @@ -54,11 +54,10 @@ Example: mockgen -source=foo.go [other options] ``` -### Reflect mode +### Package mode -Reflect mode generates mock interfaces by building a program -that uses reflection to understand interfaces. It is enabled -by passing two non-flag arguments: an import path, and a +Package mode works by specifying the package and interface names. +It is enabled by passing two non-flag arguments: an import path, and a comma-separated list of symbols. You can use "." to refer to the current path's package. @@ -98,8 +97,6 @@ It supports the following flags: `foo=bar/baz.go`, where `bar/baz.go` is the source file and `foo` is the package name of that file used by the -source file. -- `-build_flags`: (reflect mode only) Flags passed verbatim to `go build`. - - `-mock_names`: A list of custom names for generated mocks. This is specified as a comma-separated list of elements of the form `Repository=MockSensorRepository,Endpoint=MockSensorEndpoint`, where @@ -119,15 +116,11 @@ It supports the following flags: - `-debug_parser`: Print out parser results only. -- `-exec_only`: (reflect mode) If set, execute this reflection program. - -- `-prog_only`: (reflect mode) Only generate the reflection program; write it to stdout and exit. - - `-write_package_comment`: Writes package documentation comment (godoc) if true. (default true) - `-write_generate_directive`: Add //go:generate directive to regenerate the mock. (default false) -- `-write_source_comment`: Writes original file (source mode) or interface names (reflect mode) comment if true. (default true) +- `-write_source_comment`: Writes original file (source mode) or interface names (package mode) comment if true. (default true) - `-typed`: Generate Type-safe 'Return', 'Do', 'DoAndReturn' function. (default false) diff --git a/mockgen/internal/tests/generics/generics.go b/mockgen/internal/tests/generics/generics.go index a788f21..5ff70f8 100644 --- a/mockgen/internal/tests/generics/generics.go +++ b/mockgen/internal/tests/generics/generics.go @@ -6,7 +6,7 @@ import ( ) //go:generate mockgen --source=generics.go --destination=source/mock_generics_mock.go --package source -//go:generate mockgen --destination=import_mode/mock_test.go --package=import_mode . Bar,Universe,MilkyWay,SolarSystem,Earth,Water +//go:generate mockgen --destination=package_mode/mock_test.go --package=package_mode . Bar,Universe,MilkyWay,SolarSystem,Earth,Water type Bar[T any, R any] interface { One(string) string diff --git a/mockgen/internal/tests/generics/import_mode/import_mode_test.go b/mockgen/internal/tests/generics/import_mode/import_mode_test.go deleted file mode 100644 index 462af95..0000000 --- a/mockgen/internal/tests/generics/import_mode/import_mode_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package import_mode - -import ( - "go.uber.org/mock/mockgen/internal/tests/generics" -) - -var bar generics.Bar[int, int] = &MockBar[int, int]{} - -var universe generics.Universe[int] = &MockUniverse[int]{} - -var solarSystem generics.SolarSystem[int] = &MockSolarSystem[int]{} - -var earth generics.Earth[int] = &MockEarth[int]{} - -var water generics.Water[int, uint] = &MockWater[int, uint]{} - -var externalConstraint generics.ExternalConstraint[int64, int] = &MockExternalConstraint[int64, int]{} - -var embeddedIface generics.EmbeddingIface[int, float64] = &MockEmbeddingIface[int, float64]{} - -var generator generics.Generator[int] = &MockGenerator[int]{} - -var group generics.Group[generics.Generator[any]] = &MockGroup[generics.Generator[any]]{} diff --git a/mockgen/internal/tests/generics/import_mode/mock_external_mock.go b/mockgen/internal/tests/generics/import_mode/mock_external_mock.go deleted file mode 100644 index a2bdea9..0000000 --- a/mockgen/internal/tests/generics/import_mode/mock_external_mock.go +++ /dev/null @@ -1,607 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: go.uber.org/mock/mockgen/internal/tests/generics (interfaces: ExternalConstraint,EmbeddingIface,Generator,Group) -// -// Generated by this command: -// -// mockgen --destination=import_mode/mock_external_mock.go -package=import_mode . ExternalConstraint,EmbeddingIface,Generator,Group -// - -// Package import_mode is a generated GoMock package. -package import_mode - -import ( - context "context" - reflect "reflect" - - gomock "go.uber.org/mock/gomock" - generics "go.uber.org/mock/mockgen/internal/tests/generics" - other "go.uber.org/mock/mockgen/internal/tests/generics/other" - constraints "golang.org/x/exp/constraints" -) - -// MockExternalConstraint is a mock of ExternalConstraint interface. -type MockExternalConstraint[I constraints.Integer, F any] struct { - ctrl *gomock.Controller - recorder *MockExternalConstraintMockRecorder[I, F] - isgomock struct{} -} - -// MockExternalConstraintMockRecorder is the mock recorder for MockExternalConstraint. -type MockExternalConstraintMockRecorder[I constraints.Integer, F any] struct { - mock *MockExternalConstraint[I, F] -} - -// NewMockExternalConstraint creates a new mock instance. -func NewMockExternalConstraint[I constraints.Integer, F any](ctrl *gomock.Controller) *MockExternalConstraint[I, F] { - mock := &MockExternalConstraint[I, F]{ctrl: ctrl} - mock.recorder = &MockExternalConstraintMockRecorder[I, F]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockExternalConstraint[I, F]) EXPECT() *MockExternalConstraintMockRecorder[I, F] { - return m.recorder -} - -// Eight mocks base method. -func (m *MockExternalConstraint[I, F]) Eight(arg0 F) other.Two[I, F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Eight", arg0) - ret0, _ := ret[0].(other.Two[I, F]) - return ret0 -} - -// Eight indicates an expected call of Eight. -func (mr *MockExternalConstraintMockRecorder[I, F]) Eight(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eight), arg0) -} - -// Eleven mocks base method. -func (m *MockExternalConstraint[I, F]) Eleven() map[string]I { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Eleven") - ret0, _ := ret[0].(map[string]I) - return ret0 -} - -// Eleven indicates an expected call of Eleven. -func (mr *MockExternalConstraintMockRecorder[I, F]) Eleven() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eleven)) -} - -// Five mocks base method. -func (m *MockExternalConstraint[I, F]) Five(arg0 I) generics.Baz[F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Five", arg0) - ret0, _ := ret[0].(generics.Baz[F]) - return ret0 -} - -// Five indicates an expected call of Five. -func (mr *MockExternalConstraintMockRecorder[I, F]) Five(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Five), arg0) -} - -// Four mocks base method. -func (m *MockExternalConstraint[I, F]) Four(arg0 I) generics.Foo[I, F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Four", arg0) - ret0, _ := ret[0].(generics.Foo[I, F]) - return ret0 -} - -// Four indicates an expected call of Four. -func (mr *MockExternalConstraintMockRecorder[I, F]) Four(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Four), arg0) -} - -// Nine mocks base method. -func (m *MockExternalConstraint[I, F]) Nine(arg0 generics.Iface[I]) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Nine", arg0) -} - -// Nine indicates an expected call of Nine. -func (mr *MockExternalConstraintMockRecorder[I, F]) Nine(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Nine), arg0) -} - -// One mocks base method. -func (m *MockExternalConstraint[I, F]) One(arg0 string) string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "One", arg0) - ret0, _ := ret[0].(string) - return ret0 -} - -// One indicates an expected call of One. -func (mr *MockExternalConstraintMockRecorder[I, F]) One(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).One), arg0) -} - -// Seven mocks base method. -func (m *MockExternalConstraint[I, F]) Seven(arg0 I) other.One[I] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Seven", arg0) - ret0, _ := ret[0].(other.One[I]) - return ret0 -} - -// Seven indicates an expected call of Seven. -func (mr *MockExternalConstraintMockRecorder[I, F]) Seven(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Seven), arg0) -} - -// Six mocks base method. -func (m *MockExternalConstraint[I, F]) Six(arg0 I) *generics.Baz[F] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Six", arg0) - ret0, _ := ret[0].(*generics.Baz[F]) - return ret0 -} - -// Six indicates an expected call of Six. -func (mr *MockExternalConstraintMockRecorder[I, F]) Six(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Six), arg0) -} - -// Ten mocks base method. -func (m *MockExternalConstraint[I, F]) Ten(arg0 *I) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Ten", arg0) -} - -// Ten indicates an expected call of Ten. -func (mr *MockExternalConstraintMockRecorder[I, F]) Ten(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Ten), arg0) -} - -// Thirteen mocks base method. -func (m *MockExternalConstraint[I, F]) Thirteen(arg0 ...I) *F { - m.ctrl.T.Helper() - varargs := []any{} - for _, a := range arg0 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Thirteen", varargs...) - ret0, _ := ret[0].(*F) - return ret0 -} - -// Thirteen indicates an expected call of Thirteen. -func (mr *MockExternalConstraintMockRecorder[I, F]) Thirteen(arg0 ...any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Thirteen), arg0...) -} - -// Three mocks base method. -func (m *MockExternalConstraint[I, F]) Three(arg0 I) F { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Three", arg0) - ret0, _ := ret[0].(F) - return ret0 -} - -// Three indicates an expected call of Three. -func (mr *MockExternalConstraintMockRecorder[I, F]) Three(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Three), arg0) -} - -// Twelve mocks base method. -func (m *MockExternalConstraint[I, F]) Twelve(ctx context.Context) <-chan []I { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Twelve", ctx) - ret0, _ := ret[0].(<-chan []I) - return ret0 -} - -// Twelve indicates an expected call of Twelve. -func (mr *MockExternalConstraintMockRecorder[I, F]) Twelve(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Twelve), ctx) -} - -// Two mocks base method. -func (m *MockExternalConstraint[I, F]) Two(arg0 I) string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Two", arg0) - ret0, _ := ret[0].(string) - return ret0 -} - -// Two indicates an expected call of Two. -func (mr *MockExternalConstraintMockRecorder[I, F]) Two(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Two), arg0) -} - -// MockEmbeddingIface is a mock of EmbeddingIface interface. -type MockEmbeddingIface[T constraints.Integer, R constraints.Float] struct { - ctrl *gomock.Controller - recorder *MockEmbeddingIfaceMockRecorder[T, R] - isgomock struct{} -} - -// MockEmbeddingIfaceMockRecorder is the mock recorder for MockEmbeddingIface. -type MockEmbeddingIfaceMockRecorder[T constraints.Integer, R constraints.Float] struct { - mock *MockEmbeddingIface[T, R] -} - -// NewMockEmbeddingIface creates a new mock instance. -func NewMockEmbeddingIface[T constraints.Integer, R constraints.Float](ctrl *gomock.Controller) *MockEmbeddingIface[T, R] { - mock := &MockEmbeddingIface[T, R]{ctrl: ctrl} - mock.recorder = &MockEmbeddingIfaceMockRecorder[T, R]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockEmbeddingIface[T, R]) EXPECT() *MockEmbeddingIfaceMockRecorder[T, R] { - return m.recorder -} - -// Eight mocks base method. -func (m *MockEmbeddingIface[T, R]) Eight(arg0 R) other.Two[T, R] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Eight", arg0) - ret0, _ := ret[0].(other.Two[T, R]) - return ret0 -} - -// Eight indicates an expected call of Eight. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eight(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eight), arg0) -} - -// Eleven mocks base method. -func (m *MockEmbeddingIface[T, R]) Eleven() map[string]T { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Eleven") - ret0, _ := ret[0].(map[string]T) - return ret0 -} - -// Eleven indicates an expected call of Eleven. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eleven() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eleven)) -} - -// First mocks base method. -func (m *MockEmbeddingIface[T, R]) First() R { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "First") - ret0, _ := ret[0].(R) - return ret0 -} - -// First indicates an expected call of First. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) First() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "First", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).First)) -} - -// Five mocks base method. -func (m *MockEmbeddingIface[T, R]) Five(arg0 T) generics.Baz[R] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Five", arg0) - ret0, _ := ret[0].(generics.Baz[R]) - return ret0 -} - -// Five indicates an expected call of Five. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Five(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Five), arg0) -} - -// Four mocks base method. -func (m *MockEmbeddingIface[T, R]) Four(arg0 T) generics.Foo[T, R] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Four", arg0) - ret0, _ := ret[0].(generics.Foo[T, R]) - return ret0 -} - -// Four indicates an expected call of Four. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Four(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Four), arg0) -} - -// Fourth mocks base method. -func (m *MockEmbeddingIface[T, R]) Fourth() generics.Generator[T] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Fourth") - ret0, _ := ret[0].(generics.Generator[T]) - return ret0 -} - -// Fourth indicates an expected call of Fourth. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Fourth() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fourth", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Fourth)) -} - -// Generate mocks base method. -func (m *MockEmbeddingIface[T, R]) Generate() R { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Generate") - ret0, _ := ret[0].(R) - return ret0 -} - -// Generate indicates an expected call of Generate. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Generate() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Generate)) -} - -// Nine mocks base method. -func (m *MockEmbeddingIface[T, R]) Nine(arg0 generics.Iface[T]) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Nine", arg0) -} - -// Nine indicates an expected call of Nine. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Nine(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Nine), arg0) -} - -// One mocks base method. -func (m *MockEmbeddingIface[T, R]) One(arg0 string) string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "One", arg0) - ret0, _ := ret[0].(string) - return ret0 -} - -// One indicates an expected call of One. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) One(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).One), arg0) -} - -// Read mocks base method. -func (m *MockEmbeddingIface[T, R]) Read(p []byte) (int, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Read", p) - ret0, _ := ret[0].(int) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// Read indicates an expected call of Read. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Read(p any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Read), p) -} - -// Second mocks base method. -func (m *MockEmbeddingIface[T, R]) Second() generics.StructType { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Second") - ret0, _ := ret[0].(generics.StructType) - return ret0 -} - -// Second indicates an expected call of Second. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Second() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Second", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Second)) -} - -// Seven mocks base method. -func (m *MockEmbeddingIface[T, R]) Seven(arg0 T) other.One[T] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Seven", arg0) - ret0, _ := ret[0].(other.One[T]) - return ret0 -} - -// Seven indicates an expected call of Seven. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Seven(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Seven), arg0) -} - -// Six mocks base method. -func (m *MockEmbeddingIface[T, R]) Six(arg0 T) *generics.Baz[R] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Six", arg0) - ret0, _ := ret[0].(*generics.Baz[R]) - return ret0 -} - -// Six indicates an expected call of Six. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Six(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Six), arg0) -} - -// Ten mocks base method. -func (m *MockEmbeddingIface[T, R]) Ten(arg0 *T) { - m.ctrl.T.Helper() - m.ctrl.Call(m, "Ten", arg0) -} - -// Ten indicates an expected call of Ten. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Ten(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Ten), arg0) -} - -// Third mocks base method. -func (m *MockEmbeddingIface[T, R]) Third() other.Five { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Third") - ret0, _ := ret[0].(other.Five) - return ret0 -} - -// Third indicates an expected call of Third. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Third() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Third", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Third)) -} - -// Thirteen mocks base method. -func (m *MockEmbeddingIface[T, R]) Thirteen(arg0 ...T) *R { - m.ctrl.T.Helper() - varargs := []any{} - for _, a := range arg0 { - varargs = append(varargs, a) - } - ret := m.ctrl.Call(m, "Thirteen", varargs...) - ret0, _ := ret[0].(*R) - return ret0 -} - -// Thirteen indicates an expected call of Thirteen. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Thirteen(arg0 ...any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Thirteen), arg0...) -} - -// Three mocks base method. -func (m *MockEmbeddingIface[T, R]) Three(arg0 T) R { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Three", arg0) - ret0, _ := ret[0].(R) - return ret0 -} - -// Three indicates an expected call of Three. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Three(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Three), arg0) -} - -// Twelve mocks base method. -func (m *MockEmbeddingIface[T, R]) Twelve(ctx context.Context) <-chan []T { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Twelve", ctx) - ret0, _ := ret[0].(<-chan []T) - return ret0 -} - -// Twelve indicates an expected call of Twelve. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Twelve(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Twelve), ctx) -} - -// Two mocks base method. -func (m *MockEmbeddingIface[T, R]) Two(arg0 T) string { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Two", arg0) - ret0, _ := ret[0].(string) - return ret0 -} - -// Two indicates an expected call of Two. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Two(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Two), arg0) -} - -// Water mocks base method. -func (m *MockEmbeddingIface[T, R]) Water(arg0 generics.Generator[T]) []generics.Generator[T] { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Water", arg0) - ret0, _ := ret[0].([]generics.Generator[T]) - return ret0 -} - -// Water indicates an expected call of Water. -func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Water(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Water), arg0) -} - -// MockGenerator is a mock of Generator interface. -type MockGenerator[T any] struct { - ctrl *gomock.Controller - recorder *MockGeneratorMockRecorder[T] - isgomock struct{} -} - -// MockGeneratorMockRecorder is the mock recorder for MockGenerator. -type MockGeneratorMockRecorder[T any] struct { - mock *MockGenerator[T] -} - -// NewMockGenerator creates a new mock instance. -func NewMockGenerator[T any](ctrl *gomock.Controller) *MockGenerator[T] { - mock := &MockGenerator[T]{ctrl: ctrl} - mock.recorder = &MockGeneratorMockRecorder[T]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockGenerator[T]) EXPECT() *MockGeneratorMockRecorder[T] { - return m.recorder -} - -// Generate mocks base method. -func (m *MockGenerator[T]) Generate() T { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Generate") - ret0, _ := ret[0].(T) - return ret0 -} - -// Generate indicates an expected call of Generate. -func (mr *MockGeneratorMockRecorder[T]) Generate() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockGenerator[T])(nil).Generate)) -} - -// MockGroup is a mock of Group interface. -type MockGroup[T generics.Generator[any]] struct { - ctrl *gomock.Controller - recorder *MockGroupMockRecorder[T] - isgomock struct{} -} - -// MockGroupMockRecorder is the mock recorder for MockGroup. -type MockGroupMockRecorder[T generics.Generator[any]] struct { - mock *MockGroup[T] -} - -// NewMockGroup creates a new mock instance. -func NewMockGroup[T generics.Generator[any]](ctrl *gomock.Controller) *MockGroup[T] { - mock := &MockGroup[T]{ctrl: ctrl} - mock.recorder = &MockGroupMockRecorder[T]{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockGroup[T]) EXPECT() *MockGroupMockRecorder[T] { - return m.recorder -} - -// Join mocks base method. -func (m *MockGroup[T]) Join(ctx context.Context) []T { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Join", ctx) - ret0, _ := ret[0].([]T) - return ret0 -} - -// Join indicates an expected call of Join. -func (mr *MockGroupMockRecorder[T]) Join(ctx any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Join", reflect.TypeOf((*MockGroup[T])(nil).Join), ctx) -} diff --git a/mockgen/internal/tests/generics/import_mode/mock_test.go b/mockgen/internal/tests/generics/package_mode/mock_test.go similarity index 98% rename from mockgen/internal/tests/generics/import_mode/mock_test.go rename to mockgen/internal/tests/generics/package_mode/mock_test.go index da9d200..6a4858b 100644 --- a/mockgen/internal/tests/generics/import_mode/mock_test.go +++ b/mockgen/internal/tests/generics/package_mode/mock_test.go @@ -3,11 +3,11 @@ // // Generated by this command: // -// mockgen --destination=import_mode/mock_test.go --package=import_mode . Bar,Universe,MilkyWay,SolarSystem,Earth,Water +// mockgen --destination=package_mode/mock_test.go --package=package_mode . Bar,Universe,MilkyWay,SolarSystem,Earth,Water // -// Package import_mode is a generated GoMock package. -package import_mode +// Package package_mode is a generated GoMock package. +package package_mode import ( reflect "reflect" diff --git a/mockgen/internal/tests/import_mode/mock/interfaces_test.go b/mockgen/internal/tests/import_mode/mock/interfaces_test.go deleted file mode 100644 index 2d4a8ef..0000000 --- a/mockgen/internal/tests/import_mode/mock/interfaces_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package mock - -import ( - "testing" - - "go.uber.org/mock/gomock" - "go.uber.org/mock/mockgen/internal/tests/import_mode" - "go.uber.org/mock/mockgen/internal/tests/import_mode/cars" - "go.uber.org/mock/mockgen/internal/tests/import_mode/fuel" -) - -// checks, that mocks implement interfaces in compile-time. -// If something breaks, the tests will not be compiled. - -var food import_mode.Food = &MockFood{} - -var eater import_mode.Eater = &MockEater{} - -var animal import_mode.Animal = &MockAnimal{} - -var human import_mode.Human = &MockHuman{} - -var primate import_mode.Primate = &MockPrimate{} - -var car import_mode.Car[fuel.Gasoline] = &MockCar[fuel.Gasoline]{} - -var driver import_mode.Driver[fuel.Gasoline, cars.HyundaiSolaris] = &MockDriver[fuel.Gasoline, cars.HyundaiSolaris]{} - -var urbanResident import_mode.UrbanResident = &MockUrbanResident{} - -var farmer import_mode.Farmer = &MockFarmer{} - -func TestInterfaces(t *testing.T) { - ctrl := gomock.NewController(t) - - mock := NewMockFarmer(ctrl) - mock.EXPECT().Breathe() - - farmer := import_mode.Farmer(mock) - farmer.Breathe() -} diff --git a/mockgen/internal/tests/import_mode/cars/cars.go b/mockgen/internal/tests/package_mode/cars/cars.go similarity index 91% rename from mockgen/internal/tests/import_mode/cars/cars.go rename to mockgen/internal/tests/package_mode/cars/cars.go index 289812b..e8b3396 100644 --- a/mockgen/internal/tests/import_mode/cars/cars.go +++ b/mockgen/internal/tests/package_mode/cars/cars.go @@ -1,7 +1,7 @@ package cars import ( - "go.uber.org/mock/mockgen/internal/tests/import_mode/fuel" + "go.uber.org/mock/mockgen/internal/tests/package_mode/fuel" ) type FuelTank[FuelType fuel.Fuel] struct { diff --git a/mockgen/internal/tests/import_mode/fuel/fuel.go b/mockgen/internal/tests/package_mode/fuel/fuel.go similarity index 100% rename from mockgen/internal/tests/import_mode/fuel/fuel.go rename to mockgen/internal/tests/package_mode/fuel/fuel.go diff --git a/mockgen/internal/tests/import_mode/interfaces.go b/mockgen/internal/tests/package_mode/interfaces.go similarity index 87% rename from mockgen/internal/tests/import_mode/interfaces.go rename to mockgen/internal/tests/package_mode/interfaces.go index b3087aa..aa3df47 100644 --- a/mockgen/internal/tests/import_mode/interfaces.go +++ b/mockgen/internal/tests/package_mode/interfaces.go @@ -1,12 +1,12 @@ -package import_mode +package package_mode //go:generate mockgen -typed -package=mock -destination=mock/interfaces.go . Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,Earth import ( "time" - "go.uber.org/mock/mockgen/internal/tests/import_mode/cars" - "go.uber.org/mock/mockgen/internal/tests/import_mode/fuel" + "go.uber.org/mock/mockgen/internal/tests/package_mode/cars" + "go.uber.org/mock/mockgen/internal/tests/package_mode/fuel" ) type Food interface { diff --git a/mockgen/internal/tests/import_mode/mock/interfaces.go b/mockgen/internal/tests/package_mode/mock/interfaces.go similarity index 92% rename from mockgen/internal/tests/import_mode/mock/interfaces.go rename to mockgen/internal/tests/package_mode/mock/interfaces.go index 0279d21..1cb6ffd 100644 --- a/mockgen/internal/tests/import_mode/mock/interfaces.go +++ b/mockgen/internal/tests/package_mode/mock/interfaces.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: go.uber.org/mock/mockgen/internal/tests/import_mode (interfaces: Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,Earth) +// Source: go.uber.org/mock/mockgen/internal/tests/package_mode (interfaces: Food,Eater,Animal,Human,Primate,Car,Driver,UrbanResident,Farmer,Earth) // // Generated by this command: // @@ -14,9 +14,9 @@ import ( time "time" gomock "go.uber.org/mock/gomock" - import_mode "go.uber.org/mock/mockgen/internal/tests/import_mode" - cars "go.uber.org/mock/mockgen/internal/tests/import_mode/cars" - fuel "go.uber.org/mock/mockgen/internal/tests/import_mode/fuel" + package_mode "go.uber.org/mock/mockgen/internal/tests/package_mode" + cars "go.uber.org/mock/mockgen/internal/tests/package_mode/cars" + fuel "go.uber.org/mock/mockgen/internal/tests/package_mode/fuel" ) // MockFood is a mock of Food interface. @@ -106,7 +106,7 @@ func (m *MockEater) EXPECT() *MockEaterMockRecorder { } // Eat mocks base method. -func (m *MockEater) Eat(foods ...import_mode.Food) { +func (m *MockEater) Eat(foods ...package_mode.Food) { m.ctrl.T.Helper() varargs := []any{} for _, a := range foods { @@ -134,13 +134,13 @@ func (c *MockEaterEatCall) Return() *MockEaterEatCall { } // Do rewrite *gomock.Call.Do -func (c *MockEaterEatCall) Do(f func(...import_mode.Food)) *MockEaterEatCall { +func (c *MockEaterEatCall) Do(f func(...package_mode.Food)) *MockEaterEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockEaterEatCall) DoAndReturn(f func(...import_mode.Food)) *MockEaterEatCall { +func (c *MockEaterEatCall) DoAndReturn(f func(...package_mode.Food)) *MockEaterEatCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -206,7 +206,7 @@ func (c *MockAnimalBreatheCall) DoAndReturn(f func()) *MockAnimalBreatheCall { } // Eat mocks base method. -func (m *MockAnimal) Eat(foods ...import_mode.Food) { +func (m *MockAnimal) Eat(foods ...package_mode.Food) { m.ctrl.T.Helper() varargs := []any{} for _, a := range foods { @@ -234,13 +234,13 @@ func (c *MockAnimalEatCall) Return() *MockAnimalEatCall { } // Do rewrite *gomock.Call.Do -func (c *MockAnimalEatCall) Do(f func(...import_mode.Food)) *MockAnimalEatCall { +func (c *MockAnimalEatCall) Do(f func(...package_mode.Food)) *MockAnimalEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockAnimalEatCall) DoAndReturn(f func(...import_mode.Food)) *MockAnimalEatCall { +func (c *MockAnimalEatCall) DoAndReturn(f func(...package_mode.Food)) *MockAnimalEatCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -342,7 +342,7 @@ func (c *MockHumanBreatheCall) DoAndReturn(f func()) *MockHumanBreatheCall { } // Eat mocks base method. -func (m *MockHuman) Eat(foods ...import_mode.Food) { +func (m *MockHuman) Eat(foods ...package_mode.Food) { m.ctrl.T.Helper() varargs := []any{} for _, a := range foods { @@ -370,13 +370,13 @@ func (c *MockHumanEatCall) Return() *MockHumanEatCall { } // Do rewrite *gomock.Call.Do -func (c *MockHumanEatCall) Do(f func(...import_mode.Food)) *MockHumanEatCall { +func (c *MockHumanEatCall) Do(f func(...package_mode.Food)) *MockHumanEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockHumanEatCall) DoAndReturn(f func(...import_mode.Food)) *MockHumanEatCall { +func (c *MockHumanEatCall) DoAndReturn(f func(...package_mode.Food)) *MockHumanEatCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -478,7 +478,7 @@ func (c *MockPrimateBreatheCall) DoAndReturn(f func()) *MockPrimateBreatheCall { } // Eat mocks base method. -func (m *MockPrimate) Eat(foods ...import_mode.Food) { +func (m *MockPrimate) Eat(foods ...package_mode.Food) { m.ctrl.T.Helper() varargs := []any{} for _, a := range foods { @@ -506,13 +506,13 @@ func (c *MockPrimateEatCall) Return() *MockPrimateEatCall { } // Do rewrite *gomock.Call.Do -func (c *MockPrimateEatCall) Do(f func(...import_mode.Food)) *MockPrimateEatCall { +func (c *MockPrimateEatCall) Do(f func(...package_mode.Food)) *MockPrimateEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockPrimateEatCall) DoAndReturn(f func(...import_mode.Food)) *MockPrimateEatCall { +func (c *MockPrimateEatCall) DoAndReturn(f func(...package_mode.Food)) *MockPrimateEatCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -692,19 +692,19 @@ func (c *MockCarRefuelCall[FuelType]) DoAndReturn(f func(FuelType, int) error) * } // MockDriver is a mock of Driver interface. -type MockDriver[FuelType fuel.Fuel, CarType import_mode.Car[FuelType]] struct { +type MockDriver[FuelType fuel.Fuel, CarType package_mode.Car[FuelType]] struct { ctrl *gomock.Controller recorder *MockDriverMockRecorder[FuelType, CarType] isgomock struct{} } // MockDriverMockRecorder is the mock recorder for MockDriver. -type MockDriverMockRecorder[FuelType fuel.Fuel, CarType import_mode.Car[FuelType]] struct { +type MockDriverMockRecorder[FuelType fuel.Fuel, CarType package_mode.Car[FuelType]] struct { mock *MockDriver[FuelType, CarType] } // NewMockDriver creates a new mock instance. -func NewMockDriver[FuelType fuel.Fuel, CarType import_mode.Car[FuelType]](ctrl *gomock.Controller) *MockDriver[FuelType, CarType] { +func NewMockDriver[FuelType fuel.Fuel, CarType package_mode.Car[FuelType]](ctrl *gomock.Controller) *MockDriver[FuelType, CarType] { mock := &MockDriver[FuelType, CarType]{ctrl: ctrl} mock.recorder = &MockDriverMockRecorder[FuelType, CarType]{mock} return mock @@ -729,7 +729,7 @@ func (mr *MockDriverMockRecorder[FuelType, CarType]) Drive(car any) *MockDriverD } // MockDriverDriveCall wrap *gomock.Call -type MockDriverDriveCall[FuelType fuel.Fuel, CarType import_mode.Car[FuelType]] struct { +type MockDriverDriveCall[FuelType fuel.Fuel, CarType package_mode.Car[FuelType]] struct { *gomock.Call } @@ -767,7 +767,7 @@ func (mr *MockDriverMockRecorder[FuelType, CarType]) Wroom() *MockDriverWroomCal } // MockDriverWroomCall wrap *gomock.Call -type MockDriverWroomCall[FuelType fuel.Fuel, CarType import_mode.Car[FuelType]] struct { +type MockDriverWroomCall[FuelType fuel.Fuel, CarType package_mode.Car[FuelType]] struct { *gomock.Call } @@ -850,7 +850,7 @@ func (c *MockUrbanResidentBreatheCall) DoAndReturn(f func()) *MockUrbanResidentB } // Do mocks base method. -func (m *MockUrbanResident) Do(work *import_mode.Work) error { +func (m *MockUrbanResident) Do(work *package_mode.Work) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Do", work) ret0, _ := ret[0].(error) @@ -876,13 +876,13 @@ func (c *MockUrbanResidentDoCall) Return(arg0 error) *MockUrbanResidentDoCall { } // Do rewrite *gomock.Call.Do -func (c *MockUrbanResidentDoCall) Do(f func(*import_mode.Work) error) *MockUrbanResidentDoCall { +func (c *MockUrbanResidentDoCall) Do(f func(*package_mode.Work) error) *MockUrbanResidentDoCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockUrbanResidentDoCall) DoAndReturn(f func(*import_mode.Work) error) *MockUrbanResidentDoCall { +func (c *MockUrbanResidentDoCall) DoAndReturn(f func(*package_mode.Work) error) *MockUrbanResidentDoCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -924,7 +924,7 @@ func (c *MockUrbanResidentDriveCall) DoAndReturn(f func(cars.HyundaiSolaris)) *M } // Eat mocks base method. -func (m *MockUrbanResident) Eat(foods ...import_mode.Food) { +func (m *MockUrbanResident) Eat(foods ...package_mode.Food) { m.ctrl.T.Helper() varargs := []any{} for _, a := range foods { @@ -952,13 +952,13 @@ func (c *MockUrbanResidentEatCall) Return() *MockUrbanResidentEatCall { } // Do rewrite *gomock.Call.Do -func (c *MockUrbanResidentEatCall) Do(f func(...import_mode.Food)) *MockUrbanResidentEatCall { +func (c *MockUrbanResidentEatCall) Do(f func(...package_mode.Food)) *MockUrbanResidentEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockUrbanResidentEatCall) DoAndReturn(f func(...import_mode.Food)) *MockUrbanResidentEatCall { +func (c *MockUrbanResidentEatCall) DoAndReturn(f func(...package_mode.Food)) *MockUrbanResidentEatCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -1134,7 +1134,7 @@ func (c *MockFarmerBreatheCall) DoAndReturn(f func()) *MockFarmerBreatheCall { } // Do mocks base method. -func (m *MockFarmer) Do(work *import_mode.Work) error { +func (m *MockFarmer) Do(work *package_mode.Work) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Do", work) ret0, _ := ret[0].(error) @@ -1160,13 +1160,13 @@ func (c *MockFarmerDoCall) Return(arg0 error) *MockFarmerDoCall { } // Do rewrite *gomock.Call.Do -func (c *MockFarmerDoCall) Do(f func(*import_mode.Work) error) *MockFarmerDoCall { +func (c *MockFarmerDoCall) Do(f func(*package_mode.Work) error) *MockFarmerDoCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockFarmerDoCall) DoAndReturn(f func(*import_mode.Work) error) *MockFarmerDoCall { +func (c *MockFarmerDoCall) DoAndReturn(f func(*package_mode.Work) error) *MockFarmerDoCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -1208,7 +1208,7 @@ func (c *MockFarmerDriveCall) DoAndReturn(f func(cars.FordF150)) *MockFarmerDriv } // Eat mocks base method. -func (m *MockFarmer) Eat(foods ...import_mode.Food) { +func (m *MockFarmer) Eat(foods ...package_mode.Food) { m.ctrl.T.Helper() varargs := []any{} for _, a := range foods { @@ -1236,13 +1236,13 @@ func (c *MockFarmerEatCall) Return() *MockFarmerEatCall { } // Do rewrite *gomock.Call.Do -func (c *MockFarmerEatCall) Do(f func(...import_mode.Food)) *MockFarmerEatCall { +func (c *MockFarmerEatCall) Do(f func(...package_mode.Food)) *MockFarmerEatCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockFarmerEatCall) DoAndReturn(f func(...import_mode.Food)) *MockFarmerEatCall { +func (c *MockFarmerEatCall) DoAndReturn(f func(...package_mode.Food)) *MockFarmerEatCall { c.Call = c.Call.DoAndReturn(f) return c } @@ -1382,10 +1382,10 @@ func (m *MockEarth) EXPECT() *MockEarthMockRecorder { } // AddHumans mocks base method. -func (m *MockEarth) AddHumans(arg0 int) []import_mode.Primate { +func (m *MockEarth) AddHumans(arg0 int) []package_mode.Primate { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "AddHumans", arg0) - ret0, _ := ret[0].([]import_mode.Primate) + ret0, _ := ret[0].([]package_mode.Primate) return ret0 } @@ -1402,19 +1402,19 @@ type MockEarthAddHumansCall struct { } // Return rewrite *gomock.Call.Return -func (c *MockEarthAddHumansCall) Return(arg0 []import_mode.Primate) *MockEarthAddHumansCall { +func (c *MockEarthAddHumansCall) Return(arg0 []package_mode.Primate) *MockEarthAddHumansCall { c.Call = c.Call.Return(arg0) return c } // Do rewrite *gomock.Call.Do -func (c *MockEarthAddHumansCall) Do(f func(int) []import_mode.Primate) *MockEarthAddHumansCall { +func (c *MockEarthAddHumansCall) Do(f func(int) []package_mode.Primate) *MockEarthAddHumansCall { c.Call = c.Call.Do(f) return c } // DoAndReturn rewrite *gomock.Call.DoAndReturn -func (c *MockEarthAddHumansCall) DoAndReturn(f func(int) []import_mode.Primate) *MockEarthAddHumansCall { +func (c *MockEarthAddHumansCall) DoAndReturn(f func(int) []package_mode.Primate) *MockEarthAddHumansCall { c.Call = c.Call.DoAndReturn(f) return c } diff --git a/mockgen/internal/tests/package_mode/mock/interfaces_test.go b/mockgen/internal/tests/package_mode/mock/interfaces_test.go new file mode 100644 index 0000000..b47d605 --- /dev/null +++ b/mockgen/internal/tests/package_mode/mock/interfaces_test.go @@ -0,0 +1,41 @@ +package mock + +import ( + "testing" + + "go.uber.org/mock/gomock" + "go.uber.org/mock/mockgen/internal/tests/package_mode" + "go.uber.org/mock/mockgen/internal/tests/package_mode/cars" + "go.uber.org/mock/mockgen/internal/tests/package_mode/fuel" +) + +// checks, that mocks implement interfaces in compile-time. +// If something breaks, the tests will not be compiled. + +var food package_mode.Food = &MockFood{} + +var eater package_mode.Eater = &MockEater{} + +var animal package_mode.Animal = &MockAnimal{} + +var human package_mode.Human = &MockHuman{} + +var primate package_mode.Primate = &MockPrimate{} + +var car package_mode.Car[fuel.Gasoline] = &MockCar[fuel.Gasoline]{} + +var driver package_mode.Driver[fuel.Gasoline, cars.HyundaiSolaris] = &MockDriver[fuel.Gasoline, cars.HyundaiSolaris]{} + +var urbanResident package_mode.UrbanResident = &MockUrbanResident{} + +var farmer package_mode.Farmer = &MockFarmer{} + +func TestInterfaces(t *testing.T) { + ctrl := gomock.NewController(t) + + mock := NewMockFarmer(ctrl) + mock.EXPECT().Breathe() + + farmer := package_mode.Farmer(mock) + farmer.Breathe() +} diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index f23d1df..91203cc 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -61,13 +61,13 @@ var ( selfPackage = flag.String("self_package", "", "The full package import path for the generated code. The purpose of this flag is to prevent import cycles in the generated code by trying to include its own package. This can happen if the mock's package is set to one of its inputs (usually the main one) and the output is stdio so mockgen cannot detect the final output package. Setting this flag will then tell mockgen which import to exclude.") writeCmdComment = flag.Bool("write_command_comment", true, "Writes the command used as a comment if true.") writePkgComment = flag.Bool("write_package_comment", true, "Writes package documentation comment (godoc) if true.") - writeSourceComment = flag.Bool("write_source_comment", true, "Writes original file (source mode) or interface names (reflect mode) comment if true.") + writeSourceComment = flag.Bool("write_source_comment", true, "Writes original file (source mode) or interface names (package mode) comment if true.") writeGenerateDirective = flag.Bool("write_generate_directive", false, "Add //go:generate directive to regenerate the mock") copyrightFile = flag.String("copyright_file", "", "Copyright file used to add copyright header") typed = flag.Bool("typed", false, "Generate Type-safe 'Return', 'Do', 'DoAndReturn' function") imports = flag.String("imports", "", "(source mode) Comma-separated name=path pairs of explicit imports to use.") auxFiles = flag.String("aux_files", "", "(source mode) Comma-separated pkg=path pairs of auxiliary Go source files.") - excludeInterfaces = flag.String("exclude_interfaces", "", "Comma-separated names of interfaces to be excluded") + excludeInterfaces = flag.String("exclude_interfaces", "", "(source mode) Comma-separated names of interfaces to be excluded") debugParser = flag.Bool("debug_parser", false, "Print out parser results only.") showVersion = flag.Bool("version", false, "Print version.") @@ -104,7 +104,7 @@ func main() { log.Fatalf("Parse package name failed: %v", err) } } - parser := importModeParser{} + parser := packageModeParser{} pkg, err = parser.parsePackage(packageName, interfaces) } if err != nil { @@ -118,7 +118,7 @@ func main() { outputPackageName := *packageOut if outputPackageName == "" { - // pkg.Name in reflect mode is the base name of the import path, + // pkg.Name in package mode is the base name of the import path, // which might have characters that are illegal to have in package names. outputPackageName = "mock_" + sanitize(pkg.Name) } @@ -227,20 +227,21 @@ func usage() { flag.PrintDefaults() } -const usageText = `mockgen has two modes of operation: source and reflect. +const usageText = `mockgen has two modes of operation: source and package. Source mode generates mock interfaces from a source file. It is enabled by using the -source flag. Other flags that -may be useful in this mode are -imports and -aux_files. +may be useful in this mode are -imports, -aux_files and -exclude_interfaces. Example: mockgen -source=foo.go [other options] -Reflect mode generates mock interfaces by building a program -that uses reflection to understand interfaces. It is enabled -by passing two non-flag arguments: an import path, and a -comma-separated list of symbols. +Package mode works by specifying the package and interface names. +It is enabled by passing two non-flag arguments: an import path, and a +comma-separated list of symbols. +You can use "." to refer to the current path's package. Example: mockgen database/sql/driver Conn,Driver + mockgen . SomeInterface ` diff --git a/mockgen/import_mode.go b/mockgen/package_mode.go similarity index 91% rename from mockgen/import_mode.go rename to mockgen/package_mode.go index 77b11fa..540a83e 100644 --- a/mockgen/import_mode.go +++ b/mockgen/package_mode.go @@ -9,11 +9,11 @@ import ( "golang.org/x/tools/go/packages" ) -type importModeParser struct { +type packageModeParser struct { pkgName string } -func (p *importModeParser) parsePackage(packageName string, ifaces []string) (*model.Package, error) { +func (p *packageModeParser) parsePackage(packageName string, ifaces []string) (*model.Package, error) { p.pkgName = packageName pkg, err := p.loadPackage(packageName) @@ -33,7 +33,7 @@ func (p *importModeParser) parsePackage(packageName string, ifaces []string) (*m }, nil } -func (p *importModeParser) loadPackage(packageName string) (*packages.Package, error) { +func (p *packageModeParser) loadPackage(packageName string) (*packages.Package, error) { cfg := &packages.Config{ Mode: packages.NeedDeps | packages.NeedImports | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedEmbedFiles, } @@ -58,7 +58,7 @@ func (p *importModeParser) loadPackage(packageName string) (*packages.Package, e return pkgs[0], nil } -func (p *importModeParser) extractInterfacesFromPackage(pkg *packages.Package, ifaces []string) ([]*model.Interface, error) { +func (p *packageModeParser) extractInterfacesFromPackage(pkg *packages.Package, ifaces []string) ([]*model.Interface, error) { interfaces := make([]*model.Interface, len(ifaces)) for i, iface := range ifaces { obj := pkg.Types.Scope().Lookup(iface) @@ -77,7 +77,7 @@ func (p *importModeParser) extractInterfacesFromPackage(pkg *packages.Package, i return interfaces, nil } -func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, error) { +func (p *packageModeParser) parseInterface(obj types.Object) (*model.Interface, error) { named, ok := types.Unalias(obj.Type()).(*types.Named) if !ok { return nil, fmt.Errorf("%s is not an interface. it is a %T", obj.Name(), obj.Type().Underlying()) @@ -131,7 +131,7 @@ func (p *importModeParser) parseInterface(obj types.Object) (*model.Interface, e return &model.Interface{Name: obj.Name(), Methods: methods, TypeParams: typeParams}, nil } -func (o *importModeParser) isConstraint(t *types.Interface) bool { +func (o *packageModeParser) isConstraint(t *types.Interface) bool { for i := range t.NumEmbeddeds() { embed := t.EmbeddedType(i) if _, ok := embed.Underlying().(*types.Interface); !ok { @@ -142,7 +142,7 @@ func (o *importModeParser) isConstraint(t *types.Interface) bool { return false } -func (p *importModeParser) parseType(t types.Type) (model.Type, error) { +func (p *packageModeParser) parseType(t types.Type) (model.Type, error) { switch t := t.(type) { case *types.Array: elementType, err := p.parseType(t.Elem()) @@ -252,7 +252,7 @@ func (p *importModeParser) parseType(t types.Type) (model.Type, error) { } } -func (p *importModeParser) parseFunc(sig *types.Signature) (*model.FuncType, error) { +func (p *packageModeParser) parseFunc(sig *types.Signature) (*model.FuncType, error) { var variadic *model.Parameter params := make([]*model.Parameter, 0, sig.Params().Len()) for i := range sig.Params().Len() { @@ -310,7 +310,7 @@ func (p *importModeParser) parseFunc(sig *types.Signature) (*model.FuncType, err }, nil } -func (p *importModeParser) parseConstraint(t *types.TypeParam) (model.Type, error) { +func (p *packageModeParser) parseConstraint(t *types.TypeParam) (model.Type, error) { if t == nil { return nil, fmt.Errorf("nil type param") } diff --git a/mockgen/import_mode_test.go b/mockgen/package_mode_test.go similarity index 76% rename from mockgen/import_mode_test.go rename to mockgen/package_mode_test.go index c5df56a..5db836f 100644 --- a/mockgen/import_mode_test.go +++ b/mockgen/package_mode_test.go @@ -7,7 +7,7 @@ import ( "go.uber.org/mock/mockgen/model" ) -func Test_importModeParser_parsePackage(t *testing.T) { +func Test_packageModeParser_parsePackage(t *testing.T) { type args struct { packageName string ifaces []string @@ -29,7 +29,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { { name: "error: interface does not exist", args: args{ - packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + packageName: "go.uber.org/mock/mockgen/internal/tests/package_mode", ifaces: []string{"Alien"}, }, expectedErr: "extract interfaces from package: interface Alien does not exist", @@ -37,7 +37,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { { name: "error: search for struct instead of interface", args: args{ - packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + packageName: "go.uber.org/mock/mockgen/internal/tests/package_mode", ifaces: []string{"Work"}, }, expectedErr: "extract interfaces from package: parse interface: " + @@ -47,7 +47,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { { name: "error: search for constraint instead of interface", args: args{ - packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + packageName: "go.uber.org/mock/mockgen/internal/tests/package_mode", ifaces: []string{"Counter"}, }, expectedErr: "extract interfaces from package: parse interface: " + @@ -57,12 +57,12 @@ func Test_importModeParser_parsePackage(t *testing.T) { { name: "success: simple interface", args: args{ - packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + packageName: "go.uber.org/mock/mockgen/internal/tests/package_mode", ifaces: []string{"Food"}, }, expected: &model.Package{ - Name: "import_mode", - PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Name: "package_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/package_mode", Interfaces: []*model.Interface{ { Name: "Food", @@ -81,12 +81,12 @@ func Test_importModeParser_parsePackage(t *testing.T) { { name: "success: interface with variadic args", args: args{ - packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + packageName: "go.uber.org/mock/mockgen/internal/tests/package_mode", ifaces: []string{"Eater"}, }, expected: &model.Package{ - Name: "import_mode", - PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Name: "package_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/package_mode", Interfaces: []*model.Interface{ { Name: "Eater", @@ -96,7 +96,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { Variadic: &model.Parameter{ Name: "foods", Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Package: "go.uber.org/mock/mockgen/internal/tests/package_mode", Type: "Food", }, }, @@ -109,12 +109,12 @@ func Test_importModeParser_parsePackage(t *testing.T) { { name: "success: interface with generic", args: args{ - packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + packageName: "go.uber.org/mock/mockgen/internal/tests/package_mode", ifaces: []string{"Car"}, }, expected: &model.Package{ - Name: "import_mode", - PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Name: "package_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/package_mode", Interfaces: []*model.Interface{ { Name: "Car", @@ -130,7 +130,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { Out: []*model.Parameter{ { Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode/cars", + Package: "go.uber.org/mock/mockgen/internal/tests/package_mode/cars", Type: "FuelTank", TypeParams: &model.TypeParametersType{ TypeParameters: []model.Type{ @@ -164,7 +164,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { { Name: "FuelType", Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode/fuel", + Package: "go.uber.org/mock/mockgen/internal/tests/package_mode/fuel", Type: "Fuel", }, }, @@ -176,12 +176,12 @@ func Test_importModeParser_parsePackage(t *testing.T) { { name: "success: interface with embedded interfaces", args: args{ - packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + packageName: "go.uber.org/mock/mockgen/internal/tests/package_mode", ifaces: []string{"Animal"}, }, expected: &model.Package{ - Name: "import_mode", - PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Name: "package_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/package_mode", Interfaces: []*model.Interface{ { Name: "Animal", @@ -192,7 +192,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { Variadic: &model.Parameter{ Name: "foods", Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Package: "go.uber.org/mock/mockgen/internal/tests/package_mode", Type: "Food", }, }, @@ -217,12 +217,12 @@ func Test_importModeParser_parsePackage(t *testing.T) { { name: "success: subtype of interface", args: args{ - packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + packageName: "go.uber.org/mock/mockgen/internal/tests/package_mode", ifaces: []string{"Primate"}, }, expected: &model.Package{ - Name: "import_mode", - PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Name: "package_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/package_mode", Interfaces: []*model.Interface{ { Name: "Primate", @@ -233,7 +233,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { Variadic: &model.Parameter{ Name: "foods", Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Package: "go.uber.org/mock/mockgen/internal/tests/package_mode", Type: "Food", }, }, @@ -258,12 +258,12 @@ func Test_importModeParser_parsePackage(t *testing.T) { { name: "success: alias to interface", args: args{ - packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + packageName: "go.uber.org/mock/mockgen/internal/tests/package_mode", ifaces: []string{"Human"}, }, expected: &model.Package{ - Name: "import_mode", - PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Name: "package_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/package_mode", Interfaces: []*model.Interface{ { Name: "Human", @@ -274,7 +274,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { Variadic: &model.Parameter{ Name: "foods", Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Package: "go.uber.org/mock/mockgen/internal/tests/package_mode", Type: "Food", }, }, @@ -299,12 +299,12 @@ func Test_importModeParser_parsePackage(t *testing.T) { { name: "success: interfaces with aliases in params and returns", args: args{ - packageName: "go.uber.org/mock/mockgen/internal/tests/import_mode", + packageName: "go.uber.org/mock/mockgen/internal/tests/package_mode", ifaces: []string{"Earth"}, }, expected: &model.Package{ - Name: "import_mode", - PkgPath: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Name: "package_mode", + PkgPath: "go.uber.org/mock/mockgen/internal/tests/package_mode", Interfaces: []*model.Interface{ { Name: "Earth", @@ -321,7 +321,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { Type: &model.ArrayType{ Len: -1, // slice Type: &model.NamedType{ - Package: "go.uber.org/mock/mockgen/internal/tests/import_mode", + Package: "go.uber.org/mock/mockgen/internal/tests/package_mode", Type: "Primate", }, }, @@ -345,7 +345,7 @@ func Test_importModeParser_parsePackage(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - parser := importModeParser{} + parser := packageModeParser{} actual, err := parser.parsePackage(tt.args.packageName, tt.args.ifaces) if tt.expectedErr != "" { From cbd7843bca2924aaa98b6e0d548b560f4e7fdd9c Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Fri, 27 Sep 2024 23:01:46 +0300 Subject: [PATCH 13/16] added warning message if deprecated flags are set --- mockgen/deprecated.go | 45 +++++++++++++++++++++++++++++++++++++++++++ mockgen/mockgen.go | 2 ++ 2 files changed, 47 insertions(+) create mode 100644 mockgen/deprecated.go diff --git a/mockgen/deprecated.go b/mockgen/deprecated.go new file mode 100644 index 0000000..ee7fa21 --- /dev/null +++ b/mockgen/deprecated.go @@ -0,0 +1,45 @@ +package main + +import ( + "flag" + "log" + "os" +) + +const ( + deprecatedFlagProgOnly = "prog_only" + deprecatedFlagExecOnly = "exec_only" + deprecatedFlagBuildFlags = "build_flags" +) + +var ( + _ = flag.Bool("prog_only", false, "DEPRECATED (reflect mode) Only generate the reflection program; write it to stdout and exit.") + _ = flag.String("exec_only", "", "DEPRECATED (reflect mode) If set, execute this reflection program.") + _ = flag.String("build_flags", "", "DEPRECATED (reflect mode) Additional flags for go build.") +) + +// notifyAboutDeprecatedFlags prints a warning message for a deprecated flags if they are set. +func notifyAboutDeprecatedFlags() { + const resetColorPostfix = "\033[0m" + logger := initWarningLogger() + + flag.Visit(func(f *flag.Flag) { + switch f.Name { + case deprecatedFlagProgOnly: + logger.Println("The -prog_only flag is deprecated and has no effect.", resetColorPostfix) + case deprecatedFlagExecOnly: + logger.Println("The -exec_only flag is deprecated and has no effect.", resetColorPostfix) + case deprecatedFlagBuildFlags: + logger.Println("The -build_flags flag is deprecated and has no effect.", resetColorPostfix) + } + }) +} + +func initWarningLogger() *log.Logger { + const ( + yellowColor = "\033[33m" + warningPrefix = yellowColor + "WARNING: " + ) + + return log.New(os.Stdout, warningPrefix, log.Ldate|log.Ltime) +} diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index 91203cc..eb5c0ce 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -77,6 +77,8 @@ func main() { flag.Usage = usage flag.Parse() + notifyAboutDeprecatedFlags() + if *showVersion { printVersion() return From b14e7ad36f2ed7514051cf74a6029a776fe05482 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Fri, 27 Sep 2024 23:03:02 +0300 Subject: [PATCH 14/16] regenerated forgotten mock --- mockgen/internal/tests/generics/external.go | 2 +- .../package_mode/mock_external_mock.go | 607 ++++++++++++++++++ 2 files changed, 608 insertions(+), 1 deletion(-) create mode 100644 mockgen/internal/tests/generics/package_mode/mock_external_mock.go diff --git a/mockgen/internal/tests/generics/external.go b/mockgen/internal/tests/generics/external.go index 6756361..443d565 100644 --- a/mockgen/internal/tests/generics/external.go +++ b/mockgen/internal/tests/generics/external.go @@ -9,7 +9,7 @@ import ( ) //go:generate mockgen --source=external.go --destination=source/mock_external_mock.go --package source -//go:generate mockgen --destination=import_mode/mock_external_mock.go -package=import_mode . ExternalConstraint,EmbeddingIface,Generator,Group +//go:generate mockgen --destination=package_mode/mock_external_mock.go -package=package_mode . ExternalConstraint,EmbeddingIface,Generator,Group type ExternalConstraint[I constraints.Integer, F any] interface { One(string) string diff --git a/mockgen/internal/tests/generics/package_mode/mock_external_mock.go b/mockgen/internal/tests/generics/package_mode/mock_external_mock.go new file mode 100644 index 0000000..61fda78 --- /dev/null +++ b/mockgen/internal/tests/generics/package_mode/mock_external_mock.go @@ -0,0 +1,607 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: go.uber.org/mock/mockgen/internal/tests/generics (interfaces: ExternalConstraint,EmbeddingIface,Generator,Group) +// +// Generated by this command: +// +// mockgen --destination=package_mode/mock_external_mock.go -package=package_mode . ExternalConstraint,EmbeddingIface,Generator,Group +// + +// Package package_mode is a generated GoMock package. +package package_mode + +import ( + context "context" + reflect "reflect" + + gomock "go.uber.org/mock/gomock" + generics "go.uber.org/mock/mockgen/internal/tests/generics" + other "go.uber.org/mock/mockgen/internal/tests/generics/other" + constraints "golang.org/x/exp/constraints" +) + +// MockExternalConstraint is a mock of ExternalConstraint interface. +type MockExternalConstraint[I constraints.Integer, F any] struct { + ctrl *gomock.Controller + recorder *MockExternalConstraintMockRecorder[I, F] + isgomock struct{} +} + +// MockExternalConstraintMockRecorder is the mock recorder for MockExternalConstraint. +type MockExternalConstraintMockRecorder[I constraints.Integer, F any] struct { + mock *MockExternalConstraint[I, F] +} + +// NewMockExternalConstraint creates a new mock instance. +func NewMockExternalConstraint[I constraints.Integer, F any](ctrl *gomock.Controller) *MockExternalConstraint[I, F] { + mock := &MockExternalConstraint[I, F]{ctrl: ctrl} + mock.recorder = &MockExternalConstraintMockRecorder[I, F]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockExternalConstraint[I, F]) EXPECT() *MockExternalConstraintMockRecorder[I, F] { + return m.recorder +} + +// Eight mocks base method. +func (m *MockExternalConstraint[I, F]) Eight(arg0 F) other.Two[I, F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[I, F]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockExternalConstraintMockRecorder[I, F]) Eight(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eight), arg0) +} + +// Eleven mocks base method. +func (m *MockExternalConstraint[I, F]) Eleven() map[string]I { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(map[string]I) + return ret0 +} + +// Eleven indicates an expected call of Eleven. +func (mr *MockExternalConstraintMockRecorder[I, F]) Eleven() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Eleven)) +} + +// Five mocks base method. +func (m *MockExternalConstraint[I, F]) Five(arg0 I) generics.Baz[F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(generics.Baz[F]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockExternalConstraintMockRecorder[I, F]) Five(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Five), arg0) +} + +// Four mocks base method. +func (m *MockExternalConstraint[I, F]) Four(arg0 I) generics.Foo[I, F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(generics.Foo[I, F]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockExternalConstraintMockRecorder[I, F]) Four(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Four), arg0) +} + +// Nine mocks base method. +func (m *MockExternalConstraint[I, F]) Nine(arg0 generics.Iface[I]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockExternalConstraintMockRecorder[I, F]) Nine(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Nine), arg0) +} + +// One mocks base method. +func (m *MockExternalConstraint[I, F]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockExternalConstraintMockRecorder[I, F]) One(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).One), arg0) +} + +// Seven mocks base method. +func (m *MockExternalConstraint[I, F]) Seven(arg0 I) other.One[I] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[I]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockExternalConstraintMockRecorder[I, F]) Seven(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Seven), arg0) +} + +// Six mocks base method. +func (m *MockExternalConstraint[I, F]) Six(arg0 I) *generics.Baz[F] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*generics.Baz[F]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockExternalConstraintMockRecorder[I, F]) Six(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Six), arg0) +} + +// Ten mocks base method. +func (m *MockExternalConstraint[I, F]) Ten(arg0 *I) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockExternalConstraintMockRecorder[I, F]) Ten(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Ten), arg0) +} + +// Thirteen mocks base method. +func (m *MockExternalConstraint[I, F]) Thirteen(arg0 ...I) *F { + m.ctrl.T.Helper() + varargs := []any{} + for _, a := range arg0 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Thirteen", varargs...) + ret0, _ := ret[0].(*F) + return ret0 +} + +// Thirteen indicates an expected call of Thirteen. +func (mr *MockExternalConstraintMockRecorder[I, F]) Thirteen(arg0 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Thirteen), arg0...) +} + +// Three mocks base method. +func (m *MockExternalConstraint[I, F]) Three(arg0 I) F { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(F) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockExternalConstraintMockRecorder[I, F]) Three(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Three), arg0) +} + +// Twelve mocks base method. +func (m *MockExternalConstraint[I, F]) Twelve(ctx context.Context) <-chan []I { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twelve", ctx) + ret0, _ := ret[0].(<-chan []I) + return ret0 +} + +// Twelve indicates an expected call of Twelve. +func (mr *MockExternalConstraintMockRecorder[I, F]) Twelve(ctx any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Twelve), ctx) +} + +// Two mocks base method. +func (m *MockExternalConstraint[I, F]) Two(arg0 I) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockExternalConstraintMockRecorder[I, F]) Two(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockExternalConstraint[I, F])(nil).Two), arg0) +} + +// MockEmbeddingIface is a mock of EmbeddingIface interface. +type MockEmbeddingIface[T constraints.Integer, R constraints.Float] struct { + ctrl *gomock.Controller + recorder *MockEmbeddingIfaceMockRecorder[T, R] + isgomock struct{} +} + +// MockEmbeddingIfaceMockRecorder is the mock recorder for MockEmbeddingIface. +type MockEmbeddingIfaceMockRecorder[T constraints.Integer, R constraints.Float] struct { + mock *MockEmbeddingIface[T, R] +} + +// NewMockEmbeddingIface creates a new mock instance. +func NewMockEmbeddingIface[T constraints.Integer, R constraints.Float](ctrl *gomock.Controller) *MockEmbeddingIface[T, R] { + mock := &MockEmbeddingIface[T, R]{ctrl: ctrl} + mock.recorder = &MockEmbeddingIfaceMockRecorder[T, R]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockEmbeddingIface[T, R]) EXPECT() *MockEmbeddingIfaceMockRecorder[T, R] { + return m.recorder +} + +// Eight mocks base method. +func (m *MockEmbeddingIface[T, R]) Eight(arg0 R) other.Two[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eight", arg0) + ret0, _ := ret[0].(other.Two[T, R]) + return ret0 +} + +// Eight indicates an expected call of Eight. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eight(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eight", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eight), arg0) +} + +// Eleven mocks base method. +func (m *MockEmbeddingIface[T, R]) Eleven() map[string]T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Eleven") + ret0, _ := ret[0].(map[string]T) + return ret0 +} + +// Eleven indicates an expected call of Eleven. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Eleven() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eleven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Eleven)) +} + +// First mocks base method. +func (m *MockEmbeddingIface[T, R]) First() R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "First") + ret0, _ := ret[0].(R) + return ret0 +} + +// First indicates an expected call of First. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) First() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "First", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).First)) +} + +// Five mocks base method. +func (m *MockEmbeddingIface[T, R]) Five(arg0 T) generics.Baz[R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Five", arg0) + ret0, _ := ret[0].(generics.Baz[R]) + return ret0 +} + +// Five indicates an expected call of Five. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Five(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Five", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Five), arg0) +} + +// Four mocks base method. +func (m *MockEmbeddingIface[T, R]) Four(arg0 T) generics.Foo[T, R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Four", arg0) + ret0, _ := ret[0].(generics.Foo[T, R]) + return ret0 +} + +// Four indicates an expected call of Four. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Four(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Four", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Four), arg0) +} + +// Fourth mocks base method. +func (m *MockEmbeddingIface[T, R]) Fourth() generics.Generator[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Fourth") + ret0, _ := ret[0].(generics.Generator[T]) + return ret0 +} + +// Fourth indicates an expected call of Fourth. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Fourth() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Fourth", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Fourth)) +} + +// Generate mocks base method. +func (m *MockEmbeddingIface[T, R]) Generate() R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Generate") + ret0, _ := ret[0].(R) + return ret0 +} + +// Generate indicates an expected call of Generate. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Generate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Generate)) +} + +// Nine mocks base method. +func (m *MockEmbeddingIface[T, R]) Nine(arg0 generics.Iface[T]) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Nine", arg0) +} + +// Nine indicates an expected call of Nine. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Nine(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Nine", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Nine), arg0) +} + +// One mocks base method. +func (m *MockEmbeddingIface[T, R]) One(arg0 string) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "One", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// One indicates an expected call of One. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) One(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "One", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).One), arg0) +} + +// Read mocks base method. +func (m *MockEmbeddingIface[T, R]) Read(p []byte) (int, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Read", p) + ret0, _ := ret[0].(int) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// Read indicates an expected call of Read. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Read(p any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Read), p) +} + +// Second mocks base method. +func (m *MockEmbeddingIface[T, R]) Second() generics.StructType { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Second") + ret0, _ := ret[0].(generics.StructType) + return ret0 +} + +// Second indicates an expected call of Second. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Second() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Second", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Second)) +} + +// Seven mocks base method. +func (m *MockEmbeddingIface[T, R]) Seven(arg0 T) other.One[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Seven", arg0) + ret0, _ := ret[0].(other.One[T]) + return ret0 +} + +// Seven indicates an expected call of Seven. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Seven(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Seven", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Seven), arg0) +} + +// Six mocks base method. +func (m *MockEmbeddingIface[T, R]) Six(arg0 T) *generics.Baz[R] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Six", arg0) + ret0, _ := ret[0].(*generics.Baz[R]) + return ret0 +} + +// Six indicates an expected call of Six. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Six(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Six", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Six), arg0) +} + +// Ten mocks base method. +func (m *MockEmbeddingIface[T, R]) Ten(arg0 *T) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Ten", arg0) +} + +// Ten indicates an expected call of Ten. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Ten(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Ten", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Ten), arg0) +} + +// Third mocks base method. +func (m *MockEmbeddingIface[T, R]) Third() other.Five { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Third") + ret0, _ := ret[0].(other.Five) + return ret0 +} + +// Third indicates an expected call of Third. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Third() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Third", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Third)) +} + +// Thirteen mocks base method. +func (m *MockEmbeddingIface[T, R]) Thirteen(arg0 ...T) *R { + m.ctrl.T.Helper() + varargs := []any{} + for _, a := range arg0 { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Thirteen", varargs...) + ret0, _ := ret[0].(*R) + return ret0 +} + +// Thirteen indicates an expected call of Thirteen. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Thirteen(arg0 ...any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Thirteen", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Thirteen), arg0...) +} + +// Three mocks base method. +func (m *MockEmbeddingIface[T, R]) Three(arg0 T) R { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Three", arg0) + ret0, _ := ret[0].(R) + return ret0 +} + +// Three indicates an expected call of Three. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Three(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Three", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Three), arg0) +} + +// Twelve mocks base method. +func (m *MockEmbeddingIface[T, R]) Twelve(ctx context.Context) <-chan []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Twelve", ctx) + ret0, _ := ret[0].(<-chan []T) + return ret0 +} + +// Twelve indicates an expected call of Twelve. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Twelve(ctx any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Twelve", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Twelve), ctx) +} + +// Two mocks base method. +func (m *MockEmbeddingIface[T, R]) Two(arg0 T) string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Two", arg0) + ret0, _ := ret[0].(string) + return ret0 +} + +// Two indicates an expected call of Two. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Two(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Two", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Two), arg0) +} + +// Water mocks base method. +func (m *MockEmbeddingIface[T, R]) Water(arg0 generics.Generator[T]) []generics.Generator[T] { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Water", arg0) + ret0, _ := ret[0].([]generics.Generator[T]) + return ret0 +} + +// Water indicates an expected call of Water. +func (mr *MockEmbeddingIfaceMockRecorder[T, R]) Water(arg0 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Water", reflect.TypeOf((*MockEmbeddingIface[T, R])(nil).Water), arg0) +} + +// MockGenerator is a mock of Generator interface. +type MockGenerator[T any] struct { + ctrl *gomock.Controller + recorder *MockGeneratorMockRecorder[T] + isgomock struct{} +} + +// MockGeneratorMockRecorder is the mock recorder for MockGenerator. +type MockGeneratorMockRecorder[T any] struct { + mock *MockGenerator[T] +} + +// NewMockGenerator creates a new mock instance. +func NewMockGenerator[T any](ctrl *gomock.Controller) *MockGenerator[T] { + mock := &MockGenerator[T]{ctrl: ctrl} + mock.recorder = &MockGeneratorMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGenerator[T]) EXPECT() *MockGeneratorMockRecorder[T] { + return m.recorder +} + +// Generate mocks base method. +func (m *MockGenerator[T]) Generate() T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Generate") + ret0, _ := ret[0].(T) + return ret0 +} + +// Generate indicates an expected call of Generate. +func (mr *MockGeneratorMockRecorder[T]) Generate() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Generate", reflect.TypeOf((*MockGenerator[T])(nil).Generate)) +} + +// MockGroup is a mock of Group interface. +type MockGroup[T generics.Generator[any]] struct { + ctrl *gomock.Controller + recorder *MockGroupMockRecorder[T] + isgomock struct{} +} + +// MockGroupMockRecorder is the mock recorder for MockGroup. +type MockGroupMockRecorder[T generics.Generator[any]] struct { + mock *MockGroup[T] +} + +// NewMockGroup creates a new mock instance. +func NewMockGroup[T generics.Generator[any]](ctrl *gomock.Controller) *MockGroup[T] { + mock := &MockGroup[T]{ctrl: ctrl} + mock.recorder = &MockGroupMockRecorder[T]{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockGroup[T]) EXPECT() *MockGroupMockRecorder[T] { + return m.recorder +} + +// Join mocks base method. +func (m *MockGroup[T]) Join(ctx context.Context) []T { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Join", ctx) + ret0, _ := ret[0].([]T) + return ret0 +} + +// Join indicates an expected call of Join. +func (mr *MockGroupMockRecorder[T]) Join(ctx any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Join", reflect.TypeOf((*MockGroup[T])(nil).Join), ctx) +} From dcf893da4c12004b207965863a1cdd02f9e6cd70 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Wed, 2 Oct 2024 09:24:36 +0300 Subject: [PATCH 15/16] returned support for build_flags flag --- mockgen/deprecated.go | 8 +-- .../internal/tests/build_flags/directive.go | 6 +++ .../tests/build_flags/interfaces_1.go | 7 +++ .../tests/build_flags/interfaces_2.go | 7 +++ .../build_flags/mock1/interfaces_mock.go | 54 +++++++++++++++++++ .../build_flags/mock2/interfaces_mock.go | 52 ++++++++++++++++++ mockgen/package_mode.go | 14 ++++- 7 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 mockgen/internal/tests/build_flags/directive.go create mode 100644 mockgen/internal/tests/build_flags/interfaces_1.go create mode 100644 mockgen/internal/tests/build_flags/interfaces_2.go create mode 100644 mockgen/internal/tests/build_flags/mock1/interfaces_mock.go create mode 100644 mockgen/internal/tests/build_flags/mock2/interfaces_mock.go diff --git a/mockgen/deprecated.go b/mockgen/deprecated.go index ee7fa21..0b45a2e 100644 --- a/mockgen/deprecated.go +++ b/mockgen/deprecated.go @@ -7,15 +7,13 @@ import ( ) const ( - deprecatedFlagProgOnly = "prog_only" - deprecatedFlagExecOnly = "exec_only" - deprecatedFlagBuildFlags = "build_flags" + deprecatedFlagProgOnly = "prog_only" + deprecatedFlagExecOnly = "exec_only" ) var ( _ = flag.Bool("prog_only", false, "DEPRECATED (reflect mode) Only generate the reflection program; write it to stdout and exit.") _ = flag.String("exec_only", "", "DEPRECATED (reflect mode) If set, execute this reflection program.") - _ = flag.String("build_flags", "", "DEPRECATED (reflect mode) Additional flags for go build.") ) // notifyAboutDeprecatedFlags prints a warning message for a deprecated flags if they are set. @@ -29,8 +27,6 @@ func notifyAboutDeprecatedFlags() { logger.Println("The -prog_only flag is deprecated and has no effect.", resetColorPostfix) case deprecatedFlagExecOnly: logger.Println("The -exec_only flag is deprecated and has no effect.", resetColorPostfix) - case deprecatedFlagBuildFlags: - logger.Println("The -build_flags flag is deprecated and has no effect.", resetColorPostfix) } }) } diff --git a/mockgen/internal/tests/build_flags/directive.go b/mockgen/internal/tests/build_flags/directive.go new file mode 100644 index 0000000..4bfc9e9 --- /dev/null +++ b/mockgen/internal/tests/build_flags/directive.go @@ -0,0 +1,6 @@ +package build_flags + +// one build flag +//go:generate mockgen -destination=mock1/interfaces_mock.go -build_flags=-tags=tag1 . Interface +// multiple build flags +//go:generate mockgen -destination=mock2/interfaces_mock.go "-build_flags=-race -tags=tag2" . Interface diff --git a/mockgen/internal/tests/build_flags/interfaces_1.go b/mockgen/internal/tests/build_flags/interfaces_1.go new file mode 100644 index 0000000..e159cd6 --- /dev/null +++ b/mockgen/internal/tests/build_flags/interfaces_1.go @@ -0,0 +1,7 @@ +//go:build tag1 + +package build_flags + +type Interface interface { + HelloWorld() string +} diff --git a/mockgen/internal/tests/build_flags/interfaces_2.go b/mockgen/internal/tests/build_flags/interfaces_2.go new file mode 100644 index 0000000..5404cf7 --- /dev/null +++ b/mockgen/internal/tests/build_flags/interfaces_2.go @@ -0,0 +1,7 @@ +//go:build tag2 + +package build_flags + +type Interface interface { + Foo() +} diff --git a/mockgen/internal/tests/build_flags/mock1/interfaces_mock.go b/mockgen/internal/tests/build_flags/mock1/interfaces_mock.go new file mode 100644 index 0000000..7ca80bd --- /dev/null +++ b/mockgen/internal/tests/build_flags/mock1/interfaces_mock.go @@ -0,0 +1,54 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: go.uber.org/mock/mockgen/internal/tests/build_flags (interfaces: Interface) +// +// Generated by this command: +// +// mockgen -destination=mock1/interfaces_mock.go -build_flags=-tags=tag1 . Interface +// + +// Package mock_build_flags is a generated GoMock package. +package mock_build_flags + +import ( + reflect "reflect" + + gomock "go.uber.org/mock/gomock" +) + +// MockInterface is a mock of Interface interface. +type MockInterface struct { + ctrl *gomock.Controller + recorder *MockInterfaceMockRecorder + isgomock struct{} +} + +// MockInterfaceMockRecorder is the mock recorder for MockInterface. +type MockInterfaceMockRecorder struct { + mock *MockInterface +} + +// NewMockInterface creates a new mock instance. +func NewMockInterface(ctrl *gomock.Controller) *MockInterface { + mock := &MockInterface{ctrl: ctrl} + mock.recorder = &MockInterfaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder { + return m.recorder +} + +// HelloWorld mocks base method. +func (m *MockInterface) HelloWorld() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "HelloWorld") + ret0, _ := ret[0].(string) + return ret0 +} + +// HelloWorld indicates an expected call of HelloWorld. +func (mr *MockInterfaceMockRecorder) HelloWorld() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "HelloWorld", reflect.TypeOf((*MockInterface)(nil).HelloWorld)) +} diff --git a/mockgen/internal/tests/build_flags/mock2/interfaces_mock.go b/mockgen/internal/tests/build_flags/mock2/interfaces_mock.go new file mode 100644 index 0000000..4f21187 --- /dev/null +++ b/mockgen/internal/tests/build_flags/mock2/interfaces_mock.go @@ -0,0 +1,52 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: go.uber.org/mock/mockgen/internal/tests/build_flags (interfaces: Interface) +// +// Generated by this command: +// +// mockgen -destination=mock2/interfaces_mock.go -build_flags=-race -tags=tag2 . Interface +// + +// Package mock_build_flags is a generated GoMock package. +package mock_build_flags + +import ( + reflect "reflect" + + gomock "go.uber.org/mock/gomock" +) + +// MockInterface is a mock of Interface interface. +type MockInterface struct { + ctrl *gomock.Controller + recorder *MockInterfaceMockRecorder + isgomock struct{} +} + +// MockInterfaceMockRecorder is the mock recorder for MockInterface. +type MockInterfaceMockRecorder struct { + mock *MockInterface +} + +// NewMockInterface creates a new mock instance. +func NewMockInterface(ctrl *gomock.Controller) *MockInterface { + mock := &MockInterface{ctrl: ctrl} + mock.recorder = &MockInterfaceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder { + return m.recorder +} + +// Foo mocks base method. +func (m *MockInterface) Foo() { + m.ctrl.T.Helper() + m.ctrl.Call(m, "Foo") +} + +// Foo indicates an expected call of Foo. +func (mr *MockInterfaceMockRecorder) Foo() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Foo", reflect.TypeOf((*MockInterface)(nil).Foo)) +} diff --git a/mockgen/package_mode.go b/mockgen/package_mode.go index 540a83e..abc9c7a 100644 --- a/mockgen/package_mode.go +++ b/mockgen/package_mode.go @@ -2,13 +2,19 @@ package main import ( "errors" + "flag" "fmt" "go/types" + "strings" "go.uber.org/mock/mockgen/model" "golang.org/x/tools/go/packages" ) +var ( + buildFlags = flag.String("build_flags", "", "(package mode) Additional flags for go build.") +) + type packageModeParser struct { pkgName string } @@ -34,8 +40,14 @@ func (p *packageModeParser) parsePackage(packageName string, ifaces []string) (* } func (p *packageModeParser) loadPackage(packageName string) (*packages.Package, error) { + var buildFlagsSet []string + if *buildFlags != "" { + buildFlagsSet = strings.Split(*buildFlags, " ") + } + cfg := &packages.Config{ - Mode: packages.NeedDeps | packages.NeedImports | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedEmbedFiles, + Mode: packages.NeedDeps | packages.NeedImports | packages.NeedTypes | packages.NeedTypesInfo | packages.NeedEmbedFiles, + BuildFlags: buildFlagsSet, } pkgs, err := packages.Load(cfg, packageName) if err != nil { From 3d7cfd32f6d5e5a1f1cfd13ea88f178f62591005 Mon Sep 17 00:00:00 2001 From: Tulskiy Aleksandr Date: Thu, 3 Oct 2024 20:58:51 +0300 Subject: [PATCH 16/16] returned build_flags description to README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2a5f4fb..b449eb2 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,8 @@ It supports the following flags: `foo=bar/baz.go`, where `bar/baz.go` is the source file and `foo` is the package name of that file used by the -source file. +- `-build_flags`: (package mode only) Flags passed verbatim to `go list`. + - `-mock_names`: A list of custom names for generated mocks. This is specified as a comma-separated list of elements of the form `Repository=MockSensorRepository,Endpoint=MockSensorEndpoint`, where