diff options
| author | Uriel García Rivas | 2020-12-07 17:23:54 -0600 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-12-27 20:20:55 +0100 |
| commit | 552af8920df24e16738dbb1cb6b46dd52de7804c (patch) | |
| tree | c336ff726945350d6943488dbf1102be43246533 /tests/SelfTest | |
| parent | ce54ec185f69e32661efdcb4659f892415316b0e (diff) | |
| download | catch3-552af8920df24e16738dbb1cb6b46dd52de7804c.tar.gz | |
Added AnyMatch, AllMatch and NoneMatch
Diffstat (limited to 'tests/SelfTest')
| -rw-r--r-- | tests/SelfTest/Baselines/automake.sw.approved.txt | 1 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/compact.sw.approved.txt | 18 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/console.std.approved.txt | 4 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/console.sw.approved.txt | 127 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/junit.sw.approved.txt | 5 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/sonarqube.sw.approved.txt | 3 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/tap.sw.approved.txt | 38 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/teamcity.sw.approved.txt | 2 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/xml.sw.approved.txt | 164 | ||||
| -rw-r--r-- | tests/SelfTest/UsageTests/MatchersRanges.tests.cpp | 55 |
10 files changed, 407 insertions, 10 deletions
diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index 45e62ac5..4b51b804 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -238,6 +238,7 @@ Message from section two :test-result: FAIL Unexpected exceptions can be translated :test-result: PASS Upcasting special member functions :test-result: PASS Usage of the SizeIs range matcher +:test-result: PASS Usage of the quantifiers matchers :test-result: PASS Use a custom approx :test-result: PASS Variadic macros :test-result: PASS Vector Approx matcher diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index bbb50a93..a50cc6e3 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -1668,6 +1668,24 @@ MatchersRanges.tests.cpp:<line number>: passed: arr, !SizeIs(!Lt(3)) for: { 0, 0 MatchersRanges.tests.cpp:<line number>: passed: map, SizeIs(3) for: { {?}, {?}, {?} } has size == 3 MatchersRanges.tests.cpp:<line number>: passed: unrelated::ADL_size{}, SizeIs(12) for: {?} has size == 12 MatchersRanges.tests.cpp:<line number>: passed: has_size{}, SizeIs(13) for: {?} has size == 13 +MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, AllMatch(Contains(0)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match contains element 0 +MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, AllMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match has size == 5 +MatchersRanges.tests.cpp:<line number>: passed: string_vector, AllMatch(StartsWith("C")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match starts with: "C" +MatchersRanges.tests.cpp:<line number>: passed: string_vector, AllMatch(EndsWith("+")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match ends with: "+" +MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, AllMatch(!IsEmpty()) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match not is empty +MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, AllMatch(SizeIs(2)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match has size == 2 +MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, AnyMatch(Contains(-2)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match contains element -2 +MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, AnyMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match has size == 5 +MatchersRanges.tests.cpp:<line number>: passed: string_vector, AnyMatch(StartsWith("CMak")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match starts with: "CMak" +MatchersRanges.tests.cpp:<line number>: passed: string_vector, AnyMatch(EndsWith("++")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match ends with: "++" +MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, AnyMatch(Contains(4)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match contains element 4 +MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, AnyMatch(SizeIs(2)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match has size == 2 +MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, NoneMatch(Contains(-6)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match contains element -6 +MatchersRanges.tests.cpp:<line number>: passed: int_arr_arr, NoneMatch(SizeIs(42)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match has size == 42 +MatchersRanges.tests.cpp:<line number>: passed: string_vector, NoneMatch(StartsWith("abd")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match starts with: "abd" +MatchersRanges.tests.cpp:<line number>: passed: string_vector, NoneMatch(EndsWith("#!--")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match ends with: "#!--" +MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, NoneMatch(IsEmpty()) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match is empty +MatchersRanges.tests.cpp:<line number>: passed: int_vectors_list, NoneMatch(SizeIs(3)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match has size == 3 Approx.tests.cpp:<line number>: passed: d == approx( 1.23 ) for: 1.23 == Approx( 1.23 ) Approx.tests.cpp:<line number>: passed: d == approx( 1.22 ) for: 1.23 == Approx( 1.22 ) Approx.tests.cpp:<line number>: passed: d == approx( 1.24 ) for: 1.23 == Approx( 1.24 ) diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 2440a763..acd627ee 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1380,6 +1380,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 351 | 277 passed | 70 failed | 4 failed as expected -assertions: 1992 | 1840 passed | 131 failed | 21 failed as expected +test cases: 352 | 278 passed | 70 failed | 4 failed as expected +assertions: 2010 | 1858 passed | 131 failed | 21 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index d8a60b83..2dd42716 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -12287,6 +12287,129 @@ with expansion: {?} has size == 13 ------------------------------------------------------------------------------- +Usage of the quantifiers matchers + Usage of the AllMatch range matcher +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp:<line number> +............................................................................... + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_arr_arr, AllMatch(Contains(0)) ) +with expansion: + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 + }, { 1, 0, 0, -1, 5 } } all match contains element 0 + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_arr_arr, AllMatch(SizeIs(5)) ) +with expansion: + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 + }, { 1, 0, 0, -1, 5 } } all match has size == 5 + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( string_vector, AllMatch(StartsWith("C")) ) +with expansion: + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match starts with: + "C" + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( string_vector, AllMatch(EndsWith("+")) ) +with expansion: + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match ends with: + "+" + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_vectors_list, AllMatch(!IsEmpty()) ) +with expansion: + { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match not is empty + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_vectors_list, AllMatch(SizeIs(2)) ) +with expansion: + { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match has size == 2 + +------------------------------------------------------------------------------- +Usage of the quantifiers matchers + Usage of the AnyMatch range matcher +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp:<line number> +............................................................................... + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_arr_arr, AnyMatch(Contains(-2)) ) +with expansion: + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 + }, { 1, 0, 0, -1, 5 } } any match contains element -2 + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_arr_arr, AnyMatch(SizeIs(5)) ) +with expansion: + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 + }, { 1, 0, 0, -1, 5 } } any match has size == 5 + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( string_vector, AnyMatch(StartsWith("CMak")) ) +with expansion: + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match starts with: + "CMak" + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( string_vector, AnyMatch(EndsWith("++")) ) +with expansion: + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match ends with: + "++" + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_vectors_list, AnyMatch(Contains(4)) ) +with expansion: + { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match contains element 4 + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_vectors_list, AnyMatch(SizeIs(2)) ) +with expansion: + { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match has size == 2 + +------------------------------------------------------------------------------- +Usage of the quantifiers matchers + Usage of the NoneMatch range matcher +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp:<line number> +............................................................................... + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_arr_arr, NoneMatch(Contains(-6)) ) +with expansion: + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 + }, { 1, 0, 0, -1, 5 } } none match contains element -6 + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_arr_arr, NoneMatch(SizeIs(42)) ) +with expansion: + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 + }, { 1, 0, 0, -1, 5 } } none match has size == 42 + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( string_vector, NoneMatch(StartsWith("abd")) ) +with expansion: + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match starts + with: "abd" + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( string_vector, NoneMatch(EndsWith("#!--")) ) +with expansion: + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match ends with: + "#!--" + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_vectors_list, NoneMatch(IsEmpty()) ) +with expansion: + { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match is empty + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( int_vectors_list, NoneMatch(SizeIs(3)) ) +with expansion: + { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match has size == 3 + +------------------------------------------------------------------------------- Use a custom approx ------------------------------------------------------------------------------- Approx.tests.cpp:<line number> @@ -15681,6 +15804,6 @@ Misc.tests.cpp:<line number> Misc.tests.cpp:<line number>: PASSED: =============================================================================== -test cases: 351 | 261 passed | 86 failed | 4 failed as expected -assertions: 2009 | 1840 passed | 148 failed | 21 failed as expected +test cases: 352 | 262 passed | 86 failed | 4 failed as expected +assertions: 2027 | 1858 passed | 148 failed | 21 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 21464c62..214e03e8 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuitesloose text artifact > - <testsuite name="<exe-name>" errors="17" failures="132" tests="2010" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="132" tests="2028" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <properties> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/> <property name="random-seed" value="1"/> @@ -1283,6 +1283,9 @@ Exception.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Some with stdlib containers" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Type requires ADL found size free function" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher/Type has size member" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="Usage of the quantifiers matchers/Usage of the AllMatch range matcher" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="Usage of the quantifiers matchers/Usage of the AnyMatch range matcher" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="Usage of the quantifiers matchers/Usage of the NoneMatch range matcher" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Use a custom approx" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Variadic macros/Section with one argument" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Vector Approx matcher/Empty vector is roughly equal to an empty vector" time="{duration}" status="run"/> diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 96ebb9a0..ed78a3a9 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -1268,6 +1268,9 @@ Matchers.tests.cpp:<line number> <testCase name="Usage of the SizeIs range matcher/Some with stdlib containers" duration="{duration}"/> <testCase name="Usage of the SizeIs range matcher/Type requires ADL found size free function" duration="{duration}"/> <testCase name="Usage of the SizeIs range matcher/Type has size member" duration="{duration}"/> + <testCase name="Usage of the quantifiers matchers/Usage of the AllMatch range matcher" duration="{duration}"/> + <testCase name="Usage of the quantifiers matchers/Usage of the AnyMatch range matcher" duration="{duration}"/> + <testCase name="Usage of the quantifiers matchers/Usage of the NoneMatch range matcher" duration="{duration}"/> </file> <file path="tests/<exe-name>/UsageTests/Message.tests.cpp"> <testCase name="#1455 - INFO and WARN can start with a linebreak" duration="{duration}"/> diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index c07c22bd..3b32341b 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -3179,6 +3179,42 @@ ok {test-number} - map, SizeIs(3) for: { {?}, {?}, {?} } has size == 3 ok {test-number} - unrelated::ADL_size{}, SizeIs(12) for: {?} has size == 12 # Usage of the SizeIs range matcher ok {test-number} - has_size{}, SizeIs(13) for: {?} has size == 13 +# Usage of the quantifiers matchers +ok {test-number} - int_arr_arr, AllMatch(Contains(0)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match contains element 0 +# Usage of the quantifiers matchers +ok {test-number} - int_arr_arr, AllMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match has size == 5 +# Usage of the quantifiers matchers +ok {test-number} - string_vector, AllMatch(StartsWith("C")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match starts with: "C" +# Usage of the quantifiers matchers +ok {test-number} - string_vector, AllMatch(EndsWith("+")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match ends with: "+" +# Usage of the quantifiers matchers +ok {test-number} - int_vectors_list, AllMatch(!IsEmpty()) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match not is empty +# Usage of the quantifiers matchers +ok {test-number} - int_vectors_list, AllMatch(SizeIs(2)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match has size == 2 +# Usage of the quantifiers matchers +ok {test-number} - int_arr_arr, AnyMatch(Contains(-2)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match contains element -2 +# Usage of the quantifiers matchers +ok {test-number} - int_arr_arr, AnyMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match has size == 5 +# Usage of the quantifiers matchers +ok {test-number} - string_vector, AnyMatch(StartsWith("CMak")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match starts with: "CMak" +# Usage of the quantifiers matchers +ok {test-number} - string_vector, AnyMatch(EndsWith("++")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match ends with: "++" +# Usage of the quantifiers matchers +ok {test-number} - int_vectors_list, AnyMatch(Contains(4)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match contains element 4 +# Usage of the quantifiers matchers +ok {test-number} - int_vectors_list, AnyMatch(SizeIs(2)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match has size == 2 +# Usage of the quantifiers matchers +ok {test-number} - int_arr_arr, NoneMatch(Contains(-6)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match contains element -6 +# Usage of the quantifiers matchers +ok {test-number} - int_arr_arr, NoneMatch(SizeIs(42)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match has size == 42 +# Usage of the quantifiers matchers +ok {test-number} - string_vector, NoneMatch(StartsWith("abd")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match starts with: "abd" +# Usage of the quantifiers matchers +ok {test-number} - string_vector, NoneMatch(EndsWith("#!--")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match ends with: "#!--" +# Usage of the quantifiers matchers +ok {test-number} - int_vectors_list, NoneMatch(IsEmpty()) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match is empty +# Usage of the quantifiers matchers +ok {test-number} - int_vectors_list, NoneMatch(SizeIs(3)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match has size == 3 # Use a custom approx ok {test-number} - d == approx( 1.23 ) for: 1.23 == Approx( 1.23 ) # Use a custom approx @@ -4010,5 +4046,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2009 +1..2027 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index b9da3591..09b426b7 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -579,6 +579,8 @@ Exception.tests.cpp:<line number>|nunexpected exception with message:|n "3.14"' ##teamcity[testFinished name='Upcasting special member functions' duration="{duration}"] ##teamcity[testStarted name='Usage of the SizeIs range matcher'] ##teamcity[testFinished name='Usage of the SizeIs range matcher' duration="{duration}"] +##teamcity[testStarted name='Usage of the quantifiers matchers'] +##teamcity[testFinished name='Usage of the quantifiers matchers' duration="{duration}"] ##teamcity[testStarted name='Use a custom approx'] ##teamcity[testFinished name='Use a custom approx' duration="{duration}"] ##teamcity[testStarted name='Variadic macros'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index 928d2a70..a9de7c7e 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -14620,6 +14620,162 @@ There is no extra whitespace here </Section> <OverallResult success="true"/> </TestCase> + <TestCase name="Usage of the quantifiers matchers" tags="[matchers][quantifiers][templated]" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Section name="Usage of the AllMatch range matcher" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_arr_arr, AllMatch(Contains(0)) + </Original> + <Expanded> + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match contains element 0 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_arr_arr, AllMatch(SizeIs(5)) + </Original> + <Expanded> + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match has size == 5 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + string_vector, AllMatch(StartsWith("C")) + </Original> + <Expanded> + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match starts with: "C" + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + string_vector, AllMatch(EndsWith("+")) + </Original> + <Expanded> + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match ends with: "+" + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_vectors_list, AllMatch(!IsEmpty()) + </Original> + <Expanded> + { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match not is empty + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_vectors_list, AllMatch(SizeIs(2)) + </Original> + <Expanded> + { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match has size == 2 + </Expanded> + </Expression> + <OverallResults successes="6" failures="0" expectedFailures="0"/> + </Section> + <Section name="Usage of the AnyMatch range matcher" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_arr_arr, AnyMatch(Contains(-2)) + </Original> + <Expanded> + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match contains element -2 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_arr_arr, AnyMatch(SizeIs(5)) + </Original> + <Expanded> + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } any match has size == 5 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + string_vector, AnyMatch(StartsWith("CMak")) + </Original> + <Expanded> + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match starts with: "CMak" + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + string_vector, AnyMatch(EndsWith("++")) + </Original> + <Expanded> + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match ends with: "++" + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_vectors_list, AnyMatch(Contains(4)) + </Original> + <Expanded> + { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match contains element 4 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_vectors_list, AnyMatch(SizeIs(2)) + </Original> + <Expanded> + { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match has size == 2 + </Expanded> + </Expression> + <OverallResults successes="6" failures="0" expectedFailures="0"/> + </Section> + <Section name="Usage of the NoneMatch range matcher" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_arr_arr, NoneMatch(Contains(-6)) + </Original> + <Expanded> + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match contains element -6 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_arr_arr, NoneMatch(SizeIs(42)) + </Original> + <Expanded> + { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } none match has size == 42 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + string_vector, NoneMatch(StartsWith("abd")) + </Original> + <Expanded> + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match starts with: "abd" + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + string_vector, NoneMatch(EndsWith("#!--")) + </Original> + <Expanded> + { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match ends with: "#!--" + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_vectors_list, NoneMatch(IsEmpty()) + </Original> + <Expanded> + { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match is empty + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + int_vectors_list, NoneMatch(SizeIs(3)) + </Original> + <Expanded> + { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match has size == 3 + </Expanded> + </Expression> + <OverallResults successes="6" failures="0" expectedFailures="0"/> + </Section> + <OverallResult success="true"/> + </TestCase> <TestCase name="Use a custom approx" tags="[Approx][custom]" filename="tests/<exe-name>/UsageTests/Approx.tests.cpp" > <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/UsageTests/Approx.tests.cpp" > <Original> @@ -18598,9 +18754,9 @@ loose text artifact </Section> <OverallResult success="true"/> </TestCase> - <OverallResults successes="1840" failures="149" expectedFailures="21"/> - <OverallResultsCases successes="261" failures="86" expectedFailures="4"/> + <OverallResults successes="1858" failures="149" expectedFailures="21"/> + <OverallResultsCases successes="262" failures="86" expectedFailures="4"/> </Group> - <OverallResults successes="1840" failures="148" expectedFailures="21"/> - <OverallResultsCases successes="261" failures="86" expectedFailures="4"/> + <OverallResults successes="1858" failures="148" expectedFailures="21"/> + <OverallResultsCases successes="262" failures="86" expectedFailures="4"/> </Catch> diff --git a/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp b/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp index 505057d3..13b546e3 100644 --- a/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp +++ b/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp @@ -5,6 +5,8 @@ #include <catch2/matchers/catch_matchers_container_properties.hpp> #include <catch2/matchers/catch_matchers_contains.hpp> #include <catch2/matchers/catch_matchers_floating_point.hpp> +#include <catch2/matchers/catch_matchers_quantifiers.hpp> +#include <catch2/matchers/catch_matchers_string.hpp> #include <array> #include <cmath> @@ -217,3 +219,56 @@ TEST_CASE("Usage of the SizeIs range matcher", "[matchers][templated][size]") { REQUIRE_THAT(has_size{}, SizeIs(13)); } } + +TEST_CASE("Usage of the quantifiers matchers", "[matchers][templated][quantifiers]") { + using Catch::Matchers::AllMatch; + using Catch::Matchers::AnyMatch; + using Catch::Matchers::Contains; + using Catch::Matchers::EndsWith; + using Catch::Matchers::IsEmpty; + using Catch::Matchers::NoneMatch; + using Catch::Matchers::SizeIs; + using Catch::Matchers::StartsWith; + std::array<std::array<int, 5>, 5> int_arr_arr{{ + {{ 0, 1, 2, 3, 5 }}, + {{ 4,-3,-2, 5, 0 }}, + {{ 0, 0, 0, 5, 0 }}, + {{ 0,-5, 0, 5, 0 }}, + {{ 1, 0, 0,-1, 5 }} + }}; + std::vector<std::string> string_vector{ "Command+", "Catch2+", "CMake+", "C++", "Console+" }; + std::list<std::vector<int>> int_vectors_list{ { 1, 2 }, { 3, 4 }, { 5, 6 } }; + + SECTION("Usage of the AllMatch range matcher") { + REQUIRE_THAT(int_arr_arr, AllMatch(Contains(0))); + REQUIRE_THAT(int_arr_arr, AllMatch(SizeIs(5))); + + REQUIRE_THAT(string_vector, AllMatch(StartsWith("C"))); + REQUIRE_THAT(string_vector, AllMatch(EndsWith("+"))); + + REQUIRE_THAT(int_vectors_list, AllMatch(!IsEmpty())); + REQUIRE_THAT(int_vectors_list, AllMatch(SizeIs(2))); + } + + SECTION("Usage of the AnyMatch range matcher") { + REQUIRE_THAT(int_arr_arr, AnyMatch(Contains(-2))); + REQUIRE_THAT(int_arr_arr, AnyMatch(SizeIs(5))); + + REQUIRE_THAT(string_vector, AnyMatch(StartsWith("CMak"))); + REQUIRE_THAT(string_vector, AnyMatch(EndsWith("++"))); + + REQUIRE_THAT(int_vectors_list, AnyMatch(Contains(4))); + REQUIRE_THAT(int_vectors_list, AnyMatch(SizeIs(2))); + } + + SECTION("Usage of the NoneMatch range matcher") { + REQUIRE_THAT(int_arr_arr, NoneMatch(Contains(-6))); + REQUIRE_THAT(int_arr_arr, NoneMatch(SizeIs(42))); + + REQUIRE_THAT(string_vector, NoneMatch(StartsWith("abd"))); + REQUIRE_THAT(string_vector, NoneMatch(EndsWith("#!--"))); + + REQUIRE_THAT(int_vectors_list, NoneMatch(IsEmpty())); + REQUIRE_THAT(int_vectors_list, NoneMatch(SizeIs(3))); + } +} |