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

print messages when unexpected exceptions are thrown #876

Merged
merged 1 commit into from
Apr 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/internal/catch_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ namespace Catch {
{}

ScopedMessage::~ScopedMessage() {
getResultCapture().popScopedMessage( m_info );
if (!std::uncaught_exception())
{
getResultCapture().popScopedMessage(m_info);
}
}


Expand Down
6 changes: 5 additions & 1 deletion include/reporters/catch_reporter_console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ namespace Catch {
case ResultWas::ThrewException:
colour = Colour::Error;
passOrFail = "FAILED";
messageLabel = "due to unexpected exception with message";
messageLabel = "due to unexpected exception with ";
if (_stats.infoMessages.size() == 1)
messageLabel += "message";
if (_stats.infoMessages.size() > 1)
messageLabel += "messages";
break;
case ResultWas::FatalErrorCondition:
colour = Colour::Error;
Expand Down
15 changes: 15 additions & 0 deletions projects/SelfTest/ExceptionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,18 @@ TEST_CASE( "Mismatching exception messages failing the test", "[.][failing][!thr
REQUIRE_THROWS_WITH( thisThrows(), "should fail" );
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" );
}

TEST_CASE( "#748 - captures with unexpected exceptions", "[!shouldfail]" ) {
int answer = 42;
CAPTURE(answer);
// the message should be printed on the first two sections but not on the third
SECTION( "outside assertions" ) {
thisThrows();
}
SECTION( "inside REQUIRE_NOTHROW" ) {
REQUIRE_NOTHROW(thisThrows());
}
SECTION( "inside REQUIRE_THROWS" ) {
REQUIRE_THROWS(thisThrows());
}
}