petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
253 stars 28 forks source link

mock.VerifyWasCalled(Never()) does not work with Matchers #34

Closed berupp closed 7 years ago

berupp commented 7 years ago

Hi, When I try to verify that a method was never called, I can not use matchers

 runtime error: invalid memory address or nil pointer dereference

        /usr/local/go/src/runtime/panic.go:426 +0x4e9
  github.com/petergtz/pegomock.(*GenericMock).methodInvocationsUsingMatchers(0xc8200820a8, 0x473c48, 0x3, 0xc820073930, 0x1, 0x1, 0x0, 0x0, 0x0)
        /localdisk/gowork/src/github.com/petergtz/pegomock/dsl.go:155 +0x2e9
  github.com/petergtz/pegomock.(*GenericMock).methodInvocations(0xc8200820a8, 0x473c48, 0x3, 0xc820073940, 0x1, 0x1, 0xc820073930, 0x1, 0x1, 0x0, ...)
        /localdisk/gowork/src/github.com/petergtz/pegomock/dsl.go:139 +0x94
  github.com/petergtz/pegomock.(*GenericMock).Verify(0xc8200820a8, 0x0, 0xc04e50, 0xc8200ded00, 0x473c48, 0x3, 0xc820073940, 0x1, 0x1, 0x0, ...)
        /localdisk/gowork/src/github.com/petergtz/pegomock/dsl.go:95 +0x1aa
  bitbucket.org/berupp/sandbox/model_test.(*VerifierCar).Run(0xc8200493b0, 0x0, 0x0, 0xc04e50)

It works fine using arbitrary input. It looks like the mocked method needs to be invoked at least once to have matchers work.

Reproduce:

type Person interface{
    Name(string)
}
petergtz commented 7 years ago

Hi @berupp,

Thanks for reporting this bug. I just pushed a change that should fix it. Let me know if this solves your problem and feel free to close the issue.

Thanks, Peter

berupp commented 7 years ago

Thank you so much. It's working. This is a great project, I really like the API and ability to write custom matchers.