Skip to content

Commit

Permalink
FailNow removed from template + tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sleygin committed Jun 3, 2024
1 parent f044740 commit 5c94bfc
Show file tree
Hide file tree
Showing 21 changed files with 606 additions and 56 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ all: install test lint
generate:
go run ./cmd/minimock/minimock.go -i github.com/gojuno/minimock/v3.Tester -o ./tests
go run ./cmd/minimock/minimock.go -i ./tests.Formatter -o ./tests/formatter_mock.go
go run ./cmd/minimock/minimock.go -i ./tests.Formatter -o ./tests/formatter_with_custom_name_mock.go -n CustomFormatterNameMock
go run ./cmd/minimock/minimock.go -i ./tests.genericInout -o ./tests/generic_inout.go
go run ./cmd/minimock/minimock.go -i ./tests.genericOut -o ./tests/generic_out.go
go run ./cmd/minimock/minimock.go -i ./tests.genericIn -o ./tests/generic_in.go
Expand Down
3 changes: 1 addition & 2 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const (
// Marks this method to be optional. The default behavior of any method with Return() is '1 or more', meaning
// the test will fail minimock's automatic final call check if the mocked method was not called at least once.
// Optional() makes method check to work in '0 or more' mode.
// It is NOT RECOMMENDED to use this option by default unless you really need it, as it helps to
// It is NOT RECOMMENDED to use this option unless you really need it, as default behaviour helps to
// catch the problems when the expected method call is totally skipped during test run.
func ({{$m}} *m{{$mock}}{{$method.Name}}{{(paramsRef)}}) Optional() *m{{$mock}}{{$method.Name}}{{(paramsRef)}} {
{{$m}}.optional = true
Expand Down Expand Up @@ -386,7 +386,6 @@ const (
{{- range $method := $.Interface.Methods }}
m.Minimock{{$method.Name}}Inspect()
{{ end -}}
m.t.FailNow()
}
})
}
Expand Down
17 changes: 16 additions & 1 deletion tests/actor_mock.go

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

9 changes: 9 additions & 0 deletions tests/actor_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,12 @@ func TestActorMock_FailedToUseExpectParamsAfterSet(t *testing.T) {
return
}).ActionMock.ExpectFirstParamParam1("abc").Return(1, nil)
}

func TestActorMock_Optional(t *testing.T) {
tester := NewTesterMock(t)
tester.CleanupMock.Return()

mock := NewActorMock(tester).ActionMock.Optional().Return(1, nil)

mock.MinimockFinish()
}
49 changes: 48 additions & 1 deletion tests/context_accepter_mock.go

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

6 changes: 2 additions & 4 deletions tests/context_accepter_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ func TestContextAccepterMock_TimesFailure(t *testing.T) {
tester := NewTesterMock(t)
tester.CleanupMock.Return().
ErrorfMock.Expect("Expected %d calls to ContextAccepterMock.AcceptContextWithStructArgs but found %d calls", uint64(1), uint64(2)).
Return().
FailNowMock.Return()
Return()

// Expected 1 calls to ContextAccepterMock.AcceptContextWithStructArgs but found 2 calls
mock := NewContextAccepterMock(tester).
Expand Down Expand Up @@ -183,8 +182,7 @@ func TestContextAccepterMock_ExpectedCall(t *testing.T) {
tester := NewTesterMock(t)
tester.CleanupMock.Times(1).Return().
ErrorMock.Expect("Expected call to ContextAccepterMock.AcceptContext").Times(1).
Return().
FailNowMock.Times(1).Return()
Return()

mock := NewContextAccepterMock(tester).AcceptContextMock.Return()

Expand Down
17 changes: 16 additions & 1 deletion tests/formatter_mock.go

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

5 changes: 0 additions & 5 deletions tests/formatter_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestFormatterMock_CleanupIsCalled(t *testing.T) {
tester := NewTesterMock(t)
tester.CleanupMock.Set(t.Cleanup)
tester.ErrorMock.Expect("Expected call to FormatterMock.Format").Return()
tester.FailNowMock.Return()

NewFormatterMock(tester).FormatMock.Return("")
}
Expand Down Expand Up @@ -154,7 +153,6 @@ func TestFormatterMock_ReturnWithoutExpectForFixedArgsMethod(t *testing.T) {
tester := NewTesterMock(t).CleanupMock.Return()

tester.ErrorMock.Expect("Expected call to FormatterMock.Format")
tester.FailNowMock.Expect()

formatterMock := NewFormatterMock(tester)
formatterMock.FormatMock.Return("")
Expand Down Expand Up @@ -232,7 +230,6 @@ func TestFormatterMock_MinimockFinish(t *testing.T) {
tester := NewTesterMock(t).CleanupMock.Return()

tester.ErrorMock.Expect("Expected call to FormatterMock.Format").Return()
tester.FailNowMock.Expect().Return()

formatterMock := NewFormatterMock(tester)
formatterMock.FormatMock.Set(func(string, ...interface{}) string { return "" })
Expand All @@ -246,7 +243,6 @@ func TestFormatterMock_MinimockFinish_WithNoMetExpectations(t *testing.T) {
tester.ErrorfMock.Set(func(m string, args ...interface{}) {
assert.Equal(t, m, "Expected call to FormatterMock.Format with params: %#v")
})
tester.FailNowMock.Expect().Return()

formatterMock := NewFormatterMock(tester)
formatterMock.FormatMock.Expect("a").Return("a")
Expand All @@ -259,7 +255,6 @@ func TestFormatterMock_MinimockWait(t *testing.T) {
tester := NewTesterMock(t).CleanupMock.Return()

tester.ErrorMock.Expect("Expected call to FormatterMock.Format").Return()
tester.FailNowMock.Expect().Return()

formatterMock := NewFormatterMock(tester)
formatterMock.FormatMock.Set(func(string, ...interface{}) string { return "" })
Expand Down
Loading

0 comments on commit 5c94bfc

Please sign in to comment.