Fix for #270 (REQUIRE continues if test throws an exception).

Added test case that reproduced the bug then applied the fix.
This commit is contained in:
Phil Nash 2014-04-12 19:07:24 +01:00
parent e9d35377fa
commit a176b93738
9 changed files with 60 additions and 12 deletions

View File

@ -1,6 +1,6 @@
![catch logo](catch-logo-small.png)
*v1.0 build 33 (master branch)*
*v1.0 build 34 (master branch)*
Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch)

View File

@ -87,7 +87,7 @@ struct TestFailureException{};
throw; \
} catch( ... ) { \
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), \
resultDisposition | Catch::ResultDisposition::ContinueOnFailure, expr ); \
resultDisposition, expr ); \
} \
} while( Catch::isTrue( false ) )

View File

@ -13,7 +13,7 @@
namespace Catch {
// These numbers are maintained by a script
Version libraryVersion( 1, 0, 33, "master" );
Version libraryVersion( 1, 0, 34, "master" );
}
#endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED

View File

@ -331,6 +331,17 @@ ExceptionTests.cpp:<line number>: FAILED:
due to unexpected exception with message:
expected exception
-------------------------------------------------------------------------------
When unchecked exceptions are thrown during a require the test should fail
-------------------------------------------------------------------------------
ExceptionTests.cpp:<line number>
...............................................................................
ExceptionTests.cpp:<line number>: FAILED:
REQUIRE( thisThrows() == 0 )
due to unexpected exception with message:
expected exception
-------------------------------------------------------------------------------
Unexpected custom exceptions can be translated
-------------------------------------------------------------------------------
@ -750,5 +761,5 @@ with expansion:
"first" == "second"
===============================================================================
122 test cases - 36 failed (658 assertions - 91 failed)
123 test cases - 37 failed (659 assertions - 92 failed)

View File

@ -1110,6 +1110,17 @@ ExceptionTests.cpp:<line number>: FAILED:
due to unexpected exception with message:
expected exception
-------------------------------------------------------------------------------
When unchecked exceptions are thrown during a require the test should fail
-------------------------------------------------------------------------------
ExceptionTests.cpp:<line number>
...............................................................................
ExceptionTests.cpp:<line number>: FAILED:
REQUIRE( thisThrows() == 0 )
due to unexpected exception with message:
expected exception
-------------------------------------------------------------------------------
When unchecked exceptions are thrown, but caught, they do not affect the test
-------------------------------------------------------------------------------
@ -6958,5 +6969,5 @@ with expansion:
true
===============================================================================
122 test cases - 51 failed (677 assertions - 110 failed)
123 test cases - 52 failed (678 assertions - 111 failed)

View File

@ -1,5 +1,5 @@
<testsuites>
<testsuite name="~_" errors="10" failures="100" tests="677" hostname="tbd" time="{duration}" timestamp="tbd">
<testsuite name="~_" errors="11" failures="100" tests="678" hostname="tbd" time="{duration}" timestamp="tbd">
<testcase classname="global" name="Some simple comparisons between doubles" time="{duration}"/>
<testcase classname="global" name="Approximate comparisons with different epsilons" time="{duration}"/>
<testcase classname="global" name="Approximate comparisons with floats" time="{duration}"/>
@ -207,6 +207,12 @@ ExceptionTests.cpp:<line number>
<testcase classname="global" name="When unchecked exceptions are thrown from functions they are always failures" time="{duration}">
<error message="thisThrows() == 0" type="CHECK">
expected exception
ExceptionTests.cpp:<line number>
</error>
</testcase>
<testcase classname="global" name="When unchecked exceptions are thrown during a require the test should fail" time="{duration}">
<error message="thisThrows() == 0" type="REQUIRE">
expected exception
ExceptionTests.cpp:<line number>
</error>
</testcase>

View File

@ -1426,6 +1426,20 @@
</Expression>
<OverallResult success="false"/>
</TestCase>
<TestCase name="When unchecked exceptions are thrown during a require the test should fail">
<Expression success="false" filename="/Users/philnash/Dev/OSS/Catch/projects/SelfTest/ExceptionTests.cpp" >
<Original>
thisThrows() == 0
</Original>
<Expanded>
thisThrows() == 0
</Expanded>
<Exception filename="/Users/philnash/Dev/OSS/Catch/projects/SelfTest/ExceptionTests.cpp" >
expected exception
</Exception>
</Expression>
<OverallResult success="false"/>
</TestCase>
<TestCase name="When unchecked exceptions are thrown, but caught, they do not affect the test">
<OverallResult success="true"/>
</TestCase>
@ -7214,7 +7228,7 @@ there&quot;
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="567" failures="110"/>
<OverallResults successes="567" failures="111"/>
</Group>
<OverallResults successes="567" failures="110"/>
<OverallResults successes="567" failures="111"/>
</Catch>

View File

@ -66,6 +66,12 @@ TEST_CASE( "When unchecked exceptions are thrown from functions they are always
CHECK( thisThrows() == 0 );
}
TEST_CASE( "When unchecked exceptions are thrown during a require the test should fail", "[.][failing]" )
{
REQUIRE( thisThrows() == 0 );
FAIL( "This should never happen" );
}
TEST_CASE( "When unchecked exceptions are thrown, but caught, they do not affect the test", "" )
{
try

View File

@ -1,6 +1,6 @@
/*
* CATCH v1.0 build 33 (master branch)
* Generated: 2014-03-24 18:11:50.426554
* CATCH v1.0 build 34 (master branch)
* Generated: 2014-04-12 19:07:02.688717
* ----------------------------------------------------------
* This file has been merged from multiple headers. Please don't edit it directly
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
@ -1599,7 +1599,7 @@ struct TestFailureException{};
throw; \
} catch( ... ) { \
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), \
resultDisposition | Catch::ResultDisposition::ContinueOnFailure, expr ); \
resultDisposition, expr ); \
} \
} while( Catch::isTrue( false ) )
@ -6598,7 +6598,7 @@ namespace Catch {
namespace Catch {
// These numbers are maintained by a script
Version libraryVersion( 1, 0, 33, "master" );
Version libraryVersion( 1, 0, 34, "master" );
}
// #included from: catch_message.hpp