Add noop formatter as an option (#133)

Useful to print the generated source code for debugging.
This commit is contained in:
Suhas Karanth
2020-08-16 12:55:01 +05:30
committed by GitHub
parent e3d1bd8a7e
commit 005b899ec8
8 changed files with 154 additions and 28 deletions

View File

@@ -0,0 +1,117 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package two
import (
"github.com/matryer/moq/pkg/moq/testpackages/imports/one"
"sync"
)
// Ensure, that gofmtMock does implement DoSomething.
// If this is not the case, regenerate this file with moq.
var _ DoSomething = &gofmtMock{}
// gofmtMock is a mock implementation of DoSomething.
//
// func TestSomethingThatUsesDoSomething(t *testing.T) {
//
// // make and configure a mocked DoSomething
// mockedDoSomething := &gofmtMock{
// AnotherFunc: func(thing one.Thing) error {
// panic("mock out the Another method")
// },
// DoFunc: func(thing one.Thing) error {
// panic("mock out the Do method")
// },
// }
//
// // use mockedDoSomething in code that requires DoSomething
// // and then make assertions.
//
// }
type gofmtMock struct {
// AnotherFunc mocks the Another method.
AnotherFunc func(thing one.Thing) error
// DoFunc mocks the Do method.
DoFunc func(thing one.Thing) error
// calls tracks calls to the methods.
calls struct {
// Another holds details about calls to the Another method.
Another []struct {
// Thing is the thing argument value.
Thing one.Thing
}
// Do holds details about calls to the Do method.
Do []struct {
// Thing is the thing argument value.
Thing one.Thing
}
}
lockAnother sync.RWMutex
lockDo sync.RWMutex
}
// Another calls AnotherFunc.
func (mock *gofmtMock) Another(thing one.Thing) error {
if mock.AnotherFunc == nil {
panic("gofmtMock.AnotherFunc: method is nil but DoSomething.Another was just called")
}
callInfo := struct {
Thing one.Thing
}{
Thing: thing,
}
mock.lockAnother.Lock()
mock.calls.Another = append(mock.calls.Another, callInfo)
mock.lockAnother.Unlock()
return mock.AnotherFunc(thing)
}
// AnotherCalls gets all the calls that were made to Another.
// Check the length with:
// len(mockedDoSomething.AnotherCalls())
func (mock *gofmtMock) AnotherCalls() []struct {
Thing one.Thing
} {
var calls []struct {
Thing one.Thing
}
mock.lockAnother.RLock()
calls = mock.calls.Another
mock.lockAnother.RUnlock()
return calls
}
// Do calls DoFunc.
func (mock *gofmtMock) Do(thing one.Thing) error {
if mock.DoFunc == nil {
panic("gofmtMock.DoFunc: method is nil but DoSomething.Do was just called")
}
callInfo := struct {
Thing one.Thing
}{
Thing: thing,
}
mock.lockDo.Lock()
mock.calls.Do = append(mock.calls.Do, callInfo)
mock.lockDo.Unlock()
return mock.DoFunc(thing)
}
// DoCalls gets all the calls that were made to Do.
// Check the length with:
// len(mockedDoSomething.DoCalls())
func (mock *gofmtMock) DoCalls() []struct {
Thing one.Thing
} {
var calls []struct {
Thing one.Thing
}
mock.lockDo.RLock()
calls = mock.calls.Do
mock.lockDo.RUnlock()
return calls
}

View File

@@ -0,0 +1,118 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package two
import (
"sync"
"github.com/matryer/moq/pkg/moq/testpackages/imports/one"
)
// Ensure, that goimportsMock does implement DoSomething.
// If this is not the case, regenerate this file with moq.
var _ DoSomething = &goimportsMock{}
// goimportsMock is a mock implementation of DoSomething.
//
// func TestSomethingThatUsesDoSomething(t *testing.T) {
//
// // make and configure a mocked DoSomething
// mockedDoSomething := &goimportsMock{
// AnotherFunc: func(thing one.Thing) error {
// panic("mock out the Another method")
// },
// DoFunc: func(thing one.Thing) error {
// panic("mock out the Do method")
// },
// }
//
// // use mockedDoSomething in code that requires DoSomething
// // and then make assertions.
//
// }
type goimportsMock struct {
// AnotherFunc mocks the Another method.
AnotherFunc func(thing one.Thing) error
// DoFunc mocks the Do method.
DoFunc func(thing one.Thing) error
// calls tracks calls to the methods.
calls struct {
// Another holds details about calls to the Another method.
Another []struct {
// Thing is the thing argument value.
Thing one.Thing
}
// Do holds details about calls to the Do method.
Do []struct {
// Thing is the thing argument value.
Thing one.Thing
}
}
lockAnother sync.RWMutex
lockDo sync.RWMutex
}
// Another calls AnotherFunc.
func (mock *goimportsMock) Another(thing one.Thing) error {
if mock.AnotherFunc == nil {
panic("goimportsMock.AnotherFunc: method is nil but DoSomething.Another was just called")
}
callInfo := struct {
Thing one.Thing
}{
Thing: thing,
}
mock.lockAnother.Lock()
mock.calls.Another = append(mock.calls.Another, callInfo)
mock.lockAnother.Unlock()
return mock.AnotherFunc(thing)
}
// AnotherCalls gets all the calls that were made to Another.
// Check the length with:
// len(mockedDoSomething.AnotherCalls())
func (mock *goimportsMock) AnotherCalls() []struct {
Thing one.Thing
} {
var calls []struct {
Thing one.Thing
}
mock.lockAnother.RLock()
calls = mock.calls.Another
mock.lockAnother.RUnlock()
return calls
}
// Do calls DoFunc.
func (mock *goimportsMock) Do(thing one.Thing) error {
if mock.DoFunc == nil {
panic("goimportsMock.DoFunc: method is nil but DoSomething.Do was just called")
}
callInfo := struct {
Thing one.Thing
}{
Thing: thing,
}
mock.lockDo.Lock()
mock.calls.Do = append(mock.calls.Do, callInfo)
mock.lockDo.Unlock()
return mock.DoFunc(thing)
}
// DoCalls gets all the calls that were made to Do.
// Check the length with:
// len(mockedDoSomething.DoCalls())
func (mock *goimportsMock) DoCalls() []struct {
Thing one.Thing
} {
var calls []struct {
Thing one.Thing
}
mock.lockDo.RLock()
calls = mock.calls.Do
mock.lockDo.RUnlock()
return calls
}

View File

@@ -0,0 +1,117 @@
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package two
import (
"sync"
"github.com/matryer/moq/pkg/moq/testpackages/imports/one"
)
// Ensure, that noopMock does implement DoSomething.
// If this is not the case, regenerate this file with moq.
var _ DoSomething = &noopMock{}
// noopMock is a mock implementation of DoSomething.
//
// func TestSomethingThatUsesDoSomething(t *testing.T) {
//
// // make and configure a mocked DoSomething
// mockedDoSomething := &noopMock{
// AnotherFunc: func(thing one.Thing) error {
// panic("mock out the Another method")
// },
// DoFunc: func(thing one.Thing) error {
// panic("mock out the Do method")
// },
// }
//
// // use mockedDoSomething in code that requires DoSomething
// // and then make assertions.
//
// }
type noopMock struct {
// AnotherFunc mocks the Another method.
AnotherFunc func(thing one.Thing) error
// DoFunc mocks the Do method.
DoFunc func(thing one.Thing) error
// calls tracks calls to the methods.
calls struct {
// Another holds details about calls to the Another method.
Another []struct {
// Thing is the thing argument value.
Thing one.Thing
}
// Do holds details about calls to the Do method.
Do []struct {
// Thing is the thing argument value.
Thing one.Thing
}
}
lockAnother sync.RWMutex
lockDo sync.RWMutex
}
// Another calls AnotherFunc.
func (mock *noopMock) Another(thing one.Thing) error {
if mock.AnotherFunc == nil {
panic("noopMock.AnotherFunc: method is nil but DoSomething.Another was just called")
}
callInfo := struct {
Thing one.Thing
}{
Thing: thing,
}
mock.lockAnother.Lock()
mock.calls.Another = append(mock.calls.Another, callInfo)
mock.lockAnother.Unlock()
return mock.AnotherFunc(thing)
}
// AnotherCalls gets all the calls that were made to Another.
// Check the length with:
// len(mockedDoSomething.AnotherCalls())
func (mock *noopMock) AnotherCalls() []struct {
Thing one.Thing
} {
var calls []struct {
Thing one.Thing
}
mock.lockAnother.RLock()
calls = mock.calls.Another
mock.lockAnother.RUnlock()
return calls
}
// Do calls DoFunc.
func (mock *noopMock) Do(thing one.Thing) error {
if mock.DoFunc == nil {
panic("noopMock.DoFunc: method is nil but DoSomething.Do was just called")
}
callInfo := struct {
Thing one.Thing
}{
Thing: thing,
}
mock.lockDo.Lock()
mock.calls.Do = append(mock.calls.Do, callInfo)
mock.lockDo.Unlock()
return mock.DoFunc(thing)
}
// DoCalls gets all the calls that were made to Do.
// Check the length with:
// len(mockedDoSomething.DoCalls())
func (mock *noopMock) DoCalls() []struct {
Thing one.Thing
} {
var calls []struct {
Thing one.Thing
}
mock.lockDo.RLock()
calls = mock.calls.Do
mock.lockDo.RUnlock()
return calls
}