From feae1301cfd68ab0c1c0b3f1538cbc576aa9b463 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Fri, 7 Jul 2017 20:00:46 +0100 Subject: [PATCH 1/2] Removed confusing Enabled field --- package/moq/moq.go | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/package/moq/moq.go b/package/moq/moq.go index be3af3d..c94d275 100644 --- a/package/moq/moq.go +++ b/package/moq/moq.go @@ -264,12 +264,7 @@ type {{.InterfaceName}}Mock struct { {{.Name}}Func func({{ .Arglist }}) {{.ReturnArglist}} {{ end }} // CallsTo tracks calls to the methods. - CallsTo struct { - // Enabled indicates that calls will be tracked. - // - // // don't track calls - // {{.InterfaceName}}Mock.CallsTo.Enabled = false - Enabled bool + CallsTo struct { {{ range .Methods }} lock{{.Name}} sync.Mutex // protects {{ .Name }} // {{ .Name }} holds details about calls to the {{.Name}} method. @@ -288,19 +283,17 @@ 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 mock.CallsTo.Enabled { - mock.CallsTo.lock{{.Name}}.Lock() - mock.CallsTo.{{.Name}} = append(mock.CallsTo.{{.Name}}, struct{ - {{- range .Params }} - {{ .Name | Exported }} {{ .Type }} - {{- end }} - }{ - {{- range .Params }} - {{ .Name | Exported }}: {{ .Name }}, - {{- end }} - }) - mock.CallsTo.lock{{.Name}}.Unlock() - } + mock.CallsTo.lock{{.Name}}.Lock() + mock.CallsTo.{{.Name}} = append(mock.CallsTo.{{.Name}}, struct{ + {{- range .Params }} + {{ .Name | Exported }} {{ .Type }} + {{- end }} + }{ + {{- range .Params }} + {{ .Name | Exported }}: {{ .Name }}, + {{- end }} + }) + mock.CallsTo.lock{{.Name}}.Unlock() {{- if .ReturnArglist }} return mock.{{.Name}}Func({{.ArgCallList}}) {{- else }} From 50ce4e36c7d77f5af3b89e25f82ee114cb560895 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Fri, 7 Jul 2017 20:04:25 +0100 Subject: [PATCH 2/2] Improved generated code --- package/moq/moq.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/moq/moq.go b/package/moq/moq.go index c94d275..c2339ce 100644 --- a/package/moq/moq.go +++ b/package/moq/moq.go @@ -265,7 +265,7 @@ type {{.InterfaceName}}Mock struct { {{ end }} // CallsTo tracks calls to the methods. CallsTo struct { -{{ range .Methods }} +{{- range .Methods }} lock{{.Name}} sync.Mutex // protects {{ .Name }} // {{ .Name }} holds details about calls to the {{.Name}} method. {{ .Name }} []struct {