golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.32k stars 607 forks source link

Return last call for InOrder #403

Open codyoss opened 4 years ago

codyoss commented 4 years ago

The following changes InOrder to return the last called Call. This allows a more fluent design when using InOrder, things can be better chained together and allows composing of numerous InOrder calls.

Example:

func doX(ctrl *gomock.Controller) *gomock.Call {
    mock := NewMockA(ctrl)
    return gomock.InOrder(
        doZ(mock),
        mock.EXPECT().Foo().Return("bar"),
    )
}

func doY(ctrl *gomock.Controller) *gomock.Call {
    mock := NewMockB(ctrl)
    return gomock.InOrder(
        doZ(mock),
        mock.EXPECT().Bar().Return("foo"),
    )
}

gomock.InOrder(
    doX(ctrl),
    doY(ctrl),
)

Body here copied from #199

codyoss commented 4 years ago

This seems like a reasonable change, but it is breaking so holding off for now.

sirkon commented 3 years ago

it is breaking

Is it? Won't compile?

Because it is pure feat if it compiles.

UPD Some can make use of given func (...gomock.Call) signature indeed. Won't compile in this case. Pure feat though for a reasonable usage.