From d0755d3748531a7cf79ecabf85dd55af7430758b Mon Sep 17 00:00:00 2001 From: Timm Felden Date: Fri, 21 Oct 2022 09:07:50 +0200 Subject: [PATCH] Improve mock usability in tests Add stacktrace on fatal exit of mocked call to allow maintainers of tests using this API to understand what is actually going wrong --- gomock/controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gomock/controller.go b/gomock/controller.go index 5e2def13..cf40f334 100644 --- a/gomock/controller.go +++ b/gomock/controller.go @@ -190,7 +190,7 @@ func (ctrl *Controller) Call(receiver interface{}, method string, args ...interf // and this line changes, i.e. this code is wrapped in another anonymous function. // 0 is us, 1 is controller.Call(), 2 is the generated mock, and 3 is the user's test. origin := callerInfo(3) - ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, args, origin, err) + ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s\n from %s", receiver, method, args, origin, err, debug.Stack()) } // Two things happen here: