gojuno / minimock

Powerful mock generation tool for Go programming language
MIT License
577 stars 38 forks source link

Nil panic when method not called #31

Closed rekby closed 5 years ago

rekby commented 5 years ago

If set return parameters without .Expected for method with arguments, then not call the method - minimock will panic on Finish.

tmp.go

package asd

import "testing"

type Int interface {
    M()
    MA(i int)
}

func TestExpected(t *testing.T) {
    m := NewIntMock(t)
    m.MMock.Return()

    // Work as expected: fail test because method not called
    m.MinimockFinish()
}

func TestNilPanic(t *testing.T) {
    m := NewIntMock(t)
    m.MAMock.Return() // for method with arguments

    // invalid memory address or nil pointer dereference. Bug.
    m.MinimockFinish()
}

generated code: https://gist.github.com/rekby/3e95b03c8220cd5da895e8ccaa66bd44