diff options
| author | Phil Nash | 2015-12-04 10:19:08 +0000 |
|---|---|---|
| committer | Phil Nash | 2015-12-04 10:19:08 +0000 |
| commit | fdc42d0af47f58fa13a42b685bbeaf55a8347673 (patch) | |
| tree | 779ff3d692eeffd33353d89ad7697a592ab5201e /projects | |
| parent | d758428fe297655e558a86cc6a013fcb1bcc8c7d (diff) | |
| parent | d274fc571c3980b5ac04cbe1416cf2205e6c99f7 (diff) | |
| download | catch3-1.3.0.tar.gz | |
Merged from develop branchv1.3.0
- now v1.3.0
Diffstat (limited to 'projects')
29 files changed, 4121 insertions, 1245 deletions
diff --git a/projects/CMake/CMakeLists.txt b/projects/CMake/CMakeLists.txt index 240e1ebe..960d9fb1 100644 --- a/projects/CMake/CMakeLists.txt +++ b/projects/CMake/CMakeLists.txt @@ -22,7 +22,7 @@ set(SOURCES ${SELF_TEST_DIR}/GeneratorTests.cpp ${SELF_TEST_DIR}/MessageTests.cpp ${SELF_TEST_DIR}/MiscTests.cpp - ${SELF_TEST_DIR}/SectionTrackerTests.cpp + ${SELF_TEST_DIR}/PartTrackerTests.cpp ${SELF_TEST_DIR}/TestMain.cpp ${SELF_TEST_DIR}/TrickyTests.cpp ${SELF_TEST_DIR}/VariadicMacrosTests.cpp diff --git a/projects/SelfTest/ApproxTests.cpp b/projects/SelfTest/ApproxTests.cpp index 1df76155..53656596 100644 --- a/projects/SelfTest/ApproxTests.cpp +++ b/projects/SelfTest/ApproxTests.cpp @@ -16,7 +16,7 @@ TEST_CASE ) { double d = 1.23; - + REQUIRE( d == Approx( 1.23 ) ); REQUIRE( d != Approx( 1.22 ) ); REQUIRE( d != Approx( 1.24 ) ); @@ -34,7 +34,7 @@ TEST_CASE ) { double d = 1.23; - + REQUIRE( d != Approx( 1.231 ) ); REQUIRE( d == Approx( 1.231 ).epsilon( 0.1 ) ); } @@ -71,7 +71,7 @@ TEST_CASE const double dZero = 0; const double dSmall = 0.00001; const double dMedium = 1.234; - + REQUIRE( 1.0f == Approx( 1 ) ); REQUIRE( 0 == Approx( dZero) ); REQUIRE( 0 == Approx( dSmall ).epsilon( 0.001 ) ); @@ -87,14 +87,14 @@ TEST_CASE ) { double d = 1.23; - + Approx approx = Approx::custom().epsilon( 0.005 ); - + REQUIRE( d == approx( 1.23 ) ); REQUIRE( d == approx( 1.22 ) ); REQUIRE( d == approx( 1.24 ) ); REQUIRE( d != approx( 1.25 ) ); - + REQUIRE( approx( d ) == 1.23 ); REQUIRE( approx( d ) == 1.22 ); REQUIRE( approx( d ) == 1.24 ); diff --git a/projects/SelfTest/BDDTests.cpp b/projects/SelfTest/BDDTests.cpp index 3b5c959d..2c8bc249 100644 --- a/projects/SelfTest/BDDTests.cpp +++ b/projects/SelfTest/BDDTests.cpp @@ -30,13 +30,13 @@ SCENARIO( "Vector resizing affects size and capacity", "[vector][bdd][size][capa GIVEN( "an empty vector" ) { std::vector<int> v; REQUIRE( v.size() == 0 ); - + WHEN( "it is made larger" ) { v.resize( 10 ); THEN( "the size and capacity go up" ) { REQUIRE( v.size() == 10 ); REQUIRE( v.capacity() >= 10 ); - + AND_WHEN( "it is made smaller again" ) { v.resize( 5 ); THEN( "the size goes down but the capacity stays the same" ) { @@ -46,7 +46,7 @@ SCENARIO( "Vector resizing affects size and capacity", "[vector][bdd][size][capa } } } - + WHEN( "we reserve more space" ) { v.reserve( 10 ); THEN( "The capacity is increased but the size remains the same" ) { @@ -76,19 +76,19 @@ struct Fixture : d_counter(0) { } - + int counter() { return d_counter++; } - + int d_counter; }; - + } SCENARIO_METHOD(Fixture, - "BDD tests requiring Fixtures to provide commonly-accessed data or methods", + "BDD tests requiring Fixtures to provide commonly-accessed data or methods", "[bdd][fixtures]") { const int before(counter()); GIVEN("No operations precede me") { diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 3fc76122..976a7105 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -356,7 +356,7 @@ due to unexpected exception with message: expected exception ------------------------------------------------------------------------------- -Unexpected custom exceptions can be translated +Non-std exceptions can be translated ------------------------------------------------------------------------------- ExceptionTests.cpp:<line number> ............................................................................... @@ -366,6 +366,16 @@ due to unexpected exception with message: custom exception ------------------------------------------------------------------------------- +Custom std-exceptions can be custom translated +------------------------------------------------------------------------------- +ExceptionTests.cpp:<line number> +............................................................................... + +ExceptionTests.cpp:<line number>: FAILED: +due to unexpected exception with message: + custom std exception + +------------------------------------------------------------------------------- Custom exceptions can be translated when testing for nothrow ------------------------------------------------------------------------------- ExceptionTests.cpp:<line number> @@ -398,6 +408,17 @@ due to unexpected exception with message: 3.14 ------------------------------------------------------------------------------- +Mismatching exception messages failing the test +------------------------------------------------------------------------------- +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 ------------------------------------------------------------------------------- MessageTests.cpp:<line number> @@ -697,6 +718,29 @@ with expansion: "this string contains 'abc' as a substring" equals: "something else" ------------------------------------------------------------------------------- +Matchers can be composed with both && and || - failing +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... + +MiscTests.cpp:<line number>: FAILED: + CHECK_THAT( testStringForMatching() ( Contains( "string" ) || Contains( "different" ) ) && Contains( "random" ) ) +with expansion: + "this string contains 'abc' as a substring" ( ( contains: "string" or + contains: "different" ) and contains: "random" ) + +------------------------------------------------------------------------------- +Matchers can be negated (Not) with the ! operator - failing +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... + +MiscTests.cpp:<line number>: FAILED: + CHECK_THAT( testStringForMatching() !Contains( "substring" ) ) +with expansion: + "this string contains 'abc' as a substring" not contains: "substring" + +------------------------------------------------------------------------------- Nice descriptive name ------------------------------------------------------------------------------- MiscTests.cpp:<line number> @@ -786,6 +830,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: 167 | 124 passed | 42 failed | 1 failed as expected +assertions: 914 | 818 passed | 83 failed | 13 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 744fab67..4f3800b9 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -973,51 +973,51 @@ ConditionTests.cpp:<line number> ConditionTests.cpp:<line number>: PASSED: - REQUIRE( p == __null ) + REQUIRE( p == nullptr ) with expansion: - __null == 0 + NULL == nullptr ConditionTests.cpp:<line number>: PASSED: REQUIRE( p == pNULL ) with expansion: - __null == __null + NULL == NULL ConditionTests.cpp:<line number>: PASSED: - REQUIRE( p != __null ) + REQUIRE( p != nullptr ) with expansion: - 0x<hex digits> != 0 + 0x<hex digits> != nullptr ConditionTests.cpp:<line number>: PASSED: - REQUIRE( cp != __null ) + REQUIRE( cp != nullptr ) with expansion: - 0x<hex digits> != 0 + 0x<hex digits> != nullptr ConditionTests.cpp:<line number>: PASSED: - REQUIRE( cpc != __null ) + REQUIRE( cpc != nullptr ) with expansion: - 0x<hex digits> != 0 + 0x<hex digits> != nullptr ConditionTests.cpp:<line number>: PASSED: - REQUIRE( returnsNull() == __null ) + REQUIRE( returnsNull() == nullptr ) with expansion: - {null string} == 0 + {null string} == nullptr ConditionTests.cpp:<line number>: PASSED: - REQUIRE( returnsConstNull() == __null ) + REQUIRE( returnsConstNull() == nullptr ) with expansion: - {null string} == 0 + {null string} == nullptr ConditionTests.cpp:<line number>: PASSED: - REQUIRE( __null != p ) + REQUIRE( nullptr != p ) with expansion: - 0 != 0x<hex digits> + nullptr != 0x<hex digits> ------------------------------------------------------------------------------- 'Not' checks that should succeed @@ -1217,23 +1217,24 @@ due to unexpected exception with message: expected exception ------------------------------------------------------------------------------- -When unchecked exceptions are thrown, but caught, they do not affect the test +Non-std exceptions can be translated ------------------------------------------------------------------------------- ExceptionTests.cpp:<line number> ............................................................................... - -No assertions in test case 'When unchecked exceptions are thrown, but caught, they do not affect the test' +ExceptionTests.cpp:<line number>: FAILED: +due to unexpected exception with message: + custom exception ------------------------------------------------------------------------------- -Unexpected custom exceptions can be translated +Custom std-exceptions can be custom translated ------------------------------------------------------------------------------- ExceptionTests.cpp:<line number> ............................................................................... ExceptionTests.cpp:<line number>: FAILED: due to unexpected exception with message: - custom exception + custom std exception ------------------------------------------------------------------------------- Custom exceptions can be translated when testing for nothrow @@ -1278,6 +1279,66 @@ PASSED: REQUIRE_THROWS( thisFunctionNotImplemented( 7 ) ) ------------------------------------------------------------------------------- +Exception messages can be tested for + exact match +------------------------------------------------------------------------------- +ExceptionTests.cpp:<line number> +............................................................................... + +ExceptionTests.cpp:<line number>: +PASSED: + REQUIRE_THROWS_WITH( thisThrows(), "expected exception" ) + +------------------------------------------------------------------------------- +Exception messages can be tested for + different case +------------------------------------------------------------------------------- +ExceptionTests.cpp:<line number> +............................................................................... + +ExceptionTests.cpp:<line number>: +PASSED: + REQUIRE_THROWS_WITH( thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) ) + +------------------------------------------------------------------------------- +Exception messages can be tested for + wildcarded +------------------------------------------------------------------------------- +ExceptionTests.cpp:<line number> +............................................................................... + +ExceptionTests.cpp:<line number>: +PASSED: + REQUIRE_THROWS_WITH( thisThrows(), StartsWith( "expected" ) ) + +ExceptionTests.cpp:<line number>: +PASSED: + REQUIRE_THROWS_WITH( thisThrows(), EndsWith( "exception" ) ) + +ExceptionTests.cpp:<line number>: +PASSED: + REQUIRE_THROWS_WITH( thisThrows(), Contains( "except" ) ) + +ExceptionTests.cpp:<line number>: +PASSED: + REQUIRE_THROWS_WITH( thisThrows(), Contains( "exCept", Catch::CaseSensitive::No ) ) + +------------------------------------------------------------------------------- +Mismatching exception messages failing the test +------------------------------------------------------------------------------- +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 ------------------------------------------------------------------------------- GeneratorTests.cpp:<line number> @@ -2608,9 +2669,6 @@ warning: this is a message this is a warning - -No assertions in test case 'INFO and WARN do not abort tests' - ------------------------------------------------------------------------------- SUCCEED counts as a test pass ------------------------------------------------------------------------------- @@ -2857,18 +2915,6 @@ MessageTests.cpp:<line number>: FAILED - but was ok: CHECK_NOFAIL( 1 == 2 ) - -No assertions in test case 'The NO_FAIL macro reports a failure but does not fail the test' - -------------------------------------------------------------------------------- -just info -------------------------------------------------------------------------------- -MessageTests.cpp:<line number> -............................................................................... - - -No assertions in test case 'just info' - ------------------------------------------------------------------------------- just failure ------------------------------------------------------------------------------- @@ -2905,9 +2951,6 @@ MessageTests.cpp:<line number>: warning: toString(p): 0x<hex digits> - -No assertions in test case 'Pointers can be converted to strings' - ------------------------------------------------------------------------------- random SECTION tests s1 @@ -2987,6 +3030,34 @@ with expansion: 1 == 2 ------------------------------------------------------------------------------- +more nested SECTION tests + s1 + s3 +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... + +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( a != b ) +with expansion: + 1 != 2 + +------------------------------------------------------------------------------- +more nested SECTION tests + s1 + s4 +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... + +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( a < b ) +with expansion: + 1 < 2 + +------------------------------------------------------------------------------- even more nested SECTION tests c d (leaf) @@ -2994,8 +3065,8 @@ even more nested SECTION tests MiscTests.cpp:<line number> ............................................................................... - -No assertions in section 'd (leaf)' +MiscTests.cpp:<line number>: +PASSED: ------------------------------------------------------------------------------- even more nested SECTION tests @@ -3005,8 +3076,8 @@ even more nested SECTION tests MiscTests.cpp:<line number> ............................................................................... - -No assertions in section 'e (leaf)' +MiscTests.cpp:<line number>: +PASSED: ------------------------------------------------------------------------------- even more nested SECTION tests @@ -3015,8 +3086,8 @@ even more nested SECTION tests MiscTests.cpp:<line number> ............................................................................... - -No assertions in section 'f (leaf)' +MiscTests.cpp:<line number>: +PASSED: ------------------------------------------------------------------------------- looped SECTION tests @@ -3097,15 +3168,6 @@ with message: A string sent directly to stdout A string sent directly to stderr ------------------------------------------------------------------------------- -Sends stuff to stdout and stderr -------------------------------------------------------------------------------- -MiscTests.cpp:<line number> -............................................................................... - - -No assertions in test case 'Sends stuff to stdout and stderr' - -------------------------------------------------------------------------------- null strings ------------------------------------------------------------------------------- MiscTests.cpp:<line number> @@ -3113,13 +3175,13 @@ MiscTests.cpp:<line number> MiscTests.cpp:<line number>: PASSED: - REQUIRE( makeString( false ) != static_cast<char*>(__null) ) + REQUIRE( makeString( false ) != static_cast<char*>(nullptr) ) with expansion: "valid string" != {null string} MiscTests.cpp:<line number>: PASSED: - REQUIRE( makeString( true ) == static_cast<char*>(__null) ) + REQUIRE( makeString( true ) == static_cast<char*>(nullptr) ) with expansion: {null string} == {null string} @@ -3198,8 +3260,8 @@ xmlentitycheck MiscTests.cpp:<line number> ............................................................................... - -No assertions in section 'embedded xml' +MiscTests.cpp:<line number>: +PASSED: ------------------------------------------------------------------------------- xmlentitycheck @@ -3208,8 +3270,8 @@ xmlentitycheck MiscTests.cpp:<line number> ............................................................................... - -No assertions in section 'encoded chars' +MiscTests.cpp:<line number>: +PASSED: ------------------------------------------------------------------------------- send a single char to INFO @@ -3316,7 +3378,7 @@ MiscTests.cpp:<line number> MiscTests.cpp:<line number>: PASSED: - REQUIRE_THAT( "" Equals(__null) ) + REQUIRE_THAT( "" Equals(nullptr) ) with expansion: "" equals: "" @@ -3367,80 +3429,131 @@ with expansion: 'abc' as a substring" ------------------------------------------------------------------------------- -Factorials are computed +Matchers can be (AllOf) composed with the && operator ------------------------------------------------------------------------------- MiscTests.cpp:<line number> ............................................................................... MiscTests.cpp:<line number>: PASSED: - REQUIRE( Factorial(0) == 1 ) + CHECK_THAT( testStringForMatching() Contains( "string" ) && Contains( "abc" ) && Contains( "substring" ) && Contains( "contains" ) ) with expansion: - 1 == 1 + "this string contains 'abc' as a substring" ( contains: "string" and + contains: "abc" and contains: "substring" and contains: "contains" ) -MiscTests.cpp:<line number>: -PASSED: - REQUIRE( Factorial(1) == 1 ) -with expansion: - 1 == 1 +------------------------------------------------------------------------------- +Matchers can be (AnyOf) composed with the || operator +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... MiscTests.cpp:<line number>: PASSED: - REQUIRE( Factorial(2) == 2 ) + CHECK_THAT( testStringForMatching() Contains( "string" ) || Contains( "different" ) || Contains( "random" ) ) with expansion: - 2 == 2 + "this string contains 'abc' as a substring" ( contains: "string" or contains: + "different" or contains: "random" ) MiscTests.cpp:<line number>: PASSED: - REQUIRE( Factorial(3) == 6 ) + CHECK_THAT( testStringForMatching2() Contains( "string" ) || Contains( "different" ) || Contains( "random" ) ) with expansion: - 6 == 6 + "some completely different text that contains one common word" ( contains: + "string" or contains: "different" or contains: "random" ) + +------------------------------------------------------------------------------- +Matchers can be composed with both && and || +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... MiscTests.cpp:<line number>: PASSED: - REQUIRE( Factorial(10) == 3628800 ) + CHECK_THAT( testStringForMatching() ( Contains( "string" ) || Contains( "different" ) ) && Contains( "substring" ) ) with expansion: - 3628800 (0x<hex digits>) == 3628800 (0x<hex digits>) + "this string contains 'abc' as a substring" ( ( contains: "string" or + contains: "different" ) and contains: "substring" ) ------------------------------------------------------------------------------- -An empty test with no assertions +Matchers can be composed with both && and || - failing ------------------------------------------------------------------------------- MiscTests.cpp:<line number> ............................................................................... - -No assertions in test case 'An empty test with no assertions' +MiscTests.cpp:<line number>: FAILED: + CHECK_THAT( testStringForMatching() ( Contains( "string" ) || Contains( "different" ) ) && Contains( "random" ) ) +with expansion: + "this string contains 'abc' as a substring" ( ( contains: "string" or + contains: "different" ) and contains: "random" ) ------------------------------------------------------------------------------- -Nice descriptive name +Matchers can be negated (Not) with the ! operator ------------------------------------------------------------------------------- MiscTests.cpp:<line number> ............................................................................... MiscTests.cpp:<line number>: -warning: - This one ran +PASSED: + CHECK_THAT( testStringForMatching() !Contains( "different" ) ) +with expansion: + "this string contains 'abc' as a substring" not contains: "different" +------------------------------------------------------------------------------- +Matchers can be negated (Not) with the ! operator - failing +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... -No assertions in test case 'Nice descriptive name' +MiscTests.cpp:<line number>: FAILED: + CHECK_THAT( testStringForMatching() !Contains( "substring" ) ) +with expansion: + "this string contains 'abc' as a substring" not contains: "substring" ------------------------------------------------------------------------------- -first tag +Factorials are computed ------------------------------------------------------------------------------- MiscTests.cpp:<line number> ............................................................................... +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( Factorial(0) == 1 ) +with expansion: + 1 == 1 + +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( Factorial(1) == 1 ) +with expansion: + 1 == 1 -No assertions in test case 'first tag' +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( Factorial(2) == 2 ) +with expansion: + 2 == 2 + +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( Factorial(3) == 6 ) +with expansion: + 6 == 6 + +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( Factorial(10) == 3628800 ) +with expansion: + 3628800 (0x<hex digits>) == 3628800 (0x<hex digits>) ------------------------------------------------------------------------------- -second tag +Nice descriptive name ------------------------------------------------------------------------------- MiscTests.cpp:<line number> ............................................................................... - -No assertions in test case 'second tag' +MiscTests.cpp:<line number>: +warning: + This one ran ------------------------------------------------------------------------------- vectors can be sized and resized @@ -3703,6 +3816,142 @@ with expansion: ""wide load"" == ""wide load"" ------------------------------------------------------------------------------- +XmlEncode + normal string +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... + +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( encode( "normal string" ) == "normal string" ) +with expansion: + "normal string" == "normal string" + +------------------------------------------------------------------------------- +XmlEncode + empty string +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... + +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( encode( "" ) == "" ) +with expansion: + "" == "" + +------------------------------------------------------------------------------- +XmlEncode + string with ampersand +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... + +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( encode( "smith & jones" ) == "smith & jones" ) +with expansion: + "smith & jones" == "smith & jones" + +------------------------------------------------------------------------------- +XmlEncode + string with less-than +------------------------------------------------------------------------------- +MiscTests.cpp:<line number> +............................................................................... + +MiscTests.cpp:<line number>: +PASSED: + REQUIRE( encode( "smith < jones" ) == "smith < jones" ) +with expansion: |