Skip to content

Commit

Permalink
Merge pull request #15 from percolate/improve-nil-hook-panic-message
Browse files Browse the repository at this point in the history
Improve Error Message for nil Hook
  • Loading branch information
kevinbirch authored Mar 24, 2018
2 parents afaee97 + 1c2778d commit f9a2363
Show file tree
Hide file tree
Showing 16 changed files with 129 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.0.2
4 changes: 4 additions & 0 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func (f *Fake{{.Name}}) Reset() {
{{range $m := .Methods}}
{{with $f := gensym}}func ({{$f}} *Fake{{$m.Interface}}) {{$m.Name}}({{$m.ParametersDeclaration}}) ({{$m.ResultsDeclaration}}) {
if {{$f}}.{{$m.Name}}Hook == nil {
panic("{{$m.Interface}}.{{$m.Name}}() called but Fake{{$m.Interface}}.{{$m.Name}}Hook is nil")
}
invocation := new({{$m.Interface}}{{$m.Name}}Invocation)
{{$f}}.{{$m.Name}}Calls = append({{$f}}.{{$m.Name}}Calls, invocation)
Expand Down
16 changes: 16 additions & 0 deletions testdata/array/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ func (f *FakeArray) Reset() {
}

func (_f1 *FakeArray) ArrayParameter(ident1 [3]string) {
if _f1.ArrayParameterHook == nil {
panic("Array.ArrayParameter() called but FakeArray.ArrayParameterHook is nil")
}

invocation := new(ArrayArrayParameterInvocation)
_f1.ArrayParameterCalls = append(_f1.ArrayParameterCalls, invocation)

Expand Down Expand Up @@ -264,6 +268,10 @@ func (_f5 *FakeArray) AssertArrayParameterCalledOnceWith(t ArrayTestingT, ident1
}

func (_f6 *FakeArray) ArrayReturn() (ident1 [3]string) {
if _f6.ArrayReturnHook == nil {
panic("Array.ArrayReturn() called but FakeArray.ArrayReturnHook is nil")
}

invocation := new(ArrayArrayReturnInvocation)
_f6.ArrayReturnCalls = append(_f6.ArrayReturnCalls, invocation)

Expand Down Expand Up @@ -327,6 +335,10 @@ func (f *FakeArray) AssertArrayReturnCalledN(t ArrayTestingT, n int) {
}

func (_f7 *FakeArray) SliceParameter(ident1 []string) {
if _f7.SliceParameterHook == nil {
panic("Array.SliceParameter() called but FakeArray.SliceParameterHook is nil")
}

invocation := new(ArraySliceParameterInvocation)
_f7.SliceParameterCalls = append(_f7.SliceParameterCalls, invocation)

Expand Down Expand Up @@ -445,6 +457,10 @@ func (_f11 *FakeArray) AssertSliceParameterCalledOnceWith(t ArrayTestingT, ident
}

func (_f12 *FakeArray) SliceReturn() (ident1 []string) {
if _f12.SliceReturnHook == nil {
panic("Array.SliceReturn() called but FakeArray.SliceReturnHook is nil")
}

invocation := new(ArraySliceReturnInvocation)
_f12.SliceReturnCalls = append(_f12.SliceReturnCalls, invocation)

Expand Down
20 changes: 20 additions & 0 deletions testdata/channeler/channeler.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ func (f *FakeChanneler) Reset() {
}

func (_f1 *FakeChanneler) Channel(ident1 chan int) (ident2 chan int) {
if _f1.ChannelHook == nil {
panic("Channeler.Channel() called but FakeChanneler.ChannelHook is nil")
}

invocation := new(ChannelerChannelInvocation)
_f1.ChannelCalls = append(_f1.ChannelCalls, invocation)

Expand Down Expand Up @@ -315,6 +319,10 @@ func (_f6 *FakeChanneler) ChannelResultsForCall(ident1 chan int) (ident2 chan in
}

func (_f7 *FakeChanneler) ChannelReceive(ident1 <-chan int) (ident2 <-chan int) {
if _f7.ChannelReceiveHook == nil {
panic("Channeler.ChannelReceive() called but FakeChanneler.ChannelReceiveHook is nil")
}

invocation := new(ChannelerChannelReceiveInvocation)
_f7.ChannelReceiveCalls = append(_f7.ChannelReceiveCalls, invocation)

Expand Down Expand Up @@ -448,6 +456,10 @@ func (_f12 *FakeChanneler) ChannelReceiveResultsForCall(ident1 <-chan int) (iden
}

func (_f13 *FakeChanneler) ChannelSend(ident1 chan<- int) (ident2 chan<- int) {
if _f13.ChannelSendHook == nil {
panic("Channeler.ChannelSend() called but FakeChanneler.ChannelSendHook is nil")
}

invocation := new(ChannelerChannelSendInvocation)
_f13.ChannelSendCalls = append(_f13.ChannelSendCalls, invocation)

Expand Down Expand Up @@ -581,6 +593,10 @@ func (_f18 *FakeChanneler) ChannelSendResultsForCall(ident1 chan<- int) (ident2
}

func (_f19 *FakeChanneler) ChannelPointer(ident1 *chan int) (ident2 *chan int) {
if _f19.ChannelPointerHook == nil {
panic("Channeler.ChannelPointer() called but FakeChanneler.ChannelPointerHook is nil")
}

invocation := new(ChannelerChannelPointerInvocation)
_f19.ChannelPointerCalls = append(_f19.ChannelPointerCalls, invocation)

Expand Down Expand Up @@ -714,6 +730,10 @@ func (_f24 *FakeChanneler) ChannelPointerResultsForCall(ident1 *chan int) (ident
}

func (_f25 *FakeChanneler) ChannelInterface(ident1 chan interface{}) (ident2 chan interface{}) {
if _f25.ChannelInterfaceHook == nil {
panic("Channeler.ChannelInterface() called but FakeChanneler.ChannelInterfaceHook is nil")
}

invocation := new(ChannelerChannelInterfaceInvocation)
_f25.ChannelInterfaceCalls = append(_f25.ChannelInterfaceCalls, invocation)

Expand Down
12 changes: 12 additions & 0 deletions testdata/embedder/embedder.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func (f *FakeEmbedder) Reset() {
}

func (_f1 *FakeEmbedder) String() (ident5 string) {
if _f1.StringHook == nil {
panic("Embedder.String() called but FakeEmbedder.StringHook is nil")
}

invocation := new(EmbedderStringInvocation)
_f1.StringCalls = append(_f1.StringCalls, invocation)

Expand Down Expand Up @@ -194,6 +198,10 @@ func (f *FakeEmbedder) AssertStringCalledN(t EmbedderTestingT, n int) {
}

func (_f2 *FakeEmbedder) Embed(ident1 string) (ident2 string) {
if _f2.EmbedHook == nil {
panic("Embedder.Embed() called but FakeEmbedder.EmbedHook is nil")
}

invocation := new(EmbedderEmbedInvocation)
_f2.EmbedCalls = append(_f2.EmbedCalls, invocation)

Expand Down Expand Up @@ -327,6 +335,10 @@ func (_f7 *FakeEmbedder) EmbedResultsForCall(ident1 string) (ident2 string, foun
}

func (_f8 *FakeEmbedder) Other(ident1 string) (ident2 string) {
if _f8.OtherHook == nil {
panic("Embedder.Other() called but FakeEmbedder.OtherHook is nil")
}

invocation := new(EmbedderOtherInvocation)
_f8.OtherCalls = append(_f8.OtherCalls, invocation)

Expand Down
8 changes: 8 additions & 0 deletions testdata/funcer/funcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func (f *FakeFuncer) Reset() {
}

func (_f1 *FakeFuncer) FuncParameter(ident1 func(string) string) {
if _f1.FuncParameterHook == nil {
panic("Funcer.FuncParameter() called but FakeFuncer.FuncParameterHook is nil")
}

invocation := new(FuncerFuncParameterInvocation)
_f1.FuncParameterCalls = append(_f1.FuncParameterCalls, invocation)

Expand Down Expand Up @@ -222,6 +226,10 @@ func (_f5 *FakeFuncer) AssertFuncParameterCalledOnceWith(t FuncerTestingT, ident
}

func (_f6 *FakeFuncer) FuncReturn() (ident1 func(string) string) {
if _f6.FuncReturnHook == nil {
panic("Funcer.FuncReturn() called but FakeFuncer.FuncReturnHook is nil")
}

invocation := new(FuncerFuncReturnInvocation)
_f6.FuncReturnCalls = append(_f6.FuncReturnCalls, invocation)

Expand Down
4 changes: 4 additions & 0 deletions testdata/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func (f *FakeImporter) Reset() {
}

func (_f1 *FakeImporter) Scan(ident1 *Scanner) (ident2 z.Reader) {
if _f1.ScanHook == nil {
panic("Importer.Scan() called but FakeImporter.ScanHook is nil")
}

invocation := new(ImporterScanInvocation)
_f1.ScanCalls = append(_f1.ScanCalls, invocation)

Expand Down
8 changes: 8 additions & 0 deletions testdata/interfacer/interfacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func (f *FakeInterfacer) Reset() {
}

func (_f1 *FakeInterfacer) Interface(ident1 interface{}) (ident2 interface{}) {
if _f1.InterfaceHook == nil {
panic("Interfacer.Interface() called but FakeInterfacer.InterfaceHook is nil")
}

invocation := new(InterfacerInterfaceInvocation)
_f1.InterfaceCalls = append(_f1.InterfaceCalls, invocation)

Expand Down Expand Up @@ -243,6 +247,10 @@ func (_f6 *FakeInterfacer) InterfaceResultsForCall(ident1 interface{}) (ident2 i
}

func (_f7 *FakeInterfacer) NamedInterface(a interface{}) (z interface{}) {
if _f7.NamedInterfaceHook == nil {
panic("Interfacer.NamedInterface() called but FakeInterfacer.NamedInterfaceHook is nil")
}

invocation := new(InterfacerNamedInterfaceInvocation)
_f7.NamedInterfaceCalls = append(_f7.NamedInterfaceCalls, invocation)

Expand Down
8 changes: 8 additions & 0 deletions testdata/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func (f *FakeMapper) Reset() {
}

func (_f1 *FakeMapper) MapParameter(ident1 map[string]string) {
if _f1.MapParameterHook == nil {
panic("Mapper.MapParameter() called but FakeMapper.MapParameterHook is nil")
}

invocation := new(MapperMapParameterInvocation)
_f1.MapParameterCalls = append(_f1.MapParameterCalls, invocation)

Expand Down Expand Up @@ -222,6 +226,10 @@ func (_f5 *FakeMapper) AssertMapParameterCalledOnceWith(t MapperTestingT, ident1
}

func (_f6 *FakeMapper) MapReturn() (ident1 map[string]string) {
if _f6.MapReturnHook == nil {
panic("Mapper.MapReturn() called but FakeMapper.MapReturnHook is nil")
}

invocation := new(MapperMapReturnInvocation)
_f6.MapReturnCalls = append(_f6.MapReturnCalls, invocation)

Expand Down
8 changes: 8 additions & 0 deletions testdata/multireturner/multireturner.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func (f *FakeMultireturner) Reset() {
}

func (_f1 *FakeMultireturner) MultiReturn() (ident1 string, ident2 int) {
if _f1.MultiReturnHook == nil {
panic("Multireturner.MultiReturn() called but FakeMultireturner.MultiReturnHook is nil")
}

invocation := new(MultireturnerMultiReturnInvocation)
_f1.MultiReturnCalls = append(_f1.MultiReturnCalls, invocation)

Expand Down Expand Up @@ -170,6 +174,10 @@ func (f *FakeMultireturner) AssertMultiReturnCalledN(t MultireturnerTestingT, n
}

func (_f2 *FakeMultireturner) NamedReturn() (a int, b int, c int, d int) {
if _f2.NamedReturnHook == nil {
panic("Multireturner.NamedReturn() called but FakeMultireturner.NamedReturnHook is nil")
}

invocation := new(MultireturnerNamedReturnInvocation)
_f2.NamedReturnCalls = append(_f2.NamedReturnCalls, invocation)

Expand Down
8 changes: 8 additions & 0 deletions testdata/namedvaluer/namedvaluer.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func (f *FakeNamedvaluer) Reset() {
}

func (_f1 *FakeNamedvaluer) ManyNamed(a string, b string, f int, g int) (ret bool) {
if _f1.ManyNamedHook == nil {
panic("Namedvaluer.ManyNamed() called but FakeNamedvaluer.ManyNamedHook is nil")
}

invocation := new(NamedvaluerManyNamedInvocation)
_f1.ManyNamedCalls = append(_f1.ManyNamedCalls, invocation)

Expand Down Expand Up @@ -250,6 +254,10 @@ func (_f6 *FakeNamedvaluer) ManyNamedResultsForCall(a string, b string, f int, g
}

func (_f7 *FakeNamedvaluer) Named(a int, b string) (ret bool) {
if _f7.NamedHook == nil {
panic("Namedvaluer.Named() called but FakeNamedvaluer.NamedHook is nil")
}

invocation := new(NamedvaluerNamedInvocation)
_f7.NamedCalls = append(_f7.NamedCalls, invocation)

Expand Down
4 changes: 4 additions & 0 deletions testdata/pointer/pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (f *FakePointer) Reset() {
}

func (_f1 *FakePointer) Point(ident1 *string) (ident2 int) {
if _f1.PointHook == nil {
panic("Pointer.Point() called but FakePointer.PointHook is nil")
}

invocation := new(PointerPointInvocation)
_f1.PointCalls = append(_f1.PointCalls, invocation)

Expand Down
8 changes: 8 additions & 0 deletions testdata/qualifier/qualifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func (f *FakeQualifier) Reset() {
}

func (_f1 *FakeQualifier) Qualify(ident1 fmt.Scanner) (ident2 fmt.Scanner) {
if _f1.QualifyHook == nil {
panic("Qualifier.Qualify() called but FakeQualifier.QualifyHook is nil")
}

invocation := new(QualifierQualifyInvocation)
_f1.QualifyCalls = append(_f1.QualifyCalls, invocation)

Expand Down Expand Up @@ -246,6 +250,10 @@ func (_f6 *FakeQualifier) QualifyResultsForCall(ident1 fmt.Scanner) (ident2 fmt.
}

func (_f7 *FakeQualifier) NamedQualify(a fmt.Scanner, b fmt.Scanner, c fmt.Scanner) (d fmt.Scanner) {
if _f7.NamedQualifyHook == nil {
panic("Qualifier.NamedQualify() called but FakeQualifier.NamedQualifyHook is nil")
}

invocation := new(QualifierNamedQualifyInvocation)
_f7.NamedQualifyCalls = append(_f7.NamedQualifyCalls, invocation)

Expand Down
8 changes: 8 additions & 0 deletions testdata/structer/structer.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ func (_f1 *FakeStructer) Struct(ident1 struct {
c string
d string
}) {
if _f1.StructHook == nil {
panic("Structer.Struct() called but FakeStructer.StructHook is nil")
}

invocation := new(StructerStructInvocation)
_f1.StructCalls = append(_f1.StructCalls, invocation)

Expand Down Expand Up @@ -339,6 +343,10 @@ func (_f7 *FakeStructer) NamedStruct(a struct {
c string
d string
}) {
if _f7.NamedStructHook == nil {
panic("Structer.NamedStruct() called but FakeStructer.NamedStructHook is nil")
}

invocation := new(StructerNamedStructInvocation)
_f7.NamedStructCalls = append(_f7.NamedStructCalls, invocation)

Expand Down
8 changes: 8 additions & 0 deletions testdata/variadic/variadic.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func (f *FakeVariadic) Reset() {
}

func (_f1 *FakeVariadic) SingleVariadic(a ...string) {
if _f1.SingleVariadicHook == nil {
panic("Variadic.SingleVariadic() called but FakeVariadic.SingleVariadicHook is nil")
}

invocation := new(VariadicSingleVariadicInvocation)
_f1.SingleVariadicCalls = append(_f1.SingleVariadicCalls, invocation)

Expand Down Expand Up @@ -225,6 +229,10 @@ func (_f5 *FakeVariadic) AssertSingleVariadicCalledOnceWith(t VariadicTestingT,
}

func (_f6 *FakeVariadic) MixedVariadic(a int, b int, c int, d ...string) {
if _f6.MixedVariadicHook == nil {
panic("Variadic.MixedVariadic() called but FakeVariadic.MixedVariadicHook is nil")
}

invocation := new(VariadicMixedVariadicInvocation)
_f6.MixedVariadicCalls = append(_f6.MixedVariadicCalls, invocation)

Expand Down
4 changes: 4 additions & 0 deletions testdata/voider/voider.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (f *FakeVoider) Reset() {
}

func (_f1 *FakeVoider) VoidMethod() {
if _f1.VoidMethodHook == nil {
panic("Voider.VoidMethod() called but FakeVoider.VoidMethodHook is nil")
}

invocation := new(VoiderVoidMethodInvocation)
_f1.VoidMethodCalls = append(_f1.VoidMethodCalls, invocation)

Expand Down

0 comments on commit f9a2363

Please sign in to comment.