Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Show file and line number of call during errors #25

Closed
wants to merge 1 commit into from

Conversation

ooesili
Copy link

@ooesili ooesili commented Feb 8, 2016

Show file and line number of call during errors

This commit makes erroneous calls show their origin. Unexpected calls
show where they happened. Missing calls and improper expectations show
where they were set up in the tests. This information is printed after
each error message in square brackets.

Here is an example of the output:

--- FAIL: TestNoMatchingCall (0.00s)
    controller.go:119: no matching expected call: *mocktest_test.MockDoer.Do([hello]) [/home/ooesili/golang/src/github.com/ooesili/mocktest/mocktest.go:8]
--- FAIL: TestWrongReturnArity (0.00s)
    call.go:83: wrong number of arguments to Return for *mocktest_test.MockDoer.Do: got 1, want 2 [/home/ooesili/golang/src/github.com/ooesili/mocktest/mocktest_test.go:23]
    controller.go:164: missing call(s) to *mocktest_test.MockDoer.Do(is equal to blah) [/home/ooesili/golang/src/github.com/ooesili/mocktest/mocktest_test.go:23]
    controller.go:171: aborting test due to missing call(s)
--- FAIL: TestNotNillable (0.00s)
    call.go:95: argument 0 to Return for *mocktest_test.MockDoer.Do is nil, but string is not nillable [/home/ooesili/golang/src/github.com/ooesili/mocktest/mocktest_test.go:31]
    controller.go:164: missing call(s) to *mocktest_test.MockDoer.Do(is equal to blah) [/home/ooesili/golang/src/github.com/ooesili/mocktest/mocktest_test.go:31]
    controller.go:171: aborting test due to missing call(s)
--- FAIL: TestWrongReturnType (0.00s)
    call.go:105: wrong type of argument 1 to Return for *mocktest_test.MockDoer.Do: string is not assignable to error [/home/ooesili/golang/src/github.com/ooesili/mocktest/mocktest_test.go:39]
    controller.go:164: missing call(s) to *mocktest_test.MockDoer.Do(is equal to blah) [/home/ooesili/golang/src/github.com/ooesili/mocktest/mocktest_test.go:39]
    controller.go:171: aborting test due to missing call(s)
FAIL
FAIL    github.com/ooesili/mocktest 0.002s

I had a hard time deciding how I wanted the output to look so I'd love some feedback. I originally had the file and line number displayed as a prefix like mocktest_test.go:14: missing call(s) to ..., which looks great when used with Ginkgo, but looks awkward with plain go test, since the prefixes were doubled controller.go:164: mocktest_test.go:14: missing call(s) to ....

It would be trivial to also add the package/function name of the caller to this output. I decided against that since the file and line number is generally all I'm after when debugging.

This commit makes erroneous calls show their origin. Unexpected calls
show where they happened. Missing calls and improper expectations show
where they were set up in the tests. This information is printed after
each error message in square brackets.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@ooesili
Copy link
Author

ooesili commented Feb 8, 2016

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@owentran
Copy link

@ooesili Looks good to me. I'm not using any special test runner, just go test, so output is legible for me. Thanks!

@ooesili
Copy link
Author

ooesili commented Apr 8, 2016

@dsymonds Could I get some feedback on this?

@zwass
Copy link

zwass commented Sep 15, 2016

This looks like a useful feature... Can one of the maintainers take a look?

xmik added a commit to xmik/mock that referenced this pull request Aug 3, 2017
This commit makes erroneous calls show their origin. Unexpected calls
show where they happened. Missing calls and improper expectations show
where they were set up in the tests. This information is printed after
each error message in square brackets.

This commit was originally:
ooesili@76f75d8
and a PR for it: golang#25. But there were
minor conflicts with master from 2 aug 2017:
golang@13f3609,
which I fixed.
xmik added a commit to xmik/mock that referenced this pull request Aug 3, 2017
This commit makes erroneous calls show their origin. Unexpected calls
show where they happened. Missing calls and improper expectations show
where they were set up in the tests. This information is printed after
each error message in square brackets.

This commit was originally:
ooesili@76f75d8
and a PR for it: golang#25. But there were
minor conflicts with master from 2 aug 2017:
golang@13f3609,
which I fixed.
xmik added a commit to xmik/mock that referenced this pull request Aug 3, 2017
This commit makes erroneous calls show their origin. Unexpected calls
show where they happened. Missing calls and improper expectations show
where they were set up in the tests. This information is printed after
each error message in square brackets.

This commit was originally:
ooesili@76f75d8
and a PR for it: golang#25. But there were
minor conflicts with master from 2 aug 2017:
golang@13f3609,
which I fixed.
@ybbus
Copy link

ybbus commented Aug 18, 2017

Any news on this? Would be a huge imrovement, since I always spent a lot of time which of the expected calls in my test did not trigger or the other way around which did trigger without expectation.

This is really hard if you have a lot of tests on the same mock object / function.
Having them in Sub-Conveys of the convey testing tool is even worse.

@balshetzer
Copy link
Collaborator

This change was pulled through #97. Should be working now. Please re-open if I misunderstood.

@balshetzer balshetzer closed this Aug 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants