Added _THROWS_WITH macros

- asserts on exception message
This commit is contained in:
Phil Nash
2015-07-13 06:34:41 +01:00
parent 5d5ed5a283
commit 85de743d70
9 changed files with 106 additions and 17 deletions

View File

@@ -397,6 +397,17 @@ ExceptionTests.cpp:<line number>: FAILED:
due to unexpected exception with message:
3.14
-------------------------------------------------------------------------------
Exception messages can be tested for
-------------------------------------------------------------------------------
ExceptionTests.cpp:<line number>
...............................................................................
ExceptionTests.cpp:<line number>: FAILED:
REQUIRE_THROWS_WITH( thisThrows(), "should fail" )
with expansion:
expected exception
-------------------------------------------------------------------------------
INFO and WARN do not abort tests
-------------------------------------------------------------------------------
@@ -786,6 +797,6 @@ with expansion:
"first" == "second"
===============================================================================
test cases: 155 | 116 passed | 38 failed | 1 failed as expected
assertions: 765 | 673 passed | 79 failed | 13 failed as expected
test cases: 156 | 116 passed | 39 failed | 1 failed as expected
assertions: 767 | 674 passed | 80 failed | 13 failed as expected

View File

@@ -1277,6 +1277,21 @@ ExceptionTests.cpp:<line number>:
PASSED:
REQUIRE_THROWS( thisFunctionNotImplemented( 7 ) )
-------------------------------------------------------------------------------
Exception messages can be tested for
-------------------------------------------------------------------------------
ExceptionTests.cpp:<line number>
...............................................................................
ExceptionTests.cpp:<line number>:
PASSED:
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" )
ExceptionTests.cpp:<line number>: FAILED:
REQUIRE_THROWS_WITH( thisThrows(), "should fail" )
with expansion:
expected exception
-------------------------------------------------------------------------------
Generators over two ranges
-------------------------------------------------------------------------------
@@ -7944,6 +7959,6 @@ with expansion:
true
===============================================================================
test cases: 155 | 100 passed | 54 failed | 1 failed as expected
assertions: 785 | 673 passed | 99 failed | 13 failed as expected
test cases: 156 | 100 passed | 55 failed | 1 failed as expected
assertions: 787 | 674 passed | 100 failed | 13 failed as expected

View File

@@ -1,5 +1,5 @@
<testsuites>
<testsuite name="all tests" errors="12" failures="87" tests="785" hostname="tbd" time="{duration}" timestamp="tbd">
<testsuite name="all tests" errors="12" failures="88" tests="787" hostname="tbd" time="{duration}" timestamp="tbd">
<testcase classname="global" name="toString(enum)" time="{duration}"/>
<testcase classname="global" name="toString(enum w/operator&lt;&lt;)" time="{duration}"/>
<testcase classname="global" name="toString(enum class)" time="{duration}"/>
@@ -251,6 +251,11 @@ ExceptionTests.cpp:<line number>
</error>
</testcase>
<testcase classname="global" name="NotImplemented exception" time="{duration}"/>
<testcase classname="global" name="Exception messages can be tested for" time="{duration}">
<failure message="expected exception" type="REQUIRE_THROWS_WITH">
ExceptionTests.cpp:<line number>
</failure>
</testcase>
<testcase classname="global" name="Generators over two ranges" time="{duration}"/>
<testcase classname="global" name="Generator over a range of pairs" time="{duration}"/>
<testcase classname="global" name="INFO and WARN do not abort tests" time="{duration}"/>

View File

@@ -1596,6 +1596,25 @@
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Exception messages can be tested for">
<Expression success="true" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
<Original>
thisThrows(), &quot;expected exception&quot;
</Original>
<Expanded>
thisThrows(), &quot;expected exception&quot;
</Expanded>
</Expression>
<Expression success="false" type="REQUIRE_THROWS_WITH" filename="projects/SelfTest/ExceptionTests.cpp" >
<Original>
thisThrows(), &quot;should fail&quot;
</Original>
<Expanded>
expected exception
</Expanded>
</Expression>
<OverallResult success="false"/>
</TestCase>
<TestCase name="Generators over two ranges">
<Expression success="true" type="CATCH_REQUIRE" filename="projects/SelfTest/GeneratorTests.cpp" >
<Original>
@@ -8220,7 +8239,7 @@ there&quot;
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="673" failures="99" expectedFailures="13"/>
<OverallResults successes="674" failures="100" expectedFailures="13"/>
</Group>
<OverallResults successes="673" failures="99" expectedFailures="13"/>
<OverallResults successes="674" failures="100" expectedFailures="13"/>
</Catch>

View File

@@ -152,3 +152,8 @@ TEST_CASE( "NotImplemented exception", "" )
{
REQUIRE_THROWS( thisFunctionNotImplemented( 7 ) );
}
TEST_CASE( "Exception messages can be tested for", "[.][failing]" ) {
REQUIRE_THROWS_WITH( thisThrows(), "expected exception" );
REQUIRE_THROWS_WITH( thisThrows(), "should fail" );
}