Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in CHECK/REQUIRE prints exception message twice and raises assertion-failure counter by two #164

Closed
StephanDollberg opened this issue Apr 20, 2013 · 7 comments

Comments

@StephanDollberg
Copy link

If an exception is thrown in a test-case which doesn't except it, the assertion-failure counter is raised by two and the exception message is printed twice.

Example: (using the latest all-in-one file)

Running the following test

#define CATCH_CONFIG_MAIN                                                                            
#include "catch.hpp"

int foo() { throw 234; return 42; }

TEST_CASE("Test/1", "Test") {
    CHECK(foo() == 42);
}

Gives the following output:

test.cpp:8: foo() == 42 failed with unexpected exception with message: 'Unknown exception'
test.cpp:8: foo() == 42 failed with unexpected exception with message: 'Unknown exception'
[Finished: 'Test/1' 1 test case failed (All 2 assertions failed)]

[Testing completed. 1 test case failed (All 2 assertions failed)]

I found a related issue here(#139), however that was supposed to be fixed.

@philsquared
Copy link
Collaborator

#139 related to the integration branch (which probably hasn't been merged over since then). Looks like you've found the same issue on Master.
I'd recommend you try integration. It's superiour in many ways and I should be committing it across soon anyway.

@andyprowl
Copy link

With the integration branch the second message is slightly different and contains the message "{Unknown expression after the reported line}", but it still counts as if 2 assertions failed instead of one.

@philsquared
Copy link
Collaborator

Ah. Thanks for the extra info, Andy.
I'll take a look.

philsquared added a commit that referenced this issue Apr 20, 2013
- Removed spurious (re-)throw when catching unexpected exception
philsquared added a commit that referenced this issue Apr 20, 2013
includes:
- SFINAE version of IsStreamable (where available)
- new Text class that replaces LineWrapper (internal)
- fix for spurious double exception reporting (#164)
@philsquared
Copy link
Collaborator

Found and fixed. Thanks for reporting this guys. Was a silly little spurious (re-)throw statement that got left in at some point.
My tests for throwing exceptions outside of an exception-anticipating assertion threw it directly - but this bug requires you throw from a function - so I was missing it!
Needless to say I've added the function throwing case to my test suite now!

@philsquared
Copy link
Collaborator

(Fixed in Integration, that is)

@andyprowl
Copy link

Wow, that was fast. Thank you very much :)

@philsquared
Copy link
Collaborator

NP. Thanks for letting me know about it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants