From ad7b506c8b0f29db6b49f8a78cb7864147a6f438 Mon Sep 17 00:00:00 2001 From: defaulterrr Date: Sat, 18 Mar 2023 01:53:41 +0300 Subject: [PATCH] feat: added automatic snapshot testing --- go.mod | 1 + go.sum | 2 + snapshot_test.go | 133 +++ ..._with_any_used_as_param_and_return_type.go | 283 +++++ ...ot-generics_with_any_used_as_param_type.go | 255 +++++ ...t-generics_with_any_used_as_return_type.go | 209 ++++ ...line_union_used_as_a_generic_constraint.go | 255 +++++ ...plex_union_used_as_a_generic_constraint.go | 255 +++++ ...mple_union_used_as_a_generic_constraint.go | 255 +++++ ...cific_type_used_as_a_generic_constraint.go | 256 +++++ snapshots/TestSnapshot-package_reference.go | 1000 +++++++++++++++++ snapshots/TestSnapshot-relative_reference.go | 284 +++++ tests/{generic => }/generic_complex_union.go | 10 +- tests/{generic => }/generic_in.go | 10 +- tests/{generic => }/generic_inline_union.go | 10 +- tests/{generic => }/generic_inout.go | 10 +- tests/{generic => }/generic_out.go | 10 +- tests/{generic => }/generic_simple_union.go | 10 +- tests/{generic => }/generic_specific.go | 10 +- 19 files changed, 3223 insertions(+), 35 deletions(-) create mode 100644 snapshot_test.go create mode 100644 snapshots/TestSnapshot-generics_with_any_used_as_param_and_return_type.go create mode 100644 snapshots/TestSnapshot-generics_with_any_used_as_param_type.go create mode 100644 snapshots/TestSnapshot-generics_with_any_used_as_return_type.go create mode 100644 snapshots/TestSnapshot-generics_with_complex_inline_union_used_as_a_generic_constraint.go create mode 100644 snapshots/TestSnapshot-generics_with_complex_union_used_as_a_generic_constraint.go create mode 100644 snapshots/TestSnapshot-generics_with_simple_union_used_as_a_generic_constraint.go create mode 100644 snapshots/TestSnapshot-generics_with_specific_type_used_as_a_generic_constraint.go create mode 100644 snapshots/TestSnapshot-package_reference.go create mode 100644 snapshots/TestSnapshot-relative_reference.go rename tests/{generic => }/generic_complex_union.go (96%) rename tests/{generic => }/generic_in.go (97%) rename tests/{generic => }/generic_inline_union.go (96%) rename tests/{generic => }/generic_inout.go (97%) rename tests/{generic => }/generic_out.go (96%) rename tests/{generic => }/generic_simple_union.go (96%) rename tests/{generic => }/generic_specific.go (96%) diff --git a/go.mod b/go.mod index f85e86f..6c4ffdd 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( ) require ( + github.com/bradleyjkemp/cupaloy v2.3.0+incompatible // indirect github.com/kr/text v0.2.0 // indirect golang.org/x/mod v0.4.2 // indirect golang.org/x/sys v0.1.0 // indirect diff --git a/go.sum b/go.sum index 72f6e7a..13f311a 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/bradleyjkemp/cupaloy v2.3.0+incompatible h1:UafIjBvWQmS9i/xRg+CamMrnLTKNzo+bdmT/oH34c2Y= +github.com/bradleyjkemp/cupaloy v2.3.0+incompatible/go.mod h1:Au1Xw1sgaJ5iSFktEhYsS0dbQiS1B0/XMXl+42y9Ilk= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= diff --git a/snapshot_test.go b/snapshot_test.go new file mode 100644 index 0000000..d997e25 --- /dev/null +++ b/snapshot_test.go @@ -0,0 +1,133 @@ +package minimock_test + +import ( + "bytes" + "context" + "os" + "os/exec" + "testing" + "time" + + "github.com/bradleyjkemp/cupaloy" +) + +func mustRunMinimockWithParams( + t *testing.T, + interfacePattern string, + outputFile string, +) { + t.Helper() + + var outBuffer bytes.Buffer + + timeoutContext, cancel := context.WithTimeout(context.Background(), time.Second*10) + defer cancel() + + cmd := exec.CommandContext(timeoutContext, "go", "run", "cmd/minimock/minimock.go", "-o", outputFile, "-i", interfacePattern) + cmd.Stdout = &outBuffer + cmd.Stderr = &outBuffer + + t.Log(cmd.String()) + + if err := cmd.Run(); err != nil { + t.Log(outBuffer.String()) + t.Fail() + } +} + +func mustReadFile( + t *testing.T, + filename string, +) []byte { + t.Helper() + + contents, err := os.ReadFile(filename) + if err != nil { + t.Errorf("failed to read the file: %v", err) + t.Fail() + } + + return contents +} + +func TestSnapshot(t *testing.T) { + snapshotter := cupaloy.New( + cupaloy.SnapshotSubdirectory("snapshots"), + cupaloy.SnapshotFileExtension(".go"), + ) + + type testCase struct { + name string + outputFile string + inputInterface string + expectedOutputFile string + } + + testCases := []testCase{ + { + name: "package reference", + outputFile: "./tests", + inputInterface: "github.com/gojuno/minimock/v3.Tester", + expectedOutputFile: "tests/tester_mock_test.go", + }, + { + name: "relative reference", + inputInterface: "./tests.Formatter", + outputFile: "./tests/formatter_mock.go", + expectedOutputFile: "./tests/formatter_mock.go", + }, + { + name: "generics with any used as param and return type", + inputInterface: "./tests.genericInout", + outputFile: "./tests/generic_inout.go", + expectedOutputFile: "./tests/generic_inout.go", + }, + { + name: "generics with any used as return type", + inputInterface: "./tests.genericOut", + outputFile: "./tests/generic_out.go", + expectedOutputFile: "./tests/generic_out.go", + }, + { + name: "generics with any used as param type", + inputInterface: "./tests.genericIn", + outputFile: "./tests/generic_in.go", + expectedOutputFile: "./tests/generic_in.go", + }, + { + name: "generics with specific type used as a generic constraint", + inputInterface: "./tests.genericSpecific", + outputFile: "./tests/generic_specific.go", + expectedOutputFile: "./tests/generic_specific.go", + }, + { + name: "generics with simple union used as a generic constraint", + inputInterface: "./tests.genericSimpleUnion", + outputFile: "./tests/generic_simple_union.go", + expectedOutputFile: "./tests/generic_simple_union.go", + }, + { + name: "generics with complex union used as a generic constraint", + inputInterface: "./tests.genericComplexUnion", + outputFile: "./tests/generic_complex_union.go", + expectedOutputFile: "./tests/generic_complex_union.go", + }, + { + name: "generics with complex inline union used as a generic constraint", + inputInterface: "./tests.genericInlineUnion", + outputFile: "./tests/generic_inline_union.go", + expectedOutputFile: "./tests/generic_inline_union.go", + }, + } + + for _, testCase := range testCases { + testCase := testCase + + t.Run(testCase.name, func(t *testing.T) { + t.Parallel() + + mustRunMinimockWithParams(t, testCase.inputInterface, testCase.outputFile) + snapshotter.SnapshotT(t, mustReadFile(t, testCase.expectedOutputFile)) + }) + } +} diff --git a/snapshots/TestSnapshot-generics_with_any_used_as_param_and_return_type.go b/snapshots/TestSnapshot-generics_with_any_used_as_param_and_return_type.go new file mode 100644 index 0000000..185c923 --- /dev/null +++ b/snapshots/TestSnapshot-generics_with_any_used_as_param_and_return_type.go @@ -0,0 +1,283 @@ +package tests + +// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. + +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericInout -o ./tests/generic_inout.go -n GenericInoutMock + +import ( + "sync" + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" +) + +// GenericInoutMock implements genericInout +type GenericInoutMock[T any] struct { + t minimock.Tester + + funcName func(t1 T) (t2 T) + inspectFuncName func(t1 T) + afterNameCounter uint64 + beforeNameCounter uint64 + NameMock mGenericInoutMockName[T] +} + +// NewGenericInoutMock returns a mock for genericInout +func NewGenericInoutMock[T any](t minimock.Tester) *GenericInoutMock[T] { + m := &GenericInoutMock[T]{t: t} + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.NameMock = mGenericInoutMockName[T]{mock: m} + m.NameMock.callArgs = []*GenericInoutMockNameParams[T]{} + + return m +} + +type mGenericInoutMockName[T any] struct { + mock *GenericInoutMock[T] + defaultExpectation *GenericInoutMockNameExpectation[T] + expectations []*GenericInoutMockNameExpectation[T] + + callArgs []*GenericInoutMockNameParams[T] + mutex sync.RWMutex +} + +// GenericInoutMockNameExpectation specifies expectation struct of the genericInout.Name +type GenericInoutMockNameExpectation[T any] struct { + mock *GenericInoutMock[T] + params *GenericInoutMockNameParams[T] + results *GenericInoutMockNameResults[T] + Counter uint64 +} + +// GenericInoutMockNameParams contains parameters of the genericInout.Name +type GenericInoutMockNameParams[T any] struct { + t1 T +} + +// GenericInoutMockNameResults contains results of the genericInout.Name +type GenericInoutMockNameResults[T any] struct { + t2 T +} + +// Expect sets up expected params for genericInout.Name +func (mmName *mGenericInoutMockName[T]) Expect(t1 T) *mGenericInoutMockName[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericInoutMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericInoutMockNameExpectation[T]{} + } + + mmName.defaultExpectation.params = &GenericInoutMockNameParams[T]{t1} + for _, e := range mmName.expectations { + if minimock.Equal(e.params, mmName.defaultExpectation.params) { + mmName.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmName.defaultExpectation.params) + } + } + + return mmName +} + +// Inspect accepts an inspector function that has same arguments as the genericInout.Name +func (mmName *mGenericInoutMockName[T]) Inspect(f func(t1 T)) *mGenericInoutMockName[T] { + if mmName.mock.inspectFuncName != nil { + mmName.mock.t.Fatalf("Inspect function is already set for GenericInoutMock.Name") + } + + mmName.mock.inspectFuncName = f + + return mmName +} + +// Return sets up results that will be returned by genericInout.Name +func (mmName *mGenericInoutMockName[T]) Return(t2 T) *GenericInoutMock[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericInoutMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericInoutMockNameExpectation[T]{mock: mmName.mock} + } + mmName.defaultExpectation.results = &GenericInoutMockNameResults[T]{t2} + return mmName.mock +} + +// Set uses given function f to mock the genericInout.Name method +func (mmName *mGenericInoutMockName[T]) Set(f func(t1 T) (t2 T)) *GenericInoutMock[T] { + if mmName.defaultExpectation != nil { + mmName.mock.t.Fatalf("Default expectation is already set for the genericInout.Name method") + } + + if len(mmName.expectations) > 0 { + mmName.mock.t.Fatalf("Some expectations are already set for the genericInout.Name method") + } + + mmName.mock.funcName = f + return mmName.mock +} + +// When sets expectation for the genericInout.Name which will trigger the result defined by the following +// Then helper +func (mmName *mGenericInoutMockName[T]) When(t1 T) *GenericInoutMockNameExpectation[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericInoutMock.Name mock is already set by Set") + } + + expectation := &GenericInoutMockNameExpectation[T]{ + mock: mmName.mock, + params: &GenericInoutMockNameParams[T]{t1}, + } + mmName.expectations = append(mmName.expectations, expectation) + return expectation +} + +// Then sets up genericInout.Name return parameters for the expectation previously defined by the When method +func (e *GenericInoutMockNameExpectation[T]) Then(t2 T) *GenericInoutMock[T] { + e.results = &GenericInoutMockNameResults[T]{t2} + return e.mock +} + +// Name implements genericInout +func (mmName *GenericInoutMock[T]) Name(t1 T) (t2 T) { + mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) + defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) + + if mmName.inspectFuncName != nil { + mmName.inspectFuncName(t1) + } + + mm_params := &GenericInoutMockNameParams[T]{t1} + + // Record call args + mmName.NameMock.mutex.Lock() + mmName.NameMock.callArgs = append(mmName.NameMock.callArgs, mm_params) + mmName.NameMock.mutex.Unlock() + + for _, e := range mmName.NameMock.expectations { + if minimock.Equal(e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.t2 + } + } + + if mmName.NameMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmName.NameMock.defaultExpectation.Counter, 1) + mm_want := mmName.NameMock.defaultExpectation.params + mm_got := GenericInoutMockNameParams[T]{t1} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmName.t.Errorf("GenericInoutMock.Name got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmName.NameMock.defaultExpectation.results + if mm_results == nil { + mmName.t.Fatal("No results are set for the GenericInoutMock.Name") + } + return (*mm_results).t2 + } + if mmName.funcName != nil { + return mmName.funcName(t1) + } + mmName.t.Fatalf("Unexpected call to GenericInoutMock.Name. %v", t1) + return +} + +// NameAfterCounter returns a count of finished GenericInoutMock.Name invocations +func (mmName *GenericInoutMock[T]) NameAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.afterNameCounter) +} + +// NameBeforeCounter returns a count of GenericInoutMock.Name invocations +func (mmName *GenericInoutMock[T]) NameBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.beforeNameCounter) +} + +// Calls returns a list of arguments used in each call to GenericInoutMock.Name. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmName *mGenericInoutMockName[T]) Calls() []*GenericInoutMockNameParams[T] { + mmName.mutex.RLock() + + argCopy := make([]*GenericInoutMockNameParams[T], len(mmName.callArgs)) + copy(argCopy, mmName.callArgs) + + mmName.mutex.RUnlock() + + return argCopy +} + +// MinimockNameDone returns true if the count of the Name invocations corresponds +// the number of defined expectations +func (m *GenericInoutMock[T]) MinimockNameDone() bool { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + return true +} + +// MinimockNameInspect logs each unmet expectation +func (m *GenericInoutMock[T]) MinimockNameInspect() { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to GenericInoutMock.Name with params: %#v", *e.params) + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + if m.NameMock.defaultExpectation.params == nil { + m.t.Error("Expected call to GenericInoutMock.Name") + } else { + m.t.Errorf("Expected call to GenericInoutMock.Name with params: %#v", *m.NameMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + m.t.Error("Expected call to GenericInoutMock.Name") + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *GenericInoutMock[T]) MinimockFinish() { + if !m.minimockDone() { + m.MinimockNameInspect() + m.t.FailNow() + } +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *GenericInoutMock[T]) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *GenericInoutMock[T]) minimockDone() bool { + done := true + return done && + m.MinimockNameDone() +} + diff --git a/snapshots/TestSnapshot-generics_with_any_used_as_param_type.go b/snapshots/TestSnapshot-generics_with_any_used_as_param_type.go new file mode 100644 index 0000000..7aba884 --- /dev/null +++ b/snapshots/TestSnapshot-generics_with_any_used_as_param_type.go @@ -0,0 +1,255 @@ +package tests + +// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. + +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericIn -o ./tests/generic_in.go -n GenericInMock + +import ( + "sync" + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" +) + +// GenericInMock implements genericIn +type GenericInMock[T any] struct { + t minimock.Tester + + funcName func(t1 T) + inspectFuncName func(t1 T) + afterNameCounter uint64 + beforeNameCounter uint64 + NameMock mGenericInMockName[T] +} + +// NewGenericInMock returns a mock for genericIn +func NewGenericInMock[T any](t minimock.Tester) *GenericInMock[T] { + m := &GenericInMock[T]{t: t} + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.NameMock = mGenericInMockName[T]{mock: m} + m.NameMock.callArgs = []*GenericInMockNameParams[T]{} + + return m +} + +type mGenericInMockName[T any] struct { + mock *GenericInMock[T] + defaultExpectation *GenericInMockNameExpectation[T] + expectations []*GenericInMockNameExpectation[T] + + callArgs []*GenericInMockNameParams[T] + mutex sync.RWMutex +} + +// GenericInMockNameExpectation specifies expectation struct of the genericIn.Name +type GenericInMockNameExpectation[T any] struct { + mock *GenericInMock[T] + params *GenericInMockNameParams[T] + + Counter uint64 +} + +// GenericInMockNameParams contains parameters of the genericIn.Name +type GenericInMockNameParams[T any] struct { + t1 T +} + +// Expect sets up expected params for genericIn.Name +func (mmName *mGenericInMockName[T]) Expect(t1 T) *mGenericInMockName[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericInMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericInMockNameExpectation[T]{} + } + + mmName.defaultExpectation.params = &GenericInMockNameParams[T]{t1} + for _, e := range mmName.expectations { + if minimock.Equal(e.params, mmName.defaultExpectation.params) { + mmName.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmName.defaultExpectation.params) + } + } + + return mmName +} + +// Inspect accepts an inspector function that has same arguments as the genericIn.Name +func (mmName *mGenericInMockName[T]) Inspect(f func(t1 T)) *mGenericInMockName[T] { + if mmName.mock.inspectFuncName != nil { + mmName.mock.t.Fatalf("Inspect function is already set for GenericInMock.Name") + } + + mmName.mock.inspectFuncName = f + + return mmName +} + +// Return sets up results that will be returned by genericIn.Name +func (mmName *mGenericInMockName[T]) Return() *GenericInMock[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericInMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericInMockNameExpectation[T]{mock: mmName.mock} + } + + return mmName.mock +} + +// Set uses given function f to mock the genericIn.Name method +func (mmName *mGenericInMockName[T]) Set(f func(t1 T)) *GenericInMock[T] { + if mmName.defaultExpectation != nil { + mmName.mock.t.Fatalf("Default expectation is already set for the genericIn.Name method") + } + + if len(mmName.expectations) > 0 { + mmName.mock.t.Fatalf("Some expectations are already set for the genericIn.Name method") + } + + mmName.mock.funcName = f + return mmName.mock +} + +// Name implements genericIn +func (mmName *GenericInMock[T]) Name(t1 T) { + mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) + defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) + + if mmName.inspectFuncName != nil { + mmName.inspectFuncName(t1) + } + + mm_params := &GenericInMockNameParams[T]{t1} + + // Record call args + mmName.NameMock.mutex.Lock() + mmName.NameMock.callArgs = append(mmName.NameMock.callArgs, mm_params) + mmName.NameMock.mutex.Unlock() + + for _, e := range mmName.NameMock.expectations { + if minimock.Equal(e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return + } + } + + if mmName.NameMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmName.NameMock.defaultExpectation.Counter, 1) + mm_want := mmName.NameMock.defaultExpectation.params + mm_got := GenericInMockNameParams[T]{t1} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmName.t.Errorf("GenericInMock.Name got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + return + + } + if mmName.funcName != nil { + mmName.funcName(t1) + return + } + mmName.t.Fatalf("Unexpected call to GenericInMock.Name. %v", t1) + +} + +// NameAfterCounter returns a count of finished GenericInMock.Name invocations +func (mmName *GenericInMock[T]) NameAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.afterNameCounter) +} + +// NameBeforeCounter returns a count of GenericInMock.Name invocations +func (mmName *GenericInMock[T]) NameBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.beforeNameCounter) +} + +// Calls returns a list of arguments used in each call to GenericInMock.Name. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmName *mGenericInMockName[T]) Calls() []*GenericInMockNameParams[T] { + mmName.mutex.RLock() + + argCopy := make([]*GenericInMockNameParams[T], len(mmName.callArgs)) + copy(argCopy, mmName.callArgs) + + mmName.mutex.RUnlock() + + return argCopy +} + +// MinimockNameDone returns true if the count of the Name invocations corresponds +// the number of defined expectations +func (m *GenericInMock[T]) MinimockNameDone() bool { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + return true +} + +// MinimockNameInspect logs each unmet expectation +func (m *GenericInMock[T]) MinimockNameInspect() { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to GenericInMock.Name with params: %#v", *e.params) + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + if m.NameMock.defaultExpectation.params == nil { + m.t.Error("Expected call to GenericInMock.Name") + } else { + m.t.Errorf("Expected call to GenericInMock.Name with params: %#v", *m.NameMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + m.t.Error("Expected call to GenericInMock.Name") + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *GenericInMock[T]) MinimockFinish() { + if !m.minimockDone() { + m.MinimockNameInspect() + m.t.FailNow() + } +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *GenericInMock[T]) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *GenericInMock[T]) minimockDone() bool { + done := true + return done && + m.MinimockNameDone() +} + diff --git a/snapshots/TestSnapshot-generics_with_any_used_as_return_type.go b/snapshots/TestSnapshot-generics_with_any_used_as_return_type.go new file mode 100644 index 0000000..0b46107 --- /dev/null +++ b/snapshots/TestSnapshot-generics_with_any_used_as_return_type.go @@ -0,0 +1,209 @@ +package tests + +// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. + +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericOut -o ./tests/generic_out.go -n GenericOutMock + +import ( + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" +) + +// GenericOutMock implements genericOut +type GenericOutMock[T any] struct { + t minimock.Tester + + funcName func() (t1 T) + inspectFuncName func() + afterNameCounter uint64 + beforeNameCounter uint64 + NameMock mGenericOutMockName[T] +} + +// NewGenericOutMock returns a mock for genericOut +func NewGenericOutMock[T any](t minimock.Tester) *GenericOutMock[T] { + m := &GenericOutMock[T]{t: t} + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.NameMock = mGenericOutMockName[T]{mock: m} + + return m +} + +type mGenericOutMockName[T any] struct { + mock *GenericOutMock[T] + defaultExpectation *GenericOutMockNameExpectation[T] + expectations []*GenericOutMockNameExpectation[T] +} + +// GenericOutMockNameExpectation specifies expectation struct of the genericOut.Name +type GenericOutMockNameExpectation[T any] struct { + mock *GenericOutMock[T] + + results *GenericOutMockNameResults[T] + Counter uint64 +} + +// GenericOutMockNameResults contains results of the genericOut.Name +type GenericOutMockNameResults[T any] struct { + t1 T +} + +// Expect sets up expected params for genericOut.Name +func (mmName *mGenericOutMockName[T]) Expect() *mGenericOutMockName[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericOutMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericOutMockNameExpectation[T]{} + } + + return mmName +} + +// Inspect accepts an inspector function that has same arguments as the genericOut.Name +func (mmName *mGenericOutMockName[T]) Inspect(f func()) *mGenericOutMockName[T] { + if mmName.mock.inspectFuncName != nil { + mmName.mock.t.Fatalf("Inspect function is already set for GenericOutMock.Name") + } + + mmName.mock.inspectFuncName = f + + return mmName +} + +// Return sets up results that will be returned by genericOut.Name +func (mmName *mGenericOutMockName[T]) Return(t1 T) *GenericOutMock[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericOutMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericOutMockNameExpectation[T]{mock: mmName.mock} + } + mmName.defaultExpectation.results = &GenericOutMockNameResults[T]{t1} + return mmName.mock +} + +// Set uses given function f to mock the genericOut.Name method +func (mmName *mGenericOutMockName[T]) Set(f func() (t1 T)) *GenericOutMock[T] { + if mmName.defaultExpectation != nil { + mmName.mock.t.Fatalf("Default expectation is already set for the genericOut.Name method") + } + + if len(mmName.expectations) > 0 { + mmName.mock.t.Fatalf("Some expectations are already set for the genericOut.Name method") + } + + mmName.mock.funcName = f + return mmName.mock +} + +// Name implements genericOut +func (mmName *GenericOutMock[T]) Name() (t1 T) { + mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) + defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) + + if mmName.inspectFuncName != nil { + mmName.inspectFuncName() + } + + if mmName.NameMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmName.NameMock.defaultExpectation.Counter, 1) + + mm_results := mmName.NameMock.defaultExpectation.results + if mm_results == nil { + mmName.t.Fatal("No results are set for the GenericOutMock.Name") + } + return (*mm_results).t1 + } + if mmName.funcName != nil { + return mmName.funcName() + } + mmName.t.Fatalf("Unexpected call to GenericOutMock.Name.") + return +} + +// NameAfterCounter returns a count of finished GenericOutMock.Name invocations +func (mmName *GenericOutMock[T]) NameAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.afterNameCounter) +} + +// NameBeforeCounter returns a count of GenericOutMock.Name invocations +func (mmName *GenericOutMock[T]) NameBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.beforeNameCounter) +} + +// MinimockNameDone returns true if the count of the Name invocations corresponds +// the number of defined expectations +func (m *GenericOutMock[T]) MinimockNameDone() bool { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + return true +} + +// MinimockNameInspect logs each unmet expectation +func (m *GenericOutMock[T]) MinimockNameInspect() { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Error("Expected call to GenericOutMock.Name") + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + m.t.Error("Expected call to GenericOutMock.Name") + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + m.t.Error("Expected call to GenericOutMock.Name") + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *GenericOutMock[T]) MinimockFinish() { + if !m.minimockDone() { + m.MinimockNameInspect() + m.t.FailNow() + } +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *GenericOutMock[T]) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *GenericOutMock[T]) minimockDone() bool { + done := true + return done && + m.MinimockNameDone() +} + diff --git a/snapshots/TestSnapshot-generics_with_complex_inline_union_used_as_a_generic_constraint.go b/snapshots/TestSnapshot-generics_with_complex_inline_union_used_as_a_generic_constraint.go new file mode 100644 index 0000000..4ce08c8 --- /dev/null +++ b/snapshots/TestSnapshot-generics_with_complex_inline_union_used_as_a_generic_constraint.go @@ -0,0 +1,255 @@ +package tests + +// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. + +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericInlineUnion -o ./tests/generic_inline_union.go -n GenericInlineUnionMock + +import ( + "sync" + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" +) + +// GenericInlineUnionMock implements genericInlineUnion +type GenericInlineUnionMock[T int | float64] struct { + t minimock.Tester + + funcName func(t1 T) + inspectFuncName func(t1 T) + afterNameCounter uint64 + beforeNameCounter uint64 + NameMock mGenericInlineUnionMockName[T] +} + +// NewGenericInlineUnionMock returns a mock for genericInlineUnion +func NewGenericInlineUnionMock[T int | float64](t minimock.Tester) *GenericInlineUnionMock[T] { + m := &GenericInlineUnionMock[T]{t: t} + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.NameMock = mGenericInlineUnionMockName[T]{mock: m} + m.NameMock.callArgs = []*GenericInlineUnionMockNameParams[T]{} + + return m +} + +type mGenericInlineUnionMockName[T int | float64] struct { + mock *GenericInlineUnionMock[T] + defaultExpectation *GenericInlineUnionMockNameExpectation[T] + expectations []*GenericInlineUnionMockNameExpectation[T] + + callArgs []*GenericInlineUnionMockNameParams[T] + mutex sync.RWMutex +} + +// GenericInlineUnionMockNameExpectation specifies expectation struct of the genericInlineUnion.Name +type GenericInlineUnionMockNameExpectation[T int | float64] struct { + mock *GenericInlineUnionMock[T] + params *GenericInlineUnionMockNameParams[T] + + Counter uint64 +} + +// GenericInlineUnionMockNameParams contains parameters of the genericInlineUnion.Name +type GenericInlineUnionMockNameParams[T int | float64] struct { + t1 T +} + +// Expect sets up expected params for genericInlineUnion.Name +func (mmName *mGenericInlineUnionMockName[T]) Expect(t1 T) *mGenericInlineUnionMockName[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericInlineUnionMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericInlineUnionMockNameExpectation[T]{} + } + + mmName.defaultExpectation.params = &GenericInlineUnionMockNameParams[T]{t1} + for _, e := range mmName.expectations { + if minimock.Equal(e.params, mmName.defaultExpectation.params) { + mmName.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmName.defaultExpectation.params) + } + } + + return mmName +} + +// Inspect accepts an inspector function that has same arguments as the genericInlineUnion.Name +func (mmName *mGenericInlineUnionMockName[T]) Inspect(f func(t1 T)) *mGenericInlineUnionMockName[T] { + if mmName.mock.inspectFuncName != nil { + mmName.mock.t.Fatalf("Inspect function is already set for GenericInlineUnionMock.Name") + } + + mmName.mock.inspectFuncName = f + + return mmName +} + +// Return sets up results that will be returned by genericInlineUnion.Name +func (mmName *mGenericInlineUnionMockName[T]) Return() *GenericInlineUnionMock[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericInlineUnionMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericInlineUnionMockNameExpectation[T]{mock: mmName.mock} + } + + return mmName.mock +} + +// Set uses given function f to mock the genericInlineUnion.Name method +func (mmName *mGenericInlineUnionMockName[T]) Set(f func(t1 T)) *GenericInlineUnionMock[T] { + if mmName.defaultExpectation != nil { + mmName.mock.t.Fatalf("Default expectation is already set for the genericInlineUnion.Name method") + } + + if len(mmName.expectations) > 0 { + mmName.mock.t.Fatalf("Some expectations are already set for the genericInlineUnion.Name method") + } + + mmName.mock.funcName = f + return mmName.mock +} + +// Name implements genericInlineUnion +func (mmName *GenericInlineUnionMock[T]) Name(t1 T) { + mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) + defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) + + if mmName.inspectFuncName != nil { + mmName.inspectFuncName(t1) + } + + mm_params := &GenericInlineUnionMockNameParams[T]{t1} + + // Record call args + mmName.NameMock.mutex.Lock() + mmName.NameMock.callArgs = append(mmName.NameMock.callArgs, mm_params) + mmName.NameMock.mutex.Unlock() + + for _, e := range mmName.NameMock.expectations { + if minimock.Equal(e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return + } + } + + if mmName.NameMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmName.NameMock.defaultExpectation.Counter, 1) + mm_want := mmName.NameMock.defaultExpectation.params + mm_got := GenericInlineUnionMockNameParams[T]{t1} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmName.t.Errorf("GenericInlineUnionMock.Name got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + return + + } + if mmName.funcName != nil { + mmName.funcName(t1) + return + } + mmName.t.Fatalf("Unexpected call to GenericInlineUnionMock.Name. %v", t1) + +} + +// NameAfterCounter returns a count of finished GenericInlineUnionMock.Name invocations +func (mmName *GenericInlineUnionMock[T]) NameAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.afterNameCounter) +} + +// NameBeforeCounter returns a count of GenericInlineUnionMock.Name invocations +func (mmName *GenericInlineUnionMock[T]) NameBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.beforeNameCounter) +} + +// Calls returns a list of arguments used in each call to GenericInlineUnionMock.Name. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmName *mGenericInlineUnionMockName[T]) Calls() []*GenericInlineUnionMockNameParams[T] { + mmName.mutex.RLock() + + argCopy := make([]*GenericInlineUnionMockNameParams[T], len(mmName.callArgs)) + copy(argCopy, mmName.callArgs) + + mmName.mutex.RUnlock() + + return argCopy +} + +// MinimockNameDone returns true if the count of the Name invocations corresponds +// the number of defined expectations +func (m *GenericInlineUnionMock[T]) MinimockNameDone() bool { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + return true +} + +// MinimockNameInspect logs each unmet expectation +func (m *GenericInlineUnionMock[T]) MinimockNameInspect() { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to GenericInlineUnionMock.Name with params: %#v", *e.params) + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + if m.NameMock.defaultExpectation.params == nil { + m.t.Error("Expected call to GenericInlineUnionMock.Name") + } else { + m.t.Errorf("Expected call to GenericInlineUnionMock.Name with params: %#v", *m.NameMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + m.t.Error("Expected call to GenericInlineUnionMock.Name") + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *GenericInlineUnionMock[T]) MinimockFinish() { + if !m.minimockDone() { + m.MinimockNameInspect() + m.t.FailNow() + } +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *GenericInlineUnionMock[T]) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *GenericInlineUnionMock[T]) minimockDone() bool { + done := true + return done && + m.MinimockNameDone() +} + diff --git a/snapshots/TestSnapshot-generics_with_complex_union_used_as_a_generic_constraint.go b/snapshots/TestSnapshot-generics_with_complex_union_used_as_a_generic_constraint.go new file mode 100644 index 0000000..67277e1 --- /dev/null +++ b/snapshots/TestSnapshot-generics_with_complex_union_used_as_a_generic_constraint.go @@ -0,0 +1,255 @@ +package tests + +// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. + +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericComplexUnion -o ./tests/generic_complex_union.go -n GenericComplexUnionMock + +import ( + "sync" + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" +) + +// GenericComplexUnionMock implements genericComplexUnion +type GenericComplexUnionMock[T complexUnion] struct { + t minimock.Tester + + funcName func(t1 T) + inspectFuncName func(t1 T) + afterNameCounter uint64 + beforeNameCounter uint64 + NameMock mGenericComplexUnionMockName[T] +} + +// NewGenericComplexUnionMock returns a mock for genericComplexUnion +func NewGenericComplexUnionMock[T complexUnion](t minimock.Tester) *GenericComplexUnionMock[T] { + m := &GenericComplexUnionMock[T]{t: t} + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.NameMock = mGenericComplexUnionMockName[T]{mock: m} + m.NameMock.callArgs = []*GenericComplexUnionMockNameParams[T]{} + + return m +} + +type mGenericComplexUnionMockName[T complexUnion] struct { + mock *GenericComplexUnionMock[T] + defaultExpectation *GenericComplexUnionMockNameExpectation[T] + expectations []*GenericComplexUnionMockNameExpectation[T] + + callArgs []*GenericComplexUnionMockNameParams[T] + mutex sync.RWMutex +} + +// GenericComplexUnionMockNameExpectation specifies expectation struct of the genericComplexUnion.Name +type GenericComplexUnionMockNameExpectation[T complexUnion] struct { + mock *GenericComplexUnionMock[T] + params *GenericComplexUnionMockNameParams[T] + + Counter uint64 +} + +// GenericComplexUnionMockNameParams contains parameters of the genericComplexUnion.Name +type GenericComplexUnionMockNameParams[T complexUnion] struct { + t1 T +} + +// Expect sets up expected params for genericComplexUnion.Name +func (mmName *mGenericComplexUnionMockName[T]) Expect(t1 T) *mGenericComplexUnionMockName[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericComplexUnionMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericComplexUnionMockNameExpectation[T]{} + } + + mmName.defaultExpectation.params = &GenericComplexUnionMockNameParams[T]{t1} + for _, e := range mmName.expectations { + if minimock.Equal(e.params, mmName.defaultExpectation.params) { + mmName.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmName.defaultExpectation.params) + } + } + + return mmName +} + +// Inspect accepts an inspector function that has same arguments as the genericComplexUnion.Name +func (mmName *mGenericComplexUnionMockName[T]) Inspect(f func(t1 T)) *mGenericComplexUnionMockName[T] { + if mmName.mock.inspectFuncName != nil { + mmName.mock.t.Fatalf("Inspect function is already set for GenericComplexUnionMock.Name") + } + + mmName.mock.inspectFuncName = f + + return mmName +} + +// Return sets up results that will be returned by genericComplexUnion.Name +func (mmName *mGenericComplexUnionMockName[T]) Return() *GenericComplexUnionMock[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericComplexUnionMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericComplexUnionMockNameExpectation[T]{mock: mmName.mock} + } + + return mmName.mock +} + +// Set uses given function f to mock the genericComplexUnion.Name method +func (mmName *mGenericComplexUnionMockName[T]) Set(f func(t1 T)) *GenericComplexUnionMock[T] { + if mmName.defaultExpectation != nil { + mmName.mock.t.Fatalf("Default expectation is already set for the genericComplexUnion.Name method") + } + + if len(mmName.expectations) > 0 { + mmName.mock.t.Fatalf("Some expectations are already set for the genericComplexUnion.Name method") + } + + mmName.mock.funcName = f + return mmName.mock +} + +// Name implements genericComplexUnion +func (mmName *GenericComplexUnionMock[T]) Name(t1 T) { + mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) + defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) + + if mmName.inspectFuncName != nil { + mmName.inspectFuncName(t1) + } + + mm_params := &GenericComplexUnionMockNameParams[T]{t1} + + // Record call args + mmName.NameMock.mutex.Lock() + mmName.NameMock.callArgs = append(mmName.NameMock.callArgs, mm_params) + mmName.NameMock.mutex.Unlock() + + for _, e := range mmName.NameMock.expectations { + if minimock.Equal(e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return + } + } + + if mmName.NameMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmName.NameMock.defaultExpectation.Counter, 1) + mm_want := mmName.NameMock.defaultExpectation.params + mm_got := GenericComplexUnionMockNameParams[T]{t1} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmName.t.Errorf("GenericComplexUnionMock.Name got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + return + + } + if mmName.funcName != nil { + mmName.funcName(t1) + return + } + mmName.t.Fatalf("Unexpected call to GenericComplexUnionMock.Name. %v", t1) + +} + +// NameAfterCounter returns a count of finished GenericComplexUnionMock.Name invocations +func (mmName *GenericComplexUnionMock[T]) NameAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.afterNameCounter) +} + +// NameBeforeCounter returns a count of GenericComplexUnionMock.Name invocations +func (mmName *GenericComplexUnionMock[T]) NameBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.beforeNameCounter) +} + +// Calls returns a list of arguments used in each call to GenericComplexUnionMock.Name. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmName *mGenericComplexUnionMockName[T]) Calls() []*GenericComplexUnionMockNameParams[T] { + mmName.mutex.RLock() + + argCopy := make([]*GenericComplexUnionMockNameParams[T], len(mmName.callArgs)) + copy(argCopy, mmName.callArgs) + + mmName.mutex.RUnlock() + + return argCopy +} + +// MinimockNameDone returns true if the count of the Name invocations corresponds +// the number of defined expectations +func (m *GenericComplexUnionMock[T]) MinimockNameDone() bool { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + return true +} + +// MinimockNameInspect logs each unmet expectation +func (m *GenericComplexUnionMock[T]) MinimockNameInspect() { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to GenericComplexUnionMock.Name with params: %#v", *e.params) + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + if m.NameMock.defaultExpectation.params == nil { + m.t.Error("Expected call to GenericComplexUnionMock.Name") + } else { + m.t.Errorf("Expected call to GenericComplexUnionMock.Name with params: %#v", *m.NameMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + m.t.Error("Expected call to GenericComplexUnionMock.Name") + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *GenericComplexUnionMock[T]) MinimockFinish() { + if !m.minimockDone() { + m.MinimockNameInspect() + m.t.FailNow() + } +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *GenericComplexUnionMock[T]) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *GenericComplexUnionMock[T]) minimockDone() bool { + done := true + return done && + m.MinimockNameDone() +} + diff --git a/snapshots/TestSnapshot-generics_with_simple_union_used_as_a_generic_constraint.go b/snapshots/TestSnapshot-generics_with_simple_union_used_as_a_generic_constraint.go new file mode 100644 index 0000000..9a9832f --- /dev/null +++ b/snapshots/TestSnapshot-generics_with_simple_union_used_as_a_generic_constraint.go @@ -0,0 +1,255 @@ +package tests + +// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. + +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericSimpleUnion -o ./tests/generic_simple_union.go -n GenericSimpleUnionMock + +import ( + "sync" + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" +) + +// GenericSimpleUnionMock implements genericSimpleUnion +type GenericSimpleUnionMock[T simpleUnion] struct { + t minimock.Tester + + funcName func(t1 T) + inspectFuncName func(t1 T) + afterNameCounter uint64 + beforeNameCounter uint64 + NameMock mGenericSimpleUnionMockName[T] +} + +// NewGenericSimpleUnionMock returns a mock for genericSimpleUnion +func NewGenericSimpleUnionMock[T simpleUnion](t minimock.Tester) *GenericSimpleUnionMock[T] { + m := &GenericSimpleUnionMock[T]{t: t} + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.NameMock = mGenericSimpleUnionMockName[T]{mock: m} + m.NameMock.callArgs = []*GenericSimpleUnionMockNameParams[T]{} + + return m +} + +type mGenericSimpleUnionMockName[T simpleUnion] struct { + mock *GenericSimpleUnionMock[T] + defaultExpectation *GenericSimpleUnionMockNameExpectation[T] + expectations []*GenericSimpleUnionMockNameExpectation[T] + + callArgs []*GenericSimpleUnionMockNameParams[T] + mutex sync.RWMutex +} + +// GenericSimpleUnionMockNameExpectation specifies expectation struct of the genericSimpleUnion.Name +type GenericSimpleUnionMockNameExpectation[T simpleUnion] struct { + mock *GenericSimpleUnionMock[T] + params *GenericSimpleUnionMockNameParams[T] + + Counter uint64 +} + +// GenericSimpleUnionMockNameParams contains parameters of the genericSimpleUnion.Name +type GenericSimpleUnionMockNameParams[T simpleUnion] struct { + t1 T +} + +// Expect sets up expected params for genericSimpleUnion.Name +func (mmName *mGenericSimpleUnionMockName[T]) Expect(t1 T) *mGenericSimpleUnionMockName[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericSimpleUnionMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericSimpleUnionMockNameExpectation[T]{} + } + + mmName.defaultExpectation.params = &GenericSimpleUnionMockNameParams[T]{t1} + for _, e := range mmName.expectations { + if minimock.Equal(e.params, mmName.defaultExpectation.params) { + mmName.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmName.defaultExpectation.params) + } + } + + return mmName +} + +// Inspect accepts an inspector function that has same arguments as the genericSimpleUnion.Name +func (mmName *mGenericSimpleUnionMockName[T]) Inspect(f func(t1 T)) *mGenericSimpleUnionMockName[T] { + if mmName.mock.inspectFuncName != nil { + mmName.mock.t.Fatalf("Inspect function is already set for GenericSimpleUnionMock.Name") + } + + mmName.mock.inspectFuncName = f + + return mmName +} + +// Return sets up results that will be returned by genericSimpleUnion.Name +func (mmName *mGenericSimpleUnionMockName[T]) Return() *GenericSimpleUnionMock[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericSimpleUnionMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericSimpleUnionMockNameExpectation[T]{mock: mmName.mock} + } + + return mmName.mock +} + +// Set uses given function f to mock the genericSimpleUnion.Name method +func (mmName *mGenericSimpleUnionMockName[T]) Set(f func(t1 T)) *GenericSimpleUnionMock[T] { + if mmName.defaultExpectation != nil { + mmName.mock.t.Fatalf("Default expectation is already set for the genericSimpleUnion.Name method") + } + + if len(mmName.expectations) > 0 { + mmName.mock.t.Fatalf("Some expectations are already set for the genericSimpleUnion.Name method") + } + + mmName.mock.funcName = f + return mmName.mock +} + +// Name implements genericSimpleUnion +func (mmName *GenericSimpleUnionMock[T]) Name(t1 T) { + mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) + defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) + + if mmName.inspectFuncName != nil { + mmName.inspectFuncName(t1) + } + + mm_params := &GenericSimpleUnionMockNameParams[T]{t1} + + // Record call args + mmName.NameMock.mutex.Lock() + mmName.NameMock.callArgs = append(mmName.NameMock.callArgs, mm_params) + mmName.NameMock.mutex.Unlock() + + for _, e := range mmName.NameMock.expectations { + if minimock.Equal(e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return + } + } + + if mmName.NameMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmName.NameMock.defaultExpectation.Counter, 1) + mm_want := mmName.NameMock.defaultExpectation.params + mm_got := GenericSimpleUnionMockNameParams[T]{t1} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmName.t.Errorf("GenericSimpleUnionMock.Name got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + return + + } + if mmName.funcName != nil { + mmName.funcName(t1) + return + } + mmName.t.Fatalf("Unexpected call to GenericSimpleUnionMock.Name. %v", t1) + +} + +// NameAfterCounter returns a count of finished GenericSimpleUnionMock.Name invocations +func (mmName *GenericSimpleUnionMock[T]) NameAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.afterNameCounter) +} + +// NameBeforeCounter returns a count of GenericSimpleUnionMock.Name invocations +func (mmName *GenericSimpleUnionMock[T]) NameBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.beforeNameCounter) +} + +// Calls returns a list of arguments used in each call to GenericSimpleUnionMock.Name. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmName *mGenericSimpleUnionMockName[T]) Calls() []*GenericSimpleUnionMockNameParams[T] { + mmName.mutex.RLock() + + argCopy := make([]*GenericSimpleUnionMockNameParams[T], len(mmName.callArgs)) + copy(argCopy, mmName.callArgs) + + mmName.mutex.RUnlock() + + return argCopy +} + +// MinimockNameDone returns true if the count of the Name invocations corresponds +// the number of defined expectations +func (m *GenericSimpleUnionMock[T]) MinimockNameDone() bool { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + return true +} + +// MinimockNameInspect logs each unmet expectation +func (m *GenericSimpleUnionMock[T]) MinimockNameInspect() { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to GenericSimpleUnionMock.Name with params: %#v", *e.params) + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + if m.NameMock.defaultExpectation.params == nil { + m.t.Error("Expected call to GenericSimpleUnionMock.Name") + } else { + m.t.Errorf("Expected call to GenericSimpleUnionMock.Name with params: %#v", *m.NameMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + m.t.Error("Expected call to GenericSimpleUnionMock.Name") + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *GenericSimpleUnionMock[T]) MinimockFinish() { + if !m.minimockDone() { + m.MinimockNameInspect() + m.t.FailNow() + } +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *GenericSimpleUnionMock[T]) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *GenericSimpleUnionMock[T]) minimockDone() bool { + done := true + return done && + m.MinimockNameDone() +} + diff --git a/snapshots/TestSnapshot-generics_with_specific_type_used_as_a_generic_constraint.go b/snapshots/TestSnapshot-generics_with_specific_type_used_as_a_generic_constraint.go new file mode 100644 index 0000000..f8a7ef6 --- /dev/null +++ b/snapshots/TestSnapshot-generics_with_specific_type_used_as_a_generic_constraint.go @@ -0,0 +1,256 @@ +package tests + +// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. + +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericSpecific -o ./tests/generic_specific.go -n GenericSpecificMock + +import ( + "sync" + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" + "google.golang.org/protobuf/proto" +) + +// GenericSpecificMock implements genericSpecific +type GenericSpecificMock[T proto.Message] struct { + t minimock.Tester + + funcName func(t1 T) + inspectFuncName func(t1 T) + afterNameCounter uint64 + beforeNameCounter uint64 + NameMock mGenericSpecificMockName[T] +} + +// NewGenericSpecificMock returns a mock for genericSpecific +func NewGenericSpecificMock[T proto.Message](t minimock.Tester) *GenericSpecificMock[T] { + m := &GenericSpecificMock[T]{t: t} + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.NameMock = mGenericSpecificMockName[T]{mock: m} + m.NameMock.callArgs = []*GenericSpecificMockNameParams[T]{} + + return m +} + +type mGenericSpecificMockName[T proto.Message] struct { + mock *GenericSpecificMock[T] + defaultExpectation *GenericSpecificMockNameExpectation[T] + expectations []*GenericSpecificMockNameExpectation[T] + + callArgs []*GenericSpecificMockNameParams[T] + mutex sync.RWMutex +} + +// GenericSpecificMockNameExpectation specifies expectation struct of the genericSpecific.Name +type GenericSpecificMockNameExpectation[T proto.Message] struct { + mock *GenericSpecificMock[T] + params *GenericSpecificMockNameParams[T] + + Counter uint64 +} + +// GenericSpecificMockNameParams contains parameters of the genericSpecific.Name +type GenericSpecificMockNameParams[T proto.Message] struct { + t1 T +} + +// Expect sets up expected params for genericSpecific.Name +func (mmName *mGenericSpecificMockName[T]) Expect(t1 T) *mGenericSpecificMockName[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericSpecificMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericSpecificMockNameExpectation[T]{} + } + + mmName.defaultExpectation.params = &GenericSpecificMockNameParams[T]{t1} + for _, e := range mmName.expectations { + if minimock.Equal(e.params, mmName.defaultExpectation.params) { + mmName.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmName.defaultExpectation.params) + } + } + + return mmName +} + +// Inspect accepts an inspector function that has same arguments as the genericSpecific.Name +func (mmName *mGenericSpecificMockName[T]) Inspect(f func(t1 T)) *mGenericSpecificMockName[T] { + if mmName.mock.inspectFuncName != nil { + mmName.mock.t.Fatalf("Inspect function is already set for GenericSpecificMock.Name") + } + + mmName.mock.inspectFuncName = f + + return mmName +} + +// Return sets up results that will be returned by genericSpecific.Name +func (mmName *mGenericSpecificMockName[T]) Return() *GenericSpecificMock[T] { + if mmName.mock.funcName != nil { + mmName.mock.t.Fatalf("GenericSpecificMock.Name mock is already set by Set") + } + + if mmName.defaultExpectation == nil { + mmName.defaultExpectation = &GenericSpecificMockNameExpectation[T]{mock: mmName.mock} + } + + return mmName.mock +} + +// Set uses given function f to mock the genericSpecific.Name method +func (mmName *mGenericSpecificMockName[T]) Set(f func(t1 T)) *GenericSpecificMock[T] { + if mmName.defaultExpectation != nil { + mmName.mock.t.Fatalf("Default expectation is already set for the genericSpecific.Name method") + } + + if len(mmName.expectations) > 0 { + mmName.mock.t.Fatalf("Some expectations are already set for the genericSpecific.Name method") + } + + mmName.mock.funcName = f + return mmName.mock +} + +// Name implements genericSpecific +func (mmName *GenericSpecificMock[T]) Name(t1 T) { + mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) + defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) + + if mmName.inspectFuncName != nil { + mmName.inspectFuncName(t1) + } + + mm_params := &GenericSpecificMockNameParams[T]{t1} + + // Record call args + mmName.NameMock.mutex.Lock() + mmName.NameMock.callArgs = append(mmName.NameMock.callArgs, mm_params) + mmName.NameMock.mutex.Unlock() + + for _, e := range mmName.NameMock.expectations { + if minimock.Equal(e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return + } + } + + if mmName.NameMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmName.NameMock.defaultExpectation.Counter, 1) + mm_want := mmName.NameMock.defaultExpectation.params + mm_got := GenericSpecificMockNameParams[T]{t1} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmName.t.Errorf("GenericSpecificMock.Name got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + return + + } + if mmName.funcName != nil { + mmName.funcName(t1) + return + } + mmName.t.Fatalf("Unexpected call to GenericSpecificMock.Name. %v", t1) + +} + +// NameAfterCounter returns a count of finished GenericSpecificMock.Name invocations +func (mmName *GenericSpecificMock[T]) NameAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.afterNameCounter) +} + +// NameBeforeCounter returns a count of GenericSpecificMock.Name invocations +func (mmName *GenericSpecificMock[T]) NameBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmName.beforeNameCounter) +} + +// Calls returns a list of arguments used in each call to GenericSpecificMock.Name. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmName *mGenericSpecificMockName[T]) Calls() []*GenericSpecificMockNameParams[T] { + mmName.mutex.RLock() + + argCopy := make([]*GenericSpecificMockNameParams[T], len(mmName.callArgs)) + copy(argCopy, mmName.callArgs) + + mmName.mutex.RUnlock() + + return argCopy +} + +// MinimockNameDone returns true if the count of the Name invocations corresponds +// the number of defined expectations +func (m *GenericSpecificMock[T]) MinimockNameDone() bool { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + return false + } + return true +} + +// MinimockNameInspect logs each unmet expectation +func (m *GenericSpecificMock[T]) MinimockNameInspect() { + for _, e := range m.NameMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to GenericSpecificMock.Name with params: %#v", *e.params) + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.NameMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + if m.NameMock.defaultExpectation.params == nil { + m.t.Error("Expected call to GenericSpecificMock.Name") + } else { + m.t.Errorf("Expected call to GenericSpecificMock.Name with params: %#v", *m.NameMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcName != nil && mm_atomic.LoadUint64(&m.afterNameCounter) < 1 { + m.t.Error("Expected call to GenericSpecificMock.Name") + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *GenericSpecificMock[T]) MinimockFinish() { + if !m.minimockDone() { + m.MinimockNameInspect() + m.t.FailNow() + } +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *GenericSpecificMock[T]) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *GenericSpecificMock[T]) minimockDone() bool { + done := true + return done && + m.MinimockNameDone() +} + diff --git a/snapshots/TestSnapshot-package_reference.go b/snapshots/TestSnapshot-package_reference.go new file mode 100644 index 0000000..8764f06 --- /dev/null +++ b/snapshots/TestSnapshot-package_reference.go @@ -0,0 +1,1000 @@ +package tests + +// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. + +//go:generate minimock -i github.com/gojuno/minimock/v3.Tester -o ./tests/tester_mock_test.go -n TesterMock + +import ( + "sync" + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" +) + +// TesterMock implements minimock.Tester +type TesterMock struct { + t minimock.Tester + + funcError func(p1 ...interface{}) + inspectFuncError func(p1 ...interface{}) + afterErrorCounter uint64 + beforeErrorCounter uint64 + ErrorMock mTesterMockError + + funcErrorf func(format string, args ...interface{}) + inspectFuncErrorf func(format string, args ...interface{}) + afterErrorfCounter uint64 + beforeErrorfCounter uint64 + ErrorfMock mTesterMockErrorf + + funcFailNow func() + inspectFuncFailNow func() + afterFailNowCounter uint64 + beforeFailNowCounter uint64 + FailNowMock mTesterMockFailNow + + funcFatal func(args ...interface{}) + inspectFuncFatal func(args ...interface{}) + afterFatalCounter uint64 + beforeFatalCounter uint64 + FatalMock mTesterMockFatal + + funcFatalf func(format string, args ...interface{}) + inspectFuncFatalf func(format string, args ...interface{}) + afterFatalfCounter uint64 + beforeFatalfCounter uint64 + FatalfMock mTesterMockFatalf +} + +// NewTesterMock returns a mock for minimock.Tester +func NewTesterMock(t minimock.Tester) *TesterMock { + m := &TesterMock{t: t} + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.ErrorMock = mTesterMockError{mock: m} + m.ErrorMock.callArgs = []*TesterMockErrorParams{} + + m.ErrorfMock = mTesterMockErrorf{mock: m} + m.ErrorfMock.callArgs = []*TesterMockErrorfParams{} + + m.FailNowMock = mTesterMockFailNow{mock: m} + + m.FatalMock = mTesterMockFatal{mock: m} + m.FatalMock.callArgs = []*TesterMockFatalParams{} + + m.FatalfMock = mTesterMockFatalf{mock: m} + m.FatalfMock.callArgs = []*TesterMockFatalfParams{} + + return m +} + +type mTesterMockError struct { + mock *TesterMock + defaultExpectation *TesterMockErrorExpectation + expectations []*TesterMockErrorExpectation + + callArgs []*TesterMockErrorParams + mutex sync.RWMutex +} + +// TesterMockErrorExpectation specifies expectation struct of the Tester.Error +type TesterMockErrorExpectation struct { + mock *TesterMock + params *TesterMockErrorParams + + Counter uint64 +} + +// TesterMockErrorParams contains parameters of the Tester.Error +type TesterMockErrorParams struct { + p1 []interface{} +} + +// Expect sets up expected params for Tester.Error +func (mmError *mTesterMockError) Expect(p1 ...interface{}) *mTesterMockError { + if mmError.mock.funcError != nil { + mmError.mock.t.Fatalf("TesterMock.Error mock is already set by Set") + } + + if mmError.defaultExpectation == nil { + mmError.defaultExpectation = &TesterMockErrorExpectation{} + } + + mmError.defaultExpectation.params = &TesterMockErrorParams{p1} + for _, e := range mmError.expectations { + if minimock.Equal(e.params, mmError.defaultExpectation.params) { + mmError.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmError.defaultExpectation.params) + } + } + + return mmError +} + +// Inspect accepts an inspector function that has same arguments as the Tester.Error +func (mmError *mTesterMockError) Inspect(f func(p1 ...interface{})) *mTesterMockError { + if mmError.mock.inspectFuncError != nil { + mmError.mock.t.Fatalf("Inspect function is already set for TesterMock.Error") + } + + mmError.mock.inspectFuncError = f + + return mmError +} + +// Return sets up results that will be returned by Tester.Error +func (mmError *mTesterMockError) Return() *TesterMock { + if mmError.mock.funcError != nil { + mmError.mock.t.Fatalf("TesterMock.Error mock is already set by Set") + } + + if mmError.defaultExpectation == nil { + mmError.defaultExpectation = &TesterMockErrorExpectation{mock: mmError.mock} + } + + return mmError.mock +} + +// Set uses given function f to mock the Tester.Error method +func (mmError *mTesterMockError) Set(f func(p1 ...interface{})) *TesterMock { + if mmError.defaultExpectation != nil { + mmError.mock.t.Fatalf("Default expectation is already set for the Tester.Error method") + } + + if len(mmError.expectations) > 0 { + mmError.mock.t.Fatalf("Some expectations are already set for the Tester.Error method") + } + + mmError.mock.funcError = f + return mmError.mock +} + +// Error implements minimock.Tester +func (mmError *TesterMock) Error(p1 ...interface{}) { + mm_atomic.AddUint64(&mmError.beforeErrorCounter, 1) + defer mm_atomic.AddUint64(&mmError.afterErrorCounter, 1) + + if mmError.inspectFuncError != nil { + mmError.inspectFuncError(p1...) + } + + mm_params := &TesterMockErrorParams{p1} + + // Record call args + mmError.ErrorMock.mutex.Lock() + mmError.ErrorMock.callArgs = append(mmError.ErrorMock.callArgs, mm_params) + mmError.ErrorMock.mutex.Unlock() + + for _, e := range mmError.ErrorMock.expectations { + if minimock.Equal(e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return + } + } + + if mmError.ErrorMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmError.ErrorMock.defaultExpectation.Counter, 1) + mm_want := mmError.ErrorMock.defaultExpectation.params + mm_got := TesterMockErrorParams{p1} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmError.t.Errorf("TesterMock.Error got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + return + + } + if mmError.funcError != nil { + mmError.funcError(p1...) + return + } + mmError.t.Fatalf("Unexpected call to TesterMock.Error. %v", p1) + +} + +// ErrorAfterCounter returns a count of finished TesterMock.Error invocations +func (mmError *TesterMock) ErrorAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmError.afterErrorCounter) +} + +// ErrorBeforeCounter returns a count of TesterMock.Error invocations +func (mmError *TesterMock) ErrorBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmError.beforeErrorCounter) +} + +// Calls returns a list of arguments used in each call to TesterMock.Error. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmError *mTesterMockError) Calls() []*TesterMockErrorParams { + mmError.mutex.RLock() + + argCopy := make([]*TesterMockErrorParams, len(mmError.callArgs)) + copy(argCopy, mmError.callArgs) + + mmError.mutex.RUnlock() + + return argCopy +} + +// MinimockErrorDone returns true if the count of the Error invocations corresponds +// the number of defined expectations +func (m *TesterMock) MinimockErrorDone() bool { + for _, e := range m.ErrorMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.ErrorMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterErrorCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcError != nil && mm_atomic.LoadUint64(&m.afterErrorCounter) < 1 { + return false + } + return true +} + +// MinimockErrorInspect logs each unmet expectation +func (m *TesterMock) MinimockErrorInspect() { + for _, e := range m.ErrorMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to TesterMock.Error with params: %#v", *e.params) + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.ErrorMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterErrorCounter) < 1 { + if m.ErrorMock.defaultExpectation.params == nil { + m.t.Error("Expected call to TesterMock.Error") + } else { + m.t.Errorf("Expected call to TesterMock.Error with params: %#v", *m.ErrorMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcError != nil && mm_atomic.LoadUint64(&m.afterErrorCounter) < 1 { + m.t.Error("Expected call to TesterMock.Error") + } +} + +type mTesterMockErrorf struct { + mock *TesterMock + defaultExpectation *TesterMockErrorfExpectation + expectations []*TesterMockErrorfExpectation + + callArgs []*TesterMockErrorfParams + mutex sync.RWMutex +} + +// TesterMockErrorfExpectation specifies expectation struct of the Tester.Errorf +type TesterMockErrorfExpectation struct { + mock *TesterMock + params *TesterMockErrorfParams + + Counter uint64 +} + +// TesterMockErrorfParams contains parameters of the Tester.Errorf +type TesterMockErrorfParams struct { + format string + args []interface{} +} + +// Expect sets up expected params for Tester.Errorf +func (mmErrorf *mTesterMockErrorf) Expect(format string, args ...interface{}) *mTesterMockErrorf { + if mmErrorf.mock.funcErrorf != nil { + mmErrorf.mock.t.Fatalf("TesterMock.Errorf mock is already set by Set") + } + + if mmErrorf.defaultExpectation == nil { + mmErrorf.defaultExpectation = &TesterMockErrorfExpectation{} + } + + mmErrorf.defaultExpectation.params = &TesterMockErrorfParams{format, args} + for _, e := range mmErrorf.expectations { + if minimock.Equal(e.params, mmErrorf.defaultExpectation.params) { + mmErrorf.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmErrorf.defaultExpectation.params) + } + } + + return mmErrorf +} + +// Inspect accepts an inspector function that has same arguments as the Tester.Errorf +func (mmErrorf *mTesterMockErrorf) Inspect(f func(format string, args ...interface{})) *mTesterMockErrorf { + if mmErrorf.mock.inspectFuncErrorf != nil { + mmErrorf.mock.t.Fatalf("Inspect function is already set for TesterMock.Errorf") + } + + mmErrorf.mock.inspectFuncErrorf = f + + return mmErrorf +} + +// Return sets up results that will be returned by Tester.Errorf +func (mmErrorf *mTesterMockErrorf) Return() *TesterMock { + if mmErrorf.mock.funcErrorf != nil { + mmErrorf.mock.t.Fatalf("TesterMock.Errorf mock is already set by Set") + } + + if mmErrorf.defaultExpectation == nil { + mmErrorf.defaultExpectation = &TesterMockErrorfExpectation{mock: mmErrorf.mock} + } + + return mmErrorf.mock +} + +// Set uses given function f to mock the Tester.Errorf method +func (mmErrorf *mTesterMockErrorf) Set(f func(format string, args ...interface{})) *TesterMock { + if mmErrorf.defaultExpectation != nil { + mmErrorf.mock.t.Fatalf("Default expectation is already set for the Tester.Errorf method") + } + + if len(mmErrorf.expectations) > 0 { + mmErrorf.mock.t.Fatalf("Some expectations are already set for the Tester.Errorf method") + } + + mmErrorf.mock.funcErrorf = f + return mmErrorf.mock +} + +// Errorf implements minimock.Tester +func (mmErrorf *TesterMock) Errorf(format string, args ...interface{}) { + mm_atomic.AddUint64(&mmErrorf.beforeErrorfCounter, 1) + defer mm_atomic.AddUint64(&mmErrorf.afterErrorfCounter, 1) + + if mmErrorf.inspectFuncErrorf != nil { + mmErrorf.inspectFuncErrorf(format, args...) + } + + mm_params := &TesterMockErrorfParams{format, args} + + // Record call args + mmErrorf.ErrorfMock.mutex.Lock() + mmErrorf.ErrorfMock.callArgs = append(mmErrorf.ErrorfMock.callArgs, mm_params) + mmErrorf.ErrorfMock.mutex.Unlock() + + for _, e := range mmErrorf.ErrorfMock.expectations { + if minimock.Equal(e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return + } + } + + if mmErrorf.ErrorfMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmErrorf.ErrorfMock.defaultExpectation.Counter, 1) + mm_want := mmErrorf.ErrorfMock.defaultExpectation.params + mm_got := TesterMockErrorfParams{format, args} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmErrorf.t.Errorf("TesterMock.Errorf got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + return + + } + if mmErrorf.funcErrorf != nil { + mmErrorf.funcErrorf(format, args...) + return + } + mmErrorf.t.Fatalf("Unexpected call to TesterMock.Errorf. %v %v", format, args) + +} + +// ErrorfAfterCounter returns a count of finished TesterMock.Errorf invocations +func (mmErrorf *TesterMock) ErrorfAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmErrorf.afterErrorfCounter) +} + +// ErrorfBeforeCounter returns a count of TesterMock.Errorf invocations +func (mmErrorf *TesterMock) ErrorfBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmErrorf.beforeErrorfCounter) +} + +// Calls returns a list of arguments used in each call to TesterMock.Errorf. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmErrorf *mTesterMockErrorf) Calls() []*TesterMockErrorfParams { + mmErrorf.mutex.RLock() + + argCopy := make([]*TesterMockErrorfParams, len(mmErrorf.callArgs)) + copy(argCopy, mmErrorf.callArgs) + + mmErrorf.mutex.RUnlock() + + return argCopy +} + +// MinimockErrorfDone returns true if the count of the Errorf invocations corresponds +// the number of defined expectations +func (m *TesterMock) MinimockErrorfDone() bool { + for _, e := range m.ErrorfMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.ErrorfMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterErrorfCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcErrorf != nil && mm_atomic.LoadUint64(&m.afterErrorfCounter) < 1 { + return false + } + return true +} + +// MinimockErrorfInspect logs each unmet expectation +func (m *TesterMock) MinimockErrorfInspect() { + for _, e := range m.ErrorfMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to TesterMock.Errorf with params: %#v", *e.params) + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.ErrorfMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterErrorfCounter) < 1 { + if m.ErrorfMock.defaultExpectation.params == nil { + m.t.Error("Expected call to TesterMock.Errorf") + } else { + m.t.Errorf("Expected call to TesterMock.Errorf with params: %#v", *m.ErrorfMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcErrorf != nil && mm_atomic.LoadUint64(&m.afterErrorfCounter) < 1 { + m.t.Error("Expected call to TesterMock.Errorf") + } +} + +type mTesterMockFailNow struct { + mock *TesterMock + defaultExpectation *TesterMockFailNowExpectation + expectations []*TesterMockFailNowExpectation +} + +// TesterMockFailNowExpectation specifies expectation struct of the Tester.FailNow +type TesterMockFailNowExpectation struct { + mock *TesterMock + + Counter uint64 +} + +// Expect sets up expected params for Tester.FailNow +func (mmFailNow *mTesterMockFailNow) Expect() *mTesterMockFailNow { + if mmFailNow.mock.funcFailNow != nil { + mmFailNow.mock.t.Fatalf("TesterMock.FailNow mock is already set by Set") + } + + if mmFailNow.defaultExpectation == nil { + mmFailNow.defaultExpectation = &TesterMockFailNowExpectation{} + } + + return mmFailNow +} + +// Inspect accepts an inspector function that has same arguments as the Tester.FailNow +func (mmFailNow *mTesterMockFailNow) Inspect(f func()) *mTesterMockFailNow { + if mmFailNow.mock.inspectFuncFailNow != nil { + mmFailNow.mock.t.Fatalf("Inspect function is already set for TesterMock.FailNow") + } + + mmFailNow.mock.inspectFuncFailNow = f + + return mmFailNow +} + +// Return sets up results that will be returned by Tester.FailNow +func (mmFailNow *mTesterMockFailNow) Return() *TesterMock { + if mmFailNow.mock.funcFailNow != nil { + mmFailNow.mock.t.Fatalf("TesterMock.FailNow mock is already set by Set") + } + + if mmFailNow.defaultExpectation == nil { + mmFailNow.defaultExpectation = &TesterMockFailNowExpectation{mock: mmFailNow.mock} + } + + return mmFailNow.mock +} + +// Set uses given function f to mock the Tester.FailNow method +func (mmFailNow *mTesterMockFailNow) Set(f func()) *TesterMock { + if mmFailNow.defaultExpectation != nil { + mmFailNow.mock.t.Fatalf("Default expectation is already set for the Tester.FailNow method") + } + + if len(mmFailNow.expectations) > 0 { + mmFailNow.mock.t.Fatalf("Some expectations are already set for the Tester.FailNow method") + } + + mmFailNow.mock.funcFailNow = f + return mmFailNow.mock +} + +// FailNow implements minimock.Tester +func (mmFailNow *TesterMock) FailNow() { + mm_atomic.AddUint64(&mmFailNow.beforeFailNowCounter, 1) + defer mm_atomic.AddUint64(&mmFailNow.afterFailNowCounter, 1) + + if mmFailNow.inspectFuncFailNow != nil { + mmFailNow.inspectFuncFailNow() + } + + if mmFailNow.FailNowMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmFailNow.FailNowMock.defaultExpectation.Counter, 1) + + return + + } + if mmFailNow.funcFailNow != nil { + mmFailNow.funcFailNow() + return + } + mmFailNow.t.Fatalf("Unexpected call to TesterMock.FailNow.") + +} + +// FailNowAfterCounter returns a count of finished TesterMock.FailNow invocations +func (mmFailNow *TesterMock) FailNowAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmFailNow.afterFailNowCounter) +} + +// FailNowBeforeCounter returns a count of TesterMock.FailNow invocations +func (mmFailNow *TesterMock) FailNowBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmFailNow.beforeFailNowCounter) +} + +// MinimockFailNowDone returns true if the count of the FailNow invocations corresponds +// the number of defined expectations +func (m *TesterMock) MinimockFailNowDone() bool { + for _, e := range m.FailNowMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.FailNowMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFailNowCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcFailNow != nil && mm_atomic.LoadUint64(&m.afterFailNowCounter) < 1 { + return false + } + return true +} + +// MinimockFailNowInspect logs each unmet expectation +func (m *TesterMock) MinimockFailNowInspect() { + for _, e := range m.FailNowMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Error("Expected call to TesterMock.FailNow") + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.FailNowMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFailNowCounter) < 1 { + m.t.Error("Expected call to TesterMock.FailNow") + } + // if func was set then invocations count should be greater than zero + if m.funcFailNow != nil && mm_atomic.LoadUint64(&m.afterFailNowCounter) < 1 { + m.t.Error("Expected call to TesterMock.FailNow") + } +} + +type mTesterMockFatal struct { + mock *TesterMock + defaultExpectation *TesterMockFatalExpectation + expectations []*TesterMockFatalExpectation + + callArgs []*TesterMockFatalParams + mutex sync.RWMutex +} + +// TesterMockFatalExpectation specifies expectation struct of the Tester.Fatal +type TesterMockFatalExpectation struct { + mock *TesterMock + params *TesterMockFatalParams + + Counter uint64 +} + +// TesterMockFatalParams contains parameters of the Tester.Fatal +type TesterMockFatalParams struct { + args []interface{} +} + +// Expect sets up expected params for Tester.Fatal +func (mmFatal *mTesterMockFatal) Expect(args ...interface{}) *mTesterMockFatal { + if mmFatal.mock.funcFatal != nil { + mmFatal.mock.t.Fatalf("TesterMock.Fatal mock is already set by Set") + } + + if mmFatal.defaultExpectation == nil { + mmFatal.defaultExpectation = &TesterMockFatalExpectation{} + } + + mmFatal.defaultExpectation.params = &TesterMockFatalParams{args} + for _, e := range mmFatal.expectations { + if minimock.Equal(e.params, mmFatal.defaultExpectation.params) { + mmFatal.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmFatal.defaultExpectation.params) + } + } + + return mmFatal +} + +// Inspect accepts an inspector function that has same arguments as the Tester.Fatal +func (mmFatal *mTesterMockFatal) Inspect(f func(args ...interface{})) *mTesterMockFatal { + if mmFatal.mock.inspectFuncFatal != nil { + mmFatal.mock.t.Fatalf("Inspect function is already set for TesterMock.Fatal") + } + + mmFatal.mock.inspectFuncFatal = f + + return mmFatal +} + +// Return sets up results that will be returned by Tester.Fatal +func (mmFatal *mTesterMockFatal) Return() *TesterMock { + if mmFatal.mock.funcFatal != nil { + mmFatal.mock.t.Fatalf("TesterMock.Fatal mock is already set by Set") + } + + if mmFatal.defaultExpectation == nil { + mmFatal.defaultExpectation = &TesterMockFatalExpectation{mock: mmFatal.mock} + } + + return mmFatal.mock +} + +// Set uses given function f to mock the Tester.Fatal method +func (mmFatal *mTesterMockFatal) Set(f func(args ...interface{})) *TesterMock { + if mmFatal.defaultExpectation != nil { + mmFatal.mock.t.Fatalf("Default expectation is already set for the Tester.Fatal method") + } + + if len(mmFatal.expectations) > 0 { + mmFatal.mock.t.Fatalf("Some expectations are already set for the Tester.Fatal method") + } + + mmFatal.mock.funcFatal = f + return mmFatal.mock +} + +// Fatal implements minimock.Tester +func (mmFatal *TesterMock) Fatal(args ...interface{}) { + mm_atomic.AddUint64(&mmFatal.beforeFatalCounter, 1) + defer mm_atomic.AddUint64(&mmFatal.afterFatalCounter, 1) + + if mmFatal.inspectFuncFatal != nil { + mmFatal.inspectFuncFatal(args...) + } + + mm_params := &TesterMockFatalParams{args} + + // Record call args + mmFatal.FatalMock.mutex.Lock() + mmFatal.FatalMock.callArgs = append(mmFatal.FatalMock.callArgs, mm_params) + mmFatal.FatalMock.mutex.Unlock() + + for _, e := range mmFatal.FatalMock.expectations { + if minimock.Equal(e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return + } + } + + if mmFatal.FatalMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmFatal.FatalMock.defaultExpectation.Counter, 1) + mm_want := mmFatal.FatalMock.defaultExpectation.params + mm_got := TesterMockFatalParams{args} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmFatal.t.Errorf("TesterMock.Fatal got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + return + + } + if mmFatal.funcFatal != nil { + mmFatal.funcFatal(args...) + return + } + mmFatal.t.Fatalf("Unexpected call to TesterMock.Fatal. %v", args) + +} + +// FatalAfterCounter returns a count of finished TesterMock.Fatal invocations +func (mmFatal *TesterMock) FatalAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmFatal.afterFatalCounter) +} + +// FatalBeforeCounter returns a count of TesterMock.Fatal invocations +func (mmFatal *TesterMock) FatalBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmFatal.beforeFatalCounter) +} + +// Calls returns a list of arguments used in each call to TesterMock.Fatal. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmFatal *mTesterMockFatal) Calls() []*TesterMockFatalParams { + mmFatal.mutex.RLock() + + argCopy := make([]*TesterMockFatalParams, len(mmFatal.callArgs)) + copy(argCopy, mmFatal.callArgs) + + mmFatal.mutex.RUnlock() + + return argCopy +} + +// MinimockFatalDone returns true if the count of the Fatal invocations corresponds +// the number of defined expectations +func (m *TesterMock) MinimockFatalDone() bool { + for _, e := range m.FatalMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.FatalMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFatalCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcFatal != nil && mm_atomic.LoadUint64(&m.afterFatalCounter) < 1 { + return false + } + return true +} + +// MinimockFatalInspect logs each unmet expectation +func (m *TesterMock) MinimockFatalInspect() { + for _, e := range m.FatalMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to TesterMock.Fatal with params: %#v", *e.params) + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.FatalMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFatalCounter) < 1 { + if m.FatalMock.defaultExpectation.params == nil { + m.t.Error("Expected call to TesterMock.Fatal") + } else { + m.t.Errorf("Expected call to TesterMock.Fatal with params: %#v", *m.FatalMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcFatal != nil && mm_atomic.LoadUint64(&m.afterFatalCounter) < 1 { + m.t.Error("Expected call to TesterMock.Fatal") + } +} + +type mTesterMockFatalf struct { + mock *TesterMock + defaultExpectation *TesterMockFatalfExpectation + expectations []*TesterMockFatalfExpectation + + callArgs []*TesterMockFatalfParams + mutex sync.RWMutex +} + +// TesterMockFatalfExpectation specifies expectation struct of the Tester.Fatalf +type TesterMockFatalfExpectation struct { + mock *TesterMock + params *TesterMockFatalfParams + + Counter uint64 +} + +// TesterMockFatalfParams contains parameters of the Tester.Fatalf +type TesterMockFatalfParams struct { + format string + args []interface{} +} + +// Expect sets up expected params for Tester.Fatalf +func (mmFatalf *mTesterMockFatalf) Expect(format string, args ...interface{}) *mTesterMockFatalf { + if mmFatalf.mock.funcFatalf != nil { + mmFatalf.mock.t.Fatalf("TesterMock.Fatalf mock is already set by Set") + } + + if mmFatalf.defaultExpectation == nil { + mmFatalf.defaultExpectation = &TesterMockFatalfExpectation{} + } + + mmFatalf.defaultExpectation.params = &TesterMockFatalfParams{format, args} + for _, e := range mmFatalf.expectations { + if minimock.Equal(e.params, mmFatalf.defaultExpectation.params) { + mmFatalf.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmFatalf.defaultExpectation.params) + } + } + + return mmFatalf +} + +// Inspect accepts an inspector function that has same arguments as the Tester.Fatalf +func (mmFatalf *mTesterMockFatalf) Inspect(f func(format string, args ...interface{})) *mTesterMockFatalf { + if mmFatalf.mock.inspectFuncFatalf != nil { + mmFatalf.mock.t.Fatalf("Inspect function is already set for TesterMock.Fatalf") + } + + mmFatalf.mock.inspectFuncFatalf = f + + return mmFatalf +} + +// Return sets up results that will be returned by Tester.Fatalf +func (mmFatalf *mTesterMockFatalf) Return() *TesterMock { + if mmFatalf.mock.funcFatalf != nil { + mmFatalf.mock.t.Fatalf("TesterMock.Fatalf mock is already set by Set") + } + + if mmFatalf.defaultExpectation == nil { + mmFatalf.defaultExpectation = &TesterMockFatalfExpectation{mock: mmFatalf.mock} + } + + return mmFatalf.mock +} + +// Set uses given function f to mock the Tester.Fatalf method +func (mmFatalf *mTesterMockFatalf) Set(f func(format string, args ...interface{})) *TesterMock { + if mmFatalf.defaultExpectation != nil { + mmFatalf.mock.t.Fatalf("Default expectation is already set for the Tester.Fatalf method") + } + + if len(mmFatalf.expectations) > 0 { + mmFatalf.mock.t.Fatalf("Some expectations are already set for the Tester.Fatalf method") + } + + mmFatalf.mock.funcFatalf = f + return mmFatalf.mock +} + +// Fatalf implements minimock.Tester +func (mmFatalf *TesterMock) Fatalf(format string, args ...interface{}) { + mm_atomic.AddUint64(&mmFatalf.beforeFatalfCounter, 1) + defer mm_atomic.AddUint64(&mmFatalf.afterFatalfCounter, 1) + + if mmFatalf.inspectFuncFatalf != nil { + mmFatalf.inspectFuncFatalf(format, args...) + } + + mm_params := &TesterMockFatalfParams{format, args} + + // Record call args + mmFatalf.FatalfMock.mutex.Lock() + mmFatalf.FatalfMock.callArgs = append(mmFatalf.FatalfMock.callArgs, mm_params) + mmFatalf.FatalfMock.mutex.Unlock() + + for _, e := range mmFatalf.FatalfMock.expectations { + if minimock.Equal(e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return + } + } + + if mmFatalf.FatalfMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmFatalf.FatalfMock.defaultExpectation.Counter, 1) + mm_want := mmFatalf.FatalfMock.defaultExpectation.params + mm_got := TesterMockFatalfParams{format, args} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmFatalf.t.Errorf("TesterMock.Fatalf got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + return + + } + if mmFatalf.funcFatalf != nil { + mmFatalf.funcFatalf(format, args...) + return + } + mmFatalf.t.Fatalf("Unexpected call to TesterMock.Fatalf. %v %v", format, args) + +} + +// FatalfAfterCounter returns a count of finished TesterMock.Fatalf invocations +func (mmFatalf *TesterMock) FatalfAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmFatalf.afterFatalfCounter) +} + +// FatalfBeforeCounter returns a count of TesterMock.Fatalf invocations +func (mmFatalf *TesterMock) FatalfBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmFatalf.beforeFatalfCounter) +} + +// Calls returns a list of arguments used in each call to TesterMock.Fatalf. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmFatalf *mTesterMockFatalf) Calls() []*TesterMockFatalfParams { + mmFatalf.mutex.RLock() + + argCopy := make([]*TesterMockFatalfParams, len(mmFatalf.callArgs)) + copy(argCopy, mmFatalf.callArgs) + + mmFatalf.mutex.RUnlock() + + return argCopy +} + +// MinimockFatalfDone returns true if the count of the Fatalf invocations corresponds +// the number of defined expectations +func (m *TesterMock) MinimockFatalfDone() bool { + for _, e := range m.FatalfMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.FatalfMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFatalfCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcFatalf != nil && mm_atomic.LoadUint64(&m.afterFatalfCounter) < 1 { + return false + } + return true +} + +// MinimockFatalfInspect logs each unmet expectation +func (m *TesterMock) MinimockFatalfInspect() { + for _, e := range m.FatalfMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to TesterMock.Fatalf with params: %#v", *e.params) + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.FatalfMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFatalfCounter) < 1 { + if m.FatalfMock.defaultExpectation.params == nil { + m.t.Error("Expected call to TesterMock.Fatalf") + } else { + m.t.Errorf("Expected call to TesterMock.Fatalf with params: %#v", *m.FatalfMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcFatalf != nil && mm_atomic.LoadUint64(&m.afterFatalfCounter) < 1 { + m.t.Error("Expected call to TesterMock.Fatalf") + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *TesterMock) MinimockFinish() { + if !m.minimockDone() { + m.MinimockErrorInspect() + + m.MinimockErrorfInspect() + + m.MinimockFailNowInspect() + + m.MinimockFatalInspect() + + m.MinimockFatalfInspect() + m.t.FailNow() + } +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *TesterMock) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *TesterMock) minimockDone() bool { + done := true + return done && + m.MinimockErrorDone() && + m.MinimockErrorfDone() && + m.MinimockFailNowDone() && + m.MinimockFatalDone() && + m.MinimockFatalfDone() +} + diff --git a/snapshots/TestSnapshot-relative_reference.go b/snapshots/TestSnapshot-relative_reference.go new file mode 100644 index 0000000..3f15a38 --- /dev/null +++ b/snapshots/TestSnapshot-relative_reference.go @@ -0,0 +1,284 @@ +package tests + +// Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. + +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.Formatter -o ./tests/formatter_mock.go -n FormatterMock + +import ( + "sync" + mm_atomic "sync/atomic" + mm_time "time" + + "github.com/gojuno/minimock/v3" +) + +// FormatterMock implements Formatter +type FormatterMock struct { + t minimock.Tester + + funcFormat func(s1 string, p1 ...interface{}) (s2 string) + inspectFuncFormat func(s1 string, p1 ...interface{}) + afterFormatCounter uint64 + beforeFormatCounter uint64 + FormatMock mFormatterMockFormat +} + +// NewFormatterMock returns a mock for Formatter +func NewFormatterMock(t minimock.Tester) *FormatterMock { + m := &FormatterMock{t: t} + if controller, ok := t.(minimock.MockController); ok { + controller.RegisterMocker(m) + } + + m.FormatMock = mFormatterMockFormat{mock: m} + m.FormatMock.callArgs = []*FormatterMockFormatParams{} + + return m +} + +type mFormatterMockFormat struct { + mock *FormatterMock + defaultExpectation *FormatterMockFormatExpectation + expectations []*FormatterMockFormatExpectation + + callArgs []*FormatterMockFormatParams + mutex sync.RWMutex +} + +// FormatterMockFormatExpectation specifies expectation struct of the Formatter.Format +type FormatterMockFormatExpectation struct { + mock *FormatterMock + params *FormatterMockFormatParams + results *FormatterMockFormatResults + Counter uint64 +} + +// FormatterMockFormatParams contains parameters of the Formatter.Format +type FormatterMockFormatParams struct { + s1 string + p1 []interface{} +} + +// FormatterMockFormatResults contains results of the Formatter.Format +type FormatterMockFormatResults struct { + s2 string +} + +// Expect sets up expected params for Formatter.Format +func (mmFormat *mFormatterMockFormat) Expect(s1 string, p1 ...interface{}) *mFormatterMockFormat { + if mmFormat.mock.funcFormat != nil { + mmFormat.mock.t.Fatalf("FormatterMock.Format mock is already set by Set") + } + + if mmFormat.defaultExpectation == nil { + mmFormat.defaultExpectation = &FormatterMockFormatExpectation{} + } + + mmFormat.defaultExpectation.params = &FormatterMockFormatParams{s1, p1} + for _, e := range mmFormat.expectations { + if minimock.Equal(e.params, mmFormat.defaultExpectation.params) { + mmFormat.mock.t.Fatalf("Expectation set by When has same params: %#v", *mmFormat.defaultExpectation.params) + } + } + + return mmFormat +} + +// Inspect accepts an inspector function that has same arguments as the Formatter.Format +func (mmFormat *mFormatterMockFormat) Inspect(f func(s1 string, p1 ...interface{})) *mFormatterMockFormat { + if mmFormat.mock.inspectFuncFormat != nil { + mmFormat.mock.t.Fatalf("Inspect function is already set for FormatterMock.Format") + } + + mmFormat.mock.inspectFuncFormat = f + + return mmFormat +} + +// Return sets up results that will be returned by Formatter.Format +func (mmFormat *mFormatterMockFormat) Return(s2 string) *FormatterMock { + if mmFormat.mock.funcFormat != nil { + mmFormat.mock.t.Fatalf("FormatterMock.Format mock is already set by Set") + } + + if mmFormat.defaultExpectation == nil { + mmFormat.defaultExpectation = &FormatterMockFormatExpectation{mock: mmFormat.mock} + } + mmFormat.defaultExpectation.results = &FormatterMockFormatResults{s2} + return mmFormat.mock +} + +// Set uses given function f to mock the Formatter.Format method +func (mmFormat *mFormatterMockFormat) Set(f func(s1 string, p1 ...interface{}) (s2 string)) *FormatterMock { + if mmFormat.defaultExpectation != nil { + mmFormat.mock.t.Fatalf("Default expectation is already set for the Formatter.Format method") + } + + if len(mmFormat.expectations) > 0 { + mmFormat.mock.t.Fatalf("Some expectations are already set for the Formatter.Format method") + } + + mmFormat.mock.funcFormat = f + return mmFormat.mock +} + +// When sets expectation for the Formatter.Format which will trigger the result defined by the following +// Then helper +func (mmFormat *mFormatterMockFormat) When(s1 string, p1 ...interface{}) *FormatterMockFormatExpectation { + if mmFormat.mock.funcFormat != nil { + mmFormat.mock.t.Fatalf("FormatterMock.Format mock is already set by Set") + } + + expectation := &FormatterMockFormatExpectation{ + mock: mmFormat.mock, + params: &FormatterMockFormatParams{s1, p1}, + } + mmFormat.expectations = append(mmFormat.expectations, expectation) + return expectation +} + +// Then sets up Formatter.Format return parameters for the expectation previously defined by the When method +func (e *FormatterMockFormatExpectation) Then(s2 string) *FormatterMock { + e.results = &FormatterMockFormatResults{s2} + return e.mock +} + +// Format implements Formatter +func (mmFormat *FormatterMock) Format(s1 string, p1 ...interface{}) (s2 string) { + mm_atomic.AddUint64(&mmFormat.beforeFormatCounter, 1) + defer mm_atomic.AddUint64(&mmFormat.afterFormatCounter, 1) + + if mmFormat.inspectFuncFormat != nil { + mmFormat.inspectFuncFormat(s1, p1...) + } + + mm_params := &FormatterMockFormatParams{s1, p1} + + // Record call args + mmFormat.FormatMock.mutex.Lock() + mmFormat.FormatMock.callArgs = append(mmFormat.FormatMock.callArgs, mm_params) + mmFormat.FormatMock.mutex.Unlock() + + for _, e := range mmFormat.FormatMock.expectations { + if minimock.Equal(e.params, mm_params) { + mm_atomic.AddUint64(&e.Counter, 1) + return e.results.s2 + } + } + + if mmFormat.FormatMock.defaultExpectation != nil { + mm_atomic.AddUint64(&mmFormat.FormatMock.defaultExpectation.Counter, 1) + mm_want := mmFormat.FormatMock.defaultExpectation.params + mm_got := FormatterMockFormatParams{s1, p1} + if mm_want != nil && !minimock.Equal(*mm_want, mm_got) { + mmFormat.t.Errorf("FormatterMock.Format got unexpected parameters, want: %#v, got: %#v%s\n", *mm_want, mm_got, minimock.Diff(*mm_want, mm_got)) + } + + mm_results := mmFormat.FormatMock.defaultExpectation.results + if mm_results == nil { + mmFormat.t.Fatal("No results are set for the FormatterMock.Format") + } + return (*mm_results).s2 + } + if mmFormat.funcFormat != nil { + return mmFormat.funcFormat(s1, p1...) + } + mmFormat.t.Fatalf("Unexpected call to FormatterMock.Format. %v %v", s1, p1) + return +} + +// FormatAfterCounter returns a count of finished FormatterMock.Format invocations +func (mmFormat *FormatterMock) FormatAfterCounter() uint64 { + return mm_atomic.LoadUint64(&mmFormat.afterFormatCounter) +} + +// FormatBeforeCounter returns a count of FormatterMock.Format invocations +func (mmFormat *FormatterMock) FormatBeforeCounter() uint64 { + return mm_atomic.LoadUint64(&mmFormat.beforeFormatCounter) +} + +// Calls returns a list of arguments used in each call to FormatterMock.Format. +// The list is in the same order as the calls were made (i.e. recent calls have a higher index) +func (mmFormat *mFormatterMockFormat) Calls() []*FormatterMockFormatParams { + mmFormat.mutex.RLock() + + argCopy := make([]*FormatterMockFormatParams, len(mmFormat.callArgs)) + copy(argCopy, mmFormat.callArgs) + + mmFormat.mutex.RUnlock() + + return argCopy +} + +// MinimockFormatDone returns true if the count of the Format invocations corresponds +// the number of defined expectations +func (m *FormatterMock) MinimockFormatDone() bool { + for _, e := range m.FormatMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + return false + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.FormatMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFormatCounter) < 1 { + return false + } + // if func was set then invocations count should be greater than zero + if m.funcFormat != nil && mm_atomic.LoadUint64(&m.afterFormatCounter) < 1 { + return false + } + return true +} + +// MinimockFormatInspect logs each unmet expectation +func (m *FormatterMock) MinimockFormatInspect() { + for _, e := range m.FormatMock.expectations { + if mm_atomic.LoadUint64(&e.Counter) < 1 { + m.t.Errorf("Expected call to FormatterMock.Format with params: %#v", *e.params) + } + } + + // if default expectation was set then invocations count should be greater than zero + if m.FormatMock.defaultExpectation != nil && mm_atomic.LoadUint64(&m.afterFormatCounter) < 1 { + if m.FormatMock.defaultExpectation.params == nil { + m.t.Error("Expected call to FormatterMock.Format") + } else { + m.t.Errorf("Expected call to FormatterMock.Format with params: %#v", *m.FormatMock.defaultExpectation.params) + } + } + // if func was set then invocations count should be greater than zero + if m.funcFormat != nil && mm_atomic.LoadUint64(&m.afterFormatCounter) < 1 { + m.t.Error("Expected call to FormatterMock.Format") + } +} + +// MinimockFinish checks that all mocked methods have been called the expected number of times +func (m *FormatterMock) MinimockFinish() { + if !m.minimockDone() { + m.MinimockFormatInspect() + m.t.FailNow() + } +} + +// MinimockWait waits for all mocked methods to be called the expected number of times +func (m *FormatterMock) MinimockWait(timeout mm_time.Duration) { + timeoutCh := mm_time.After(timeout) + for { + if m.minimockDone() { + return + } + select { + case <-timeoutCh: + m.MinimockFinish() + return + case <-mm_time.After(10 * mm_time.Millisecond): + } + } +} + +func (m *FormatterMock) minimockDone() bool { + done := true + return done && + m.MinimockFormatDone() +} + diff --git a/tests/generic/generic_complex_union.go b/tests/generic_complex_union.go similarity index 96% rename from tests/generic/generic_complex_union.go rename to tests/generic_complex_union.go index 6f79c1f..21df93a 100644 --- a/tests/generic/generic_complex_union.go +++ b/tests/generic_complex_union.go @@ -1,8 +1,8 @@ -package generic +package tests // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. -//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericComplexUnion -o ./tests/generic/generic_complex_union.go -n GenericComplexUnionMock +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericComplexUnion -o ./tests/generic_complex_union.go -n GenericComplexUnionMock import ( "sync" @@ -12,7 +12,7 @@ import ( "github.com/gojuno/minimock/v3" ) -// GenericComplexUnionMock implements tests.genericComplexUnion +// GenericComplexUnionMock implements genericComplexUnion type GenericComplexUnionMock[T complexUnion] struct { t minimock.Tester @@ -23,7 +23,7 @@ type GenericComplexUnionMock[T complexUnion] struct { NameMock mGenericComplexUnionMockName[T] } -// NewGenericComplexUnionMock returns a mock for tests.genericComplexUnion +// NewGenericComplexUnionMock returns a mock for genericComplexUnion func NewGenericComplexUnionMock[T complexUnion](t minimock.Tester) *GenericComplexUnionMock[T] { m := &GenericComplexUnionMock[T]{t: t} if controller, ok := t.(minimock.MockController); ok { @@ -116,7 +116,7 @@ func (mmName *mGenericComplexUnionMockName[T]) Set(f func(t1 T)) *GenericComplex return mmName.mock } -// Name implements tests.genericComplexUnion +// Name implements genericComplexUnion func (mmName *GenericComplexUnionMock[T]) Name(t1 T) { mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) diff --git a/tests/generic/generic_in.go b/tests/generic_in.go similarity index 97% rename from tests/generic/generic_in.go rename to tests/generic_in.go index bc269ea..7131416 100644 --- a/tests/generic/generic_in.go +++ b/tests/generic_in.go @@ -1,8 +1,8 @@ -package generic +package tests // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. -//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericIn -o ./tests/generic/generic_in.go -n GenericInMock +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericIn -o ./tests/generic_in.go -n GenericInMock import ( "sync" @@ -12,7 +12,7 @@ import ( "github.com/gojuno/minimock/v3" ) -// GenericInMock implements tests.genericIn +// GenericInMock implements genericIn type GenericInMock[T any] struct { t minimock.Tester @@ -23,7 +23,7 @@ type GenericInMock[T any] struct { NameMock mGenericInMockName[T] } -// NewGenericInMock returns a mock for tests.genericIn +// NewGenericInMock returns a mock for genericIn func NewGenericInMock[T any](t minimock.Tester) *GenericInMock[T] { m := &GenericInMock[T]{t: t} if controller, ok := t.(minimock.MockController); ok { @@ -116,7 +116,7 @@ func (mmName *mGenericInMockName[T]) Set(f func(t1 T)) *GenericInMock[T] { return mmName.mock } -// Name implements tests.genericIn +// Name implements genericIn func (mmName *GenericInMock[T]) Name(t1 T) { mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) diff --git a/tests/generic/generic_inline_union.go b/tests/generic_inline_union.go similarity index 96% rename from tests/generic/generic_inline_union.go rename to tests/generic_inline_union.go index 6b71f5a..6ece3f9 100644 --- a/tests/generic/generic_inline_union.go +++ b/tests/generic_inline_union.go @@ -1,8 +1,8 @@ -package generic +package tests // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. -//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericInlineUnion -o ./tests/generic/generic_inline_union.go -n GenericInlineUnionMock +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericInlineUnion -o ./tests/generic_inline_union.go -n GenericInlineUnionMock import ( "sync" @@ -12,7 +12,7 @@ import ( "github.com/gojuno/minimock/v3" ) -// GenericInlineUnionMock implements tests.genericInlineUnion +// GenericInlineUnionMock implements genericInlineUnion type GenericInlineUnionMock[T int | float64] struct { t minimock.Tester @@ -23,7 +23,7 @@ type GenericInlineUnionMock[T int | float64] struct { NameMock mGenericInlineUnionMockName[T] } -// NewGenericInlineUnionMock returns a mock for tests.genericInlineUnion +// NewGenericInlineUnionMock returns a mock for genericInlineUnion func NewGenericInlineUnionMock[T int | float64](t minimock.Tester) *GenericInlineUnionMock[T] { m := &GenericInlineUnionMock[T]{t: t} if controller, ok := t.(minimock.MockController); ok { @@ -116,7 +116,7 @@ func (mmName *mGenericInlineUnionMockName[T]) Set(f func(t1 T)) *GenericInlineUn return mmName.mock } -// Name implements tests.genericInlineUnion +// Name implements genericInlineUnion func (mmName *GenericInlineUnionMock[T]) Name(t1 T) { mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) diff --git a/tests/generic/generic_inout.go b/tests/generic_inout.go similarity index 97% rename from tests/generic/generic_inout.go rename to tests/generic_inout.go index 25702be..f741873 100644 --- a/tests/generic/generic_inout.go +++ b/tests/generic_inout.go @@ -1,8 +1,8 @@ -package generic +package tests // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. -//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericInout -o ./tests/generic/generic_inout.go -n GenericInoutMock +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericInout -o ./tests/generic_inout.go -n GenericInoutMock import ( "sync" @@ -12,7 +12,7 @@ import ( "github.com/gojuno/minimock/v3" ) -// GenericInoutMock implements tests.genericInout +// GenericInoutMock implements genericInout type GenericInoutMock[T any] struct { t minimock.Tester @@ -23,7 +23,7 @@ type GenericInoutMock[T any] struct { NameMock mGenericInoutMockName[T] } -// NewGenericInoutMock returns a mock for tests.genericInout +// NewGenericInoutMock returns a mock for genericInout func NewGenericInoutMock[T any](t minimock.Tester) *GenericInoutMock[T] { m := &GenericInoutMock[T]{t: t} if controller, ok := t.(minimock.MockController); ok { @@ -142,7 +142,7 @@ func (e *GenericInoutMockNameExpectation[T]) Then(t2 T) *GenericInoutMock[T] { return e.mock } -// Name implements tests.genericInout +// Name implements genericInout func (mmName *GenericInoutMock[T]) Name(t1 T) (t2 T) { mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) diff --git a/tests/generic/generic_out.go b/tests/generic_out.go similarity index 96% rename from tests/generic/generic_out.go rename to tests/generic_out.go index fc16cee..528e9a5 100644 --- a/tests/generic/generic_out.go +++ b/tests/generic_out.go @@ -1,8 +1,8 @@ -package generic +package tests // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. -//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericOut -o ./tests/generic/generic_out.go -n GenericOutMock +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericOut -o ./tests/generic_out.go -n GenericOutMock import ( mm_atomic "sync/atomic" @@ -11,7 +11,7 @@ import ( "github.com/gojuno/minimock/v3" ) -// GenericOutMock implements tests.genericOut +// GenericOutMock implements genericOut type GenericOutMock[T any] struct { t minimock.Tester @@ -22,7 +22,7 @@ type GenericOutMock[T any] struct { NameMock mGenericOutMockName[T] } -// NewGenericOutMock returns a mock for tests.genericOut +// NewGenericOutMock returns a mock for genericOut func NewGenericOutMock[T any](t minimock.Tester) *GenericOutMock[T] { m := &GenericOutMock[T]{t: t} if controller, ok := t.(minimock.MockController); ok { @@ -104,7 +104,7 @@ func (mmName *mGenericOutMockName[T]) Set(f func() (t1 T)) *GenericOutMock[T] { return mmName.mock } -// Name implements tests.genericOut +// Name implements genericOut func (mmName *GenericOutMock[T]) Name() (t1 T) { mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) diff --git a/tests/generic/generic_simple_union.go b/tests/generic_simple_union.go similarity index 96% rename from tests/generic/generic_simple_union.go rename to tests/generic_simple_union.go index 87c63fc..18e25e6 100644 --- a/tests/generic/generic_simple_union.go +++ b/tests/generic_simple_union.go @@ -1,8 +1,8 @@ -package generic +package tests // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. -//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericSimpleUnion -o ./tests/generic/generic_simple_union.go -n GenericSimpleUnionMock +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericSimpleUnion -o ./tests/generic_simple_union.go -n GenericSimpleUnionMock import ( "sync" @@ -12,7 +12,7 @@ import ( "github.com/gojuno/minimock/v3" ) -// GenericSimpleUnionMock implements tests.genericSimpleUnion +// GenericSimpleUnionMock implements genericSimpleUnion type GenericSimpleUnionMock[T simpleUnion] struct { t minimock.Tester @@ -23,7 +23,7 @@ type GenericSimpleUnionMock[T simpleUnion] struct { NameMock mGenericSimpleUnionMockName[T] } -// NewGenericSimpleUnionMock returns a mock for tests.genericSimpleUnion +// NewGenericSimpleUnionMock returns a mock for genericSimpleUnion func NewGenericSimpleUnionMock[T simpleUnion](t minimock.Tester) *GenericSimpleUnionMock[T] { m := &GenericSimpleUnionMock[T]{t: t} if controller, ok := t.(minimock.MockController); ok { @@ -116,7 +116,7 @@ func (mmName *mGenericSimpleUnionMockName[T]) Set(f func(t1 T)) *GenericSimpleUn return mmName.mock } -// Name implements tests.genericSimpleUnion +// Name implements genericSimpleUnion func (mmName *GenericSimpleUnionMock[T]) Name(t1 T) { mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1) diff --git a/tests/generic/generic_specific.go b/tests/generic_specific.go similarity index 96% rename from tests/generic/generic_specific.go rename to tests/generic_specific.go index e476e68..e833040 100644 --- a/tests/generic/generic_specific.go +++ b/tests/generic_specific.go @@ -1,8 +1,8 @@ -package generic +package tests // Code generated by http://github.com/gojuno/minimock (dev). DO NOT EDIT. -//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericSpecific -o ./tests/generic/generic_specific.go -n GenericSpecificMock +//go:generate minimock -i github.com/gojuno/minimock/v3/tests.genericSpecific -o ./tests/generic_specific.go -n GenericSpecificMock import ( "sync" @@ -13,7 +13,7 @@ import ( "google.golang.org/protobuf/proto" ) -// GenericSpecificMock implements tests.genericSpecific +// GenericSpecificMock implements genericSpecific type GenericSpecificMock[T proto.Message] struct { t minimock.Tester @@ -24,7 +24,7 @@ type GenericSpecificMock[T proto.Message] struct { NameMock mGenericSpecificMockName[T] } -// NewGenericSpecificMock returns a mock for tests.genericSpecific +// NewGenericSpecificMock returns a mock for genericSpecific func NewGenericSpecificMock[T proto.Message](t minimock.Tester) *GenericSpecificMock[T] { m := &GenericSpecificMock[T]{t: t} if controller, ok := t.(minimock.MockController); ok { @@ -117,7 +117,7 @@ func (mmName *mGenericSpecificMockName[T]) Set(f func(t1 T)) *GenericSpecificMoc return mmName.mock } -// Name implements tests.genericSpecific +// Name implements genericSpecific func (mmName *GenericSpecificMock[T]) Name(t1 T) { mm_atomic.AddUint64(&mmName.beforeNameCounter, 1) defer mm_atomic.AddUint64(&mmName.afterNameCounter, 1)