Fixes issue #164

- Removed spurious (re-)throw when catching unexpected exception
This commit is contained in:
Phil Nash 2013-04-20 21:04:32 +01:00
parent b3acf45d70
commit 2666c96d4e
4 changed files with 91 additions and 46 deletions

View File

@ -88,7 +88,6 @@ inline bool isTrue( bool value ){ return value; }
} catch( ... ) { \ } catch( ... ) { \
INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), \ INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), \
resultDisposition | Catch::ResultDisposition::ContinueOnFailure, expr ); \ resultDisposition | Catch::ResultDisposition::ContinueOnFailure, expr ); \
throw; \
} \ } \
} while( Catch::isTrue( false ) ) } while( Catch::isTrue( false ) )
@ -179,7 +178,6 @@ inline bool isTrue( bool value ){ return value; }
} catch( ... ) { \ } catch( ... ) { \
INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), \ INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), \
resultDisposition | Catch::ResultDisposition::ContinueOnFailure, false ); \ resultDisposition | Catch::ResultDisposition::ContinueOnFailure, false ); \
throw; \
} \ } \
} while( Catch::isTrue( false ) ) } while( Catch::isTrue( false ) )

View File

@ -1095,31 +1095,42 @@ due to unexpected exception with message:
unexpected exception unexpected exception
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
./succeeding/exceptions/implicit ./failing/exceptions/implicit/4
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
ExceptionTests.cpp:69 ExceptionTests.cpp:69
............................................................................... ...............................................................................
ExceptionTests.cpp:71: FAILED:
CHECK( thisThrows() == 0 )
due to unexpected exception with message:
expected exception
-------------------------------------------------------------------------------
./succeeding/exceptions/implicit
-------------------------------------------------------------------------------
ExceptionTests.cpp:75
...............................................................................
No assertions in test case, './succeeding/exceptions/implicit' No assertions in test case, './succeeding/exceptions/implicit'
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
./failing/exceptions/custom ./failing/exceptions/custom
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
ExceptionTests.cpp:106 ExceptionTests.cpp:112
............................................................................... ...............................................................................
ExceptionTests.cpp:106: FAILED: ExceptionTests.cpp:112: FAILED:
due to unexpected exception with message: due to unexpected exception with message:
custom exception custom exception
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
./failing/exceptions/custom/nothrow ./failing/exceptions/custom/nothrow
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
ExceptionTests.cpp:114 ExceptionTests.cpp:120
............................................................................... ...............................................................................
ExceptionTests.cpp:116: FAILED: ExceptionTests.cpp:122: FAILED:
REQUIRE_NOTHROW( throw CustomException( "unexpected custom exception" ) ) REQUIRE_NOTHROW( throw CustomException( "unexpected custom exception" ) )
due to unexpected exception with message: due to unexpected exception with message:
unexpected custom exception unexpected custom exception
@ -1127,10 +1138,10 @@ due to unexpected exception with message:
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
./failing/exceptions/custom/throw ./failing/exceptions/custom/throw
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
ExceptionTests.cpp:119 ExceptionTests.cpp:125
............................................................................... ...............................................................................
ExceptionTests.cpp:121: FAILED: ExceptionTests.cpp:127: FAILED:
REQUIRE_THROWS_AS( throw CustomException( "custom exception - not std" ) ) REQUIRE_THROWS_AS( throw CustomException( "custom exception - not std" ) )
due to unexpected exception with message: due to unexpected exception with message:
custom exception - not std custom exception - not std
@ -1138,20 +1149,20 @@ due to unexpected exception with message:
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
./failing/exceptions/custom/double ./failing/exceptions/custom/double
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
ExceptionTests.cpp:125 ExceptionTests.cpp:131
............................................................................... ...............................................................................
ExceptionTests.cpp:125: FAILED: ExceptionTests.cpp:131: FAILED:
due to unexpected exception with message: due to unexpected exception with message:
3.14 3.14
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
./succeeding/exceptions/notimplemented ./succeeding/exceptions/notimplemented
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
ExceptionTests.cpp:134 ExceptionTests.cpp:140
............................................................................... ...............................................................................
ExceptionTests.cpp:136: ExceptionTests.cpp:142:
PASSED: PASSED:
REQUIRE_THROWS( thisFunctionNotImplemented( 7 ) ) REQUIRE_THROWS( thisFunctionNotImplemented( 7 ) )
@ -3207,6 +3218,11 @@ PASSED:
with message: with message:
Tests failed, as expected Tests failed, as expected
catch_self_test.hpp:120:
PASSED:
with message:
Tests failed, as expected
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
selftest/main selftest/main
selftest/expected result selftest/expected result
@ -3489,9 +3505,9 @@ with expansion:
TestMain.cpp:49: TestMain.cpp:49:
PASSED: PASSED:
CHECK( totals.assertions.failed == 73 ) CHECK( totals.assertions.failed == 74 )
with expansion: with expansion:
73 == 73 74 == 74
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
meta/Misc/Sections meta/Misc/Sections
@ -5503,7 +5519,7 @@ with message:
boo! boo!
=============================================================================== ===============================================================================
110 test cases - 48 failed (703 assertions - 105 failed) 111 test cases - 49 failed (705 assertions - 106 failed)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -5824,7 +5840,7 @@ with expansion:
13 test cases - 3 failed (40 assertions - 4 failed) 13 test cases - 3 failed (40 assertions - 4 failed)
<testsuites> <testsuites>
<testsuite name="~dummy" errors="9" failures="78" tests="703" hostname="tbd" time="tbd" timestamp="tbd"> <testsuite name="~dummy" errors="10" failures="78" tests="705" hostname="tbd" time="tbd" timestamp="tbd">
<testcase classname="global" name="./succeeding/Approx/simple" time="tbd"/> <testcase classname="global" name="./succeeding/Approx/simple" time="tbd"/>
<testcase classname="global" name="./succeeding/Approx/epsilon" time="tbd"/> <testcase classname="global" name="./succeeding/Approx/epsilon" time="tbd"/>
<testcase classname="global" name="./succeeding/Approx/float" time="tbd"/> <testcase classname="global" name="./succeeding/Approx/float" time="tbd"/>
@ -6024,25 +6040,30 @@ ExceptionTests.cpp:56
ExceptionTests.cpp:62 ExceptionTests.cpp:62
</error> </error>
</testcase> </testcase>
<testcase classname="global" name="./failing/exceptions/implicit/4" time="tbd">
<error message="thisThrows() == 0" type="CHECK">
ExceptionTests.cpp:71
</error>
</testcase>
<testcase classname="global" name="./succeeding/exceptions/implicit" time="tbd"/> <testcase classname="global" name="./succeeding/exceptions/implicit" time="tbd"/>
<testcase classname="global" name="./failing/exceptions/custom" time="tbd"> <testcase classname="global" name="./failing/exceptions/custom" time="tbd">
<error type="TEST_CASE"> <error type="TEST_CASE">
ExceptionTests.cpp:106 ExceptionTests.cpp:112
</error> </error>
</testcase> </testcase>
<testcase classname="global" name="./failing/exceptions/custom/nothrow" time="tbd"> <testcase classname="global" name="./failing/exceptions/custom/nothrow" time="tbd">
<error message="throw CustomException( &quot;unexpected custom exception&quot; )" type="REQUIRE_NOTHROW"> <error message="throw CustomException( &quot;unexpected custom exception&quot; )" type="REQUIRE_NOTHROW">
ExceptionTests.cpp:116 ExceptionTests.cpp:122
</error> </error>
</testcase> </testcase>
<testcase classname="global" name="./failing/exceptions/custom/throw" time="tbd"> <testcase classname="global" name="./failing/exceptions/custom/throw" time="tbd">
<error message="throw CustomException( &quot;custom exception - not std&quot; )" type="REQUIRE_THROWS_AS"> <error message="throw CustomException( &quot;custom exception - not std&quot; )" type="REQUIRE_THROWS_AS">
ExceptionTests.cpp:121 ExceptionTests.cpp:127
</error> </error>
</testcase> </testcase>
<testcase classname="global" name="./failing/exceptions/custom/double" time="tbd"> <testcase classname="global" name="./failing/exceptions/custom/double" time="tbd">
<error type="TEST_CASE"> <error type="TEST_CASE">
ExceptionTests.cpp:125 ExceptionTests.cpp:131
</error> </error>
</testcase> </testcase>
<testcase classname="global" name="./succeeding/exceptions/notimplemented" time="tbd"/> <testcase classname="global" name="./succeeding/exceptions/notimplemented" time="tbd"/>
@ -7762,51 +7783,65 @@ ExceptionTests.cpp" line="62">
</Section> </Section>
<OverallResult success="false"/> <OverallResult success="false"/>
</TestCase> </TestCase>
<TestCase name="./failing/exceptions/implicit/4">
ExceptionTests.cpp" line="71">
<Original>
thisThrows() == 0
</Original>
<Expanded>
thisThrows() == 0
</Expanded>
ExceptionTests.cpp" line="71">
expected exception
</Exception>
</Expression>
<OverallResult success="false"/>
</TestCase>
<TestCase name="./succeeding/exceptions/implicit"> <TestCase name="./succeeding/exceptions/implicit">
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<TestCase name="./failing/exceptions/custom"> <TestCase name="./failing/exceptions/custom">
ExceptionTests.cpp" line="106"> ExceptionTests.cpp" line="112">
custom exception custom exception
</Exception> </Exception>
<OverallResult success="false"/> <OverallResult success="false"/>
</TestCase> </TestCase>
<TestCase name="./failing/exceptions/custom/nothrow"> <TestCase name="./failing/exceptions/custom/nothrow">
ExceptionTests.cpp" line="116"> ExceptionTests.cpp" line="122">
<Original> <Original>
throw CustomException( &quot;unexpected custom exception&quot; ) throw CustomException( &quot;unexpected custom exception&quot; )
</Original> </Original>
<Expanded> <Expanded>
throw CustomException( &quot;unexpected custom exception&quot; ) throw CustomException( &quot;unexpected custom exception&quot; )
</Expanded> </Expanded>
ExceptionTests.cpp" line="116"> ExceptionTests.cpp" line="122">
unexpected custom exception unexpected custom exception
</Exception> </Exception>
</Expression> </Expression>
<OverallResult success="false"/> <OverallResult success="false"/>
</TestCase> </TestCase>
<TestCase name="./failing/exceptions/custom/throw"> <TestCase name="./failing/exceptions/custom/throw">
ExceptionTests.cpp" line="121"> ExceptionTests.cpp" line="127">
<Original> <Original>
throw CustomException( &quot;custom exception - not std&quot; ) throw CustomException( &quot;custom exception - not std&quot; )
</Original> </Original>
<Expanded> <Expanded>
throw CustomException( &quot;custom exception - not std&quot; ) throw CustomException( &quot;custom exception - not std&quot; )
</Expanded> </Expanded>
ExceptionTests.cpp" line="121"> ExceptionTests.cpp" line="127">
custom exception - not std custom exception - not std
</Exception> </Exception>
</Expression> </Expression>
<OverallResult success="false"/> <OverallResult success="false"/>
</TestCase> </TestCase>
<TestCase name="./failing/exceptions/custom/double"> <TestCase name="./failing/exceptions/custom/double">
ExceptionTests.cpp" line="125"> ExceptionTests.cpp" line="131">
3.14 3.14
</Exception> </Exception>
<OverallResult success="false"/> <OverallResult success="false"/>
</TestCase> </TestCase>
<TestCase name="./succeeding/exceptions/notimplemented"> <TestCase name="./succeeding/exceptions/notimplemented">
ExceptionTests.cpp" line="136"> ExceptionTests.cpp" line="142">
<Original> <Original>
thisFunctionNotImplemented( 7 ) thisFunctionNotImplemented( 7 )
</Original> </Original>
@ -9957,9 +9992,9 @@ MiscTests.cpp" line="332">
<TestCase name="selftest/main"> <TestCase name="selftest/main">
<Section name="selftest/expected result" description="Tests do what they claim"> <Section name="selftest/expected result" description="Tests do what they claim">
<Section name="selftest/expected result/failing tests" description="Tests in the 'failing' branch fail"> <Section name="selftest/expected result/failing tests" description="Tests in the 'failing' branch fail">
<OverallResults successes="26" failures="0"/> <OverallResults successes="27" failures="0"/>
</Section> </Section>
<OverallResults successes="26" failures="0"/> <OverallResults successes="27" failures="0"/>
</Section> </Section>
<Section name="selftest/expected result" description="Tests do what they claim"> <Section name="selftest/expected result" description="Tests do what they claim">
<Section name="selftest/expected result/succeeding tests" description="Tests in the 'succeeding' branch succeed"> <Section name="selftest/expected result/succeeding tests" description="Tests in the 'succeeding' branch succeed">
@ -10004,10 +10039,10 @@ TestMain.cpp" line="48">
</Expression> </Expression>
TestMain.cpp" line="49"> TestMain.cpp" line="49">
<Original> <Original>
totals.assertions.failed == 73 totals.assertions.failed == 74
</Original> </Original>
<Expanded> <Expanded>
73 == 73 74 == 74
</Expanded> </Expanded>
</Expression> </Expression>
<OverallResults successes="2" failures="0"/> <OverallResults successes="2" failures="0"/>
@ -12217,9 +12252,9 @@ BDDTests.cpp" line="54">
</Section> </Section>
<OverallResult success="true"/> <OverallResult success="true"/>
</TestCase> </TestCase>
<OverallResults successes="598" failures="105"/> <OverallResults successes="599" failures="106"/>
</Group> </Group>
<OverallResults successes="598" failures="105"/> <OverallResults successes="599" failures="106"/>
</Catch> </Catch>
[Started testing: CatchSelfTest] [Started testing: CatchSelfTest]
[Started group: '~dummy'] [Started group: '~dummy']
@ -12483,6 +12518,10 @@ ExceptionTests.cpp:62: Unexpected exception with message: 'unexpected exception'
[Finished: './failing/exceptions/implicit/3' 1 test case failed (1 assertion failed)] [Finished: './failing/exceptions/implicit/3' 1 test case failed (1 assertion failed)]
[Running: ./failing/exceptions/implicit/4]
ExceptionTests.cpp:71: thisThrows() == 0 failed with unexpected exception with message: 'expected exception'
[Finished: './failing/exceptions/implicit/4' 1 test case failed (1 assertion failed)]
[Running: ./succeeding/exceptions/implicit] [Running: ./succeeding/exceptions/implicit]
No assertions in test case, './succeeding/exceptions/implicit' No assertions in test case, './succeeding/exceptions/implicit'
@ -12490,23 +12529,23 @@ No assertions in test case, './succeeding/exceptions/implicit'
[Finished: './succeeding/exceptions/implicit' 1 test case failed (1 assertion failed)] [Finished: './succeeding/exceptions/implicit' 1 test case failed (1 assertion failed)]
[Running: ./failing/exceptions/custom] [Running: ./failing/exceptions/custom]
ExceptionTests.cpp:106: Unexpected exception with message: 'custom exception' ExceptionTests.cpp:112: Unexpected exception with message: 'custom exception'
[Finished: './failing/exceptions/custom' 1 test case failed (1 assertion failed)] [Finished: './failing/exceptions/custom' 1 test case failed (1 assertion failed)]
[Running: ./failing/exceptions/custom/nothrow] [Running: ./failing/exceptions/custom/nothrow]
ExceptionTests.cpp:116: throw CustomException( "unexpected custom exception" ) failed with unexpected exception with message: 'unexpected custom exception' ExceptionTests.cpp:122: throw CustomException( "unexpected custom exception" ) failed with unexpected exception with message: 'unexpected custom exception'
[Finished: './failing/exceptions/custom/nothrow' 1 test case failed (1 assertion failed)] [Finished: './failing/exceptions/custom/nothrow' 1 test case failed (1 assertion failed)]
[Running: ./failing/exceptions/custom/throw] [Running: ./failing/exceptions/custom/throw]
ExceptionTests.cpp:121: throw CustomException( "custom exception - not std" ) failed with unexpected exception with message: 'custom exception - not std' ExceptionTests.cpp:127: throw CustomException( "custom exception - not std" ) failed with unexpected exception with message: 'custom exception - not std'
[Finished: './failing/exceptions/custom/throw' 1 test case failed (1 assertion failed)] [Finished: './failing/exceptions/custom/throw' 1 test case failed (1 assertion failed)]
[Running: ./failing/exceptions/custom/double] [Running: ./failing/exceptions/custom/double]
ExceptionTests.cpp:125: Unexpected exception with message: '3.14' ExceptionTests.cpp:131: Unexpected exception with message: '3.14'
[Finished: './failing/exceptions/custom/double' 1 test case failed (1 assertion failed)] [Finished: './failing/exceptions/custom/double' 1 test case failed (1 assertion failed)]
[Running: ./succeeding/exceptions/notimplemented] [Running: ./succeeding/exceptions/notimplemented]
ExceptionTests.cpp:136: thisFunctionNotImplemented( 7 ) succeeded ExceptionTests.cpp:142: thisFunctionNotImplemented( 7 ) succeeded
[Finished: './succeeding/exceptions/notimplemented' All tests passed (1 assertion in 1 test case)] [Finished: './succeeding/exceptions/notimplemented' All tests passed (1 assertion in 1 test case)]
[Running: ./succeeding/generators/1] [Running: ./succeeding/generators/1]
@ -13094,9 +13133,11 @@ catch_self_test.hpp:120: succeeded
[with message: Tests failed, as expected] [with message: Tests failed, as expected]
catch_self_test.hpp:120: succeeded catch_self_test.hpp:120: succeeded
[with message: Tests failed, as expected] [with message: Tests failed, as expected]
[End of section: 'selftest/expected result/failing tests' All 26 assertions passed] catch_self_test.hpp:120: succeeded
[with message: Tests failed, as expected]
[End of section: 'selftest/expected result/failing tests' All 27 assertions passed]
[End of section: 'selftest/expected result' All 26 assertions passed] [End of section: 'selftest/expected result' All 27 assertions passed]
[Started section: 'selftest/expected result'] [Started section: 'selftest/expected result']
[Started section: 'selftest/expected result/succeeding tests'] [Started section: 'selftest/expected result/succeeding tests']
@ -13215,12 +13256,12 @@ TestMain.cpp:42: totals.assertions.failed == 0 succeeded for: 0 == 0
[Started section: 'selftest/test counts'] [Started section: 'selftest/test counts']
[Started section: 'selftest/test counts/failing tests'] [Started section: 'selftest/test counts/failing tests']
TestMain.cpp:48: totals.assertions.passed == 1 succeeded for: 1 == 1 TestMain.cpp:48: totals.assertions.passed == 1 succeeded for: 1 == 1
TestMain.cpp:49: totals.assertions.failed == 73 succeeded for: 73 == 73 TestMain.cpp:49: totals.assertions.failed == 74 succeeded for: 74 == 74
[End of section: 'selftest/test counts/failing tests' All 2 assertions passed] [End of section: 'selftest/test counts/failing tests' All 2 assertions passed]
[End of section: 'selftest/test counts' All 2 assertions passed] [End of section: 'selftest/test counts' All 2 assertions passed]
[Finished: 'selftest/main' All tests passed (76 assertions in 1 test case)] [Finished: 'selftest/main' All tests passed (77 assertions in 1 test case)]
[Running: meta/Misc/Sections] [Running: meta/Misc/Sections]
TestMain.cpp:58: totals.assertions.passed == 2 succeeded for: 2 == 2 TestMain.cpp:58: totals.assertions.passed == 2 succeeded for: 2 == 2
@ -14050,10 +14091,10 @@ BDDTests.cpp:67: succeeded
[End of section: ' Given: A section name that is so long that it cannot fit in a single console width' 1 assertion passed] [End of section: ' Given: A section name that is so long that it cannot fit in a single console width' 1 assertion passed]
[Finished: 'Scenario: This is a really long scenario name to see how the list command deals with wrapping' All tests passed (1 assertion in 1 test case)] [Finished: 'Scenario: This is a really long scenario name to see how the list command deals with wrapping' All tests passed (1 assertion in 1 test case)]
[End of group: '~dummy'. 48 of 110 test cases failed (105 of 703 assertions failed)] [End of group: '~dummy'. 49 of 111 test cases failed (106 of 705 assertions failed)]
[Testing completed. 48 of 110 test cases failed (105 of 703 assertions failed)] [Testing completed. 49 of 111 test cases failed (106 of 705 assertions failed)]
[Started testing: CatchSelfTest] [Started testing: CatchSelfTest]
[Started group: '~dummy'] [Started group: '~dummy']

View File

@ -66,6 +66,12 @@ TEST_CASE( "./failing/exceptions/implicit/3", "When unchecked exceptions are thr
} }
} }
TEST_CASE_NORETURN( "./failing/exceptions/implicit/4", "When unchecked exceptions are thrown they are always failures" )
{
CHECK( thisThrows() == 0 );
/*NOTREACHED*/
}
TEST_CASE( "./succeeding/exceptions/implicit", "When unchecked exceptions are thrown, but caught, they do not affect the test" ) TEST_CASE( "./succeeding/exceptions/implicit", "When unchecked exceptions are thrown, but caught, they do not affect the test" )
{ {
try try

View File

@ -46,7 +46,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
"Number of 'failing' tests is fixed" ) { "Number of 'failing' tests is fixed" ) {
Totals totals = runner.runMatching( "./failing/*", 1, 2 ); Totals totals = runner.runMatching( "./failing/*", 1, 2 );
CHECK( totals.assertions.passed == 1 ); CHECK( totals.assertions.passed == 1 );
CHECK( totals.assertions.failed == 73 ); CHECK( totals.assertions.failed == 74 );
} }
} }
} }