From 9153bd984b6e2cf09a1d801dc151e788c701c00d Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Tue, 7 Mar 2017 12:56:15 +0000 Subject: [PATCH] Fixes #12 --- package/moq/moq.go | 4 ++++ package/moq/moq_test.go | 25 +++++++++++++++++++++++++ package/moq/testdata/example/example.go | 1 + 3 files changed, 30 insertions(+) diff --git a/package/moq/moq.go b/package/moq/moq.go index b29bd8d..6ce174d 100644 --- a/package/moq/moq.go +++ b/package/moq/moq.go @@ -235,7 +235,11 @@ func (mock *{{$obj.InterfaceName}}Mock) {{.Name}}({{.Arglist}}) {{.ReturnArglist if mock.{{.Name}}Func == nil { panic("moq: {{$obj.InterfaceName}}Mock.{{.Name}}Func is nil but was just called") } + {{ if .ReturnArglist }} return mock.{{.Name}}Func({{.ArgCallList}}) + {{ else }} + mock.{{.Name}}Func({{.ArgCallList}}) + {{ end }} } {{ end -}} {{ end -}}` diff --git a/package/moq/moq_test.go b/package/moq/moq_test.go index b4dbf68..cd7ae02 100644 --- a/package/moq/moq_test.go +++ b/package/moq/moq_test.go @@ -89,3 +89,28 @@ func TestVariadicArguments(t *testing.T) { } } } + +func TestNothingToReturn(t *testing.T) { + m, err := New("testdata/example", "") + if err != nil { + t.Errorf("moq.New: %s", err) + } + var buf bytes.Buffer + err = m.Mock(&buf, "PersonStore") + if err != nil { + t.Errorf("m.Mock: %s", err) + } + s := buf.String() + if strings.Contains(s, `return mock.ClearCacheFunc(id)`) { + t.Errorf("should not have return for items that have no return arguments") + } + // assertions of things that should be mentioned + var strs = []string{ + "mock.ClearCacheFunc(id)", + } + for _, str := range strs { + if !strings.Contains(s, str) { + t.Errorf("expected but missing: \"%s\"", str) + } + } +} diff --git a/package/moq/testdata/example/example.go b/package/moq/testdata/example/example.go index 3adcbb8..c7a19d7 100644 --- a/package/moq/testdata/example/example.go +++ b/package/moq/testdata/example/example.go @@ -12,4 +12,5 @@ type Person struct { type PersonStore interface { Get(ctx context.Context, id string) (*Person, error) Create(ctx context.Context, person *Person, confirm bool) error + ClearCache(id string) }