diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index 4b51b804..87f2a189 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -237,8 +237,10 @@ Message from section two :test-result: PASS Trim strings :test-result: FAIL Unexpected exceptions can be translated :test-result: PASS Upcasting special member functions +:test-result: PASS Usage of AllMatch range matcher +:test-result: PASS Usage of AnyMatch range matcher +:test-result: PASS Usage of NoneMatch range matcher :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 a50cc6e3..1b6fb40c 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -1659,6 +1659,51 @@ There is no extra whitespace here Exception.tests.cpp:: failed: unexpected exception with message: '3.14' UniquePtr.tests.cpp:: passed: bptr->i == 3 for: 3 == 3 UniquePtr.tests.cpp:: passed: bptr->i == 3 for: 3 == 3 +MatchersRanges.tests.cpp:: passed: data, 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:: passed: data, !AllMatch(Contains(0) && Contains(1)) 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 } } not all match ( contains element 0 and contains element 1 ) +MatchersRanges.tests.cpp:: passed: needs_adl, AllMatch( Predicate( []( int elem ) { return elem < 6; } ) ) for: { 1, 2, 3, 4, 5 } all match matches undescribed predicate +MatchersRanges.tests.cpp:: passed: mocked, allMatch for: { 1, 2, 3, 4, 5 } all match matches undescribed predicate +MatchersRanges.tests.cpp:: passed: mocked.derefed[0] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[1] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[2] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[3] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[4] for: true +MatchersRanges.tests.cpp:: passed: mocked, !allMatch for: { 1, 2, 3, 4, 5 } not all match matches undescribed predicate +MatchersRanges.tests.cpp:: passed: mocked.derefed[0] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[1] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[2] for: true +MatchersRanges.tests.cpp:: passed: !(mocked.derefed[3]) for: !false +MatchersRanges.tests.cpp:: passed: !(mocked.derefed[4]) for: !false +MatchersRanges.tests.cpp:: passed: data, 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:: passed: data, !AnyMatch(Contains(0) && Contains(10)) 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 } } not any match ( contains element 0 and contains element 10 ) +MatchersRanges.tests.cpp:: passed: needs_adl, AnyMatch( Predicate( []( int elem ) { return elem < 3; } ) ) for: { 1, 2, 3, 4, 5 } any match matches undescribed predicate +MatchersRanges.tests.cpp:: passed: mocked, !anyMatch for: { 1, 2, 3, 4, 5 } not any match matches undescribed predicate +MatchersRanges.tests.cpp:: passed: mocked.derefed[0] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[1] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[2] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[3] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[4] for: true +MatchersRanges.tests.cpp:: passed: mocked, anyMatch for: { 1, 2, 3, 4, 5 } any match matches undescribed predicate +MatchersRanges.tests.cpp:: passed: mocked.derefed[0] for: true +MatchersRanges.tests.cpp:: passed: !(mocked.derefed[1]) for: !false +MatchersRanges.tests.cpp:: passed: !(mocked.derefed[2]) for: !false +MatchersRanges.tests.cpp:: passed: !(mocked.derefed[3]) for: !false +MatchersRanges.tests.cpp:: passed: !(mocked.derefed[4]) for: !false +MatchersRanges.tests.cpp:: passed: data, NoneMatch(SizeIs(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 has size == 6 +MatchersRanges.tests.cpp:: passed: data, !NoneMatch(Contains(0) && Contains(1)) 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 } } not none match ( contains element 0 and contains element 1 ) +MatchersRanges.tests.cpp:: passed: needs_adl, NoneMatch( Predicate( []( int elem ) { return elem > 6; } ) ) for: { 1, 2, 3, 4, 5 } none match matches undescribed predicate +MatchersRanges.tests.cpp:: passed: mocked, noneMatch for: { 1, 2, 3, 4, 5 } none match matches undescribed predicate +MatchersRanges.tests.cpp:: passed: mocked.derefed[0] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[1] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[2] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[3] for: true +MatchersRanges.tests.cpp:: passed: mocked.derefed[4] for: true +MatchersRanges.tests.cpp:: passed: mocked, !noneMatch for: { 1, 2, 3, 4, 5 } not none match matches undescribed predicate +MatchersRanges.tests.cpp:: passed: mocked.derefed[0] for: true +MatchersRanges.tests.cpp:: passed: !(mocked.derefed[1]) for: !false +MatchersRanges.tests.cpp:: passed: !(mocked.derefed[2]) for: !false +MatchersRanges.tests.cpp:: passed: !(mocked.derefed[3]) for: !false +MatchersRanges.tests.cpp:: passed: !(mocked.derefed[4]) for: !false MatchersRanges.tests.cpp:: passed: empty_vec, SizeIs(0) for: { } has size == 0 MatchersRanges.tests.cpp:: passed: empty_vec, !SizeIs(2) for: { } not has size == 2 MatchersRanges.tests.cpp:: passed: empty_vec, SizeIs(Lt(2)) for: { } size matches is less than 2 @@ -1668,24 +1713,6 @@ MatchersRanges.tests.cpp:: passed: arr, !SizeIs(!Lt(3)) for: { 0, 0 MatchersRanges.tests.cpp:: passed: map, SizeIs(3) for: { {?}, {?}, {?} } has size == 3 MatchersRanges.tests.cpp:: passed: unrelated::ADL_size{}, SizeIs(12) for: {?} has size == 12 MatchersRanges.tests.cpp:: passed: has_size{}, SizeIs(13) for: {?} has size == 13 -MatchersRanges.tests.cpp:: 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:: 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:: passed: string_vector, AllMatch(StartsWith("C")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match starts with: "C" -MatchersRanges.tests.cpp:: passed: string_vector, AllMatch(EndsWith("+")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match ends with: "+" -MatchersRanges.tests.cpp:: passed: int_vectors_list, AllMatch(!IsEmpty()) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match not is empty -MatchersRanges.tests.cpp:: passed: int_vectors_list, AllMatch(SizeIs(2)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match has size == 2 -MatchersRanges.tests.cpp:: 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:: 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:: passed: string_vector, AnyMatch(StartsWith("CMak")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match starts with: "CMak" -MatchersRanges.tests.cpp:: passed: string_vector, AnyMatch(EndsWith("++")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match ends with: "++" -MatchersRanges.tests.cpp:: passed: int_vectors_list, AnyMatch(Contains(4)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match contains element 4 -MatchersRanges.tests.cpp:: passed: int_vectors_list, AnyMatch(SizeIs(2)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match has size == 2 -MatchersRanges.tests.cpp:: 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:: 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:: passed: string_vector, NoneMatch(StartsWith("abd")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match starts with: "abd" -MatchersRanges.tests.cpp:: passed: string_vector, NoneMatch(EndsWith("#!--")) for: { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match ends with: "#!--" -MatchersRanges.tests.cpp:: passed: int_vectors_list, NoneMatch(IsEmpty()) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match is empty -MatchersRanges.tests.cpp:: passed: int_vectors_list, NoneMatch(SizeIs(3)) for: { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match has size == 3 Approx.tests.cpp:: passed: d == approx( 1.23 ) for: 1.23 == Approx( 1.23 ) Approx.tests.cpp:: passed: d == approx( 1.22 ) for: 1.23 == Approx( 1.22 ) Approx.tests.cpp:: 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 acd627ee..149bed95 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: 352 | 278 passed | 70 failed | 4 failed as expected -assertions: 2010 | 1858 passed | 131 failed | 21 failed as expected +test cases: 354 | 280 passed | 70 failed | 4 failed as expected +assertions: 2037 | 1885 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 2dd42716..08b69583 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -12220,6 +12220,330 @@ UniquePtr.tests.cpp:: PASSED: with expansion: 3 == 3 +------------------------------------------------------------------------------- +Usage of AllMatch range matcher + Basic usage +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( data, 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:: PASSED: + REQUIRE_THAT( data, !AllMatch(Contains(0) && Contains(1)) ) +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 } } not all match ( contains element 0 and contains + element 1 ) + +------------------------------------------------------------------------------- +Usage of AllMatch range matcher + Type requires ADL found begin and end +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( needs_adl, AllMatch( Predicate( []( int elem ) { return elem < 6; } ) ) ) +with expansion: + { 1, 2, 3, 4, 5 } all match matches undescribed predicate + +------------------------------------------------------------------------------- +Usage of AllMatch range matcher + Shortcircuiting + All are read +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( mocked, allMatch ) +with expansion: + { 1, 2, 3, 4, 5 } all match matches undescribed predicate + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[0] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[1] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[2] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[3] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[4] ) +with expansion: + true + +------------------------------------------------------------------------------- +Usage of AllMatch range matcher + Shortcircuiting + Short-circuited +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( mocked, !allMatch ) +with expansion: + { 1, 2, 3, 4, 5 } not all match matches undescribed predicate + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[0] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[1] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[2] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_FALSE( mocked.derefed[3] ) +with expansion: + !false + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_FALSE( mocked.derefed[4] ) +with expansion: + !false + +------------------------------------------------------------------------------- +Usage of AnyMatch range matcher + Basic usage +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( data, 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:: PASSED: + REQUIRE_THAT( data, !AnyMatch(Contains(0) && Contains(10)) ) +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 } } not any match ( contains element 0 and contains + element 10 ) + +------------------------------------------------------------------------------- +Usage of AnyMatch range matcher + Type requires ADL found begin and end +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( needs_adl, AnyMatch( Predicate( []( int elem ) { return elem < 3; } ) ) ) +with expansion: + { 1, 2, 3, 4, 5 } any match matches undescribed predicate + +------------------------------------------------------------------------------- +Usage of AnyMatch range matcher + Shortcircuiting + All are read +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( mocked, !anyMatch ) +with expansion: + { 1, 2, 3, 4, 5 } not any match matches undescribed predicate + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[0] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[1] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[2] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[3] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[4] ) +with expansion: + true + +------------------------------------------------------------------------------- +Usage of AnyMatch range matcher + Shortcircuiting + Short-circuited +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( mocked, anyMatch ) +with expansion: + { 1, 2, 3, 4, 5 } any match matches undescribed predicate + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[0] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_FALSE( mocked.derefed[1] ) +with expansion: + !false + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_FALSE( mocked.derefed[2] ) +with expansion: + !false + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_FALSE( mocked.derefed[3] ) +with expansion: + !false + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_FALSE( mocked.derefed[4] ) +with expansion: + !false + +------------------------------------------------------------------------------- +Usage of NoneMatch range matcher + Basic usage +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( data, NoneMatch(SizeIs(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 has size == 6 + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( data, !NoneMatch(Contains(0) && Contains(1)) ) +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 } } not none match ( contains element 0 and contains + element 1 ) + +------------------------------------------------------------------------------- +Usage of NoneMatch range matcher + Type requires ADL found begin and end +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( needs_adl, NoneMatch( Predicate( []( int elem ) { return elem > 6; } ) ) ) +with expansion: + { 1, 2, 3, 4, 5 } none match matches undescribed predicate + +------------------------------------------------------------------------------- +Usage of NoneMatch range matcher + Shortcircuiting + All are read +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( mocked, noneMatch ) +with expansion: + { 1, 2, 3, 4, 5 } none match matches undescribed predicate + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[0] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[1] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[2] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[3] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[4] ) +with expansion: + true + +------------------------------------------------------------------------------- +Usage of NoneMatch range matcher + Shortcircuiting + Short-circuited +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp: +............................................................................... + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_THAT( mocked, !noneMatch ) +with expansion: + { 1, 2, 3, 4, 5 } not none match matches undescribed predicate + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE( mocked.derefed[0] ) +with expansion: + true + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_FALSE( mocked.derefed[1] ) +with expansion: + !false + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_FALSE( mocked.derefed[2] ) +with expansion: + !false + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_FALSE( mocked.derefed[3] ) +with expansion: + !false + +MatchersRanges.tests.cpp:: PASSED: + REQUIRE_FALSE( mocked.derefed[4] ) +with expansion: + !false + ------------------------------------------------------------------------------- Usage of the SizeIs range matcher Some with stdlib containers @@ -12286,129 +12610,6 @@ MatchersRanges.tests.cpp:: PASSED: with expansion: {?} has size == 13 -------------------------------------------------------------------------------- -Usage of the quantifiers matchers - Usage of the AllMatch range matcher -------------------------------------------------------------------------------- -MatchersRanges.tests.cpp: -............................................................................... - -MatchersRanges.tests.cpp:: 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:: 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:: PASSED: - REQUIRE_THAT( string_vector, AllMatch(StartsWith("C")) ) -with expansion: - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match starts with: - "C" - -MatchersRanges.tests.cpp:: PASSED: - REQUIRE_THAT( string_vector, AllMatch(EndsWith("+")) ) -with expansion: - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match ends with: - "+" - -MatchersRanges.tests.cpp:: PASSED: - REQUIRE_THAT( int_vectors_list, AllMatch(!IsEmpty()) ) -with expansion: - { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match not is empty - -MatchersRanges.tests.cpp:: 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: -............................................................................... - -MatchersRanges.tests.cpp:: 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:: 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:: PASSED: - REQUIRE_THAT( string_vector, AnyMatch(StartsWith("CMak")) ) -with expansion: - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match starts with: - "CMak" - -MatchersRanges.tests.cpp:: PASSED: - REQUIRE_THAT( string_vector, AnyMatch(EndsWith("++")) ) -with expansion: - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match ends with: - "++" - -MatchersRanges.tests.cpp:: 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:: 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: -............................................................................... - -MatchersRanges.tests.cpp:: 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:: 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:: PASSED: - REQUIRE_THAT( string_vector, NoneMatch(StartsWith("abd")) ) -with expansion: - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match starts - with: "abd" - -MatchersRanges.tests.cpp:: PASSED: - REQUIRE_THAT( string_vector, NoneMatch(EndsWith("#!--")) ) -with expansion: - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match ends with: - "#!--" - -MatchersRanges.tests.cpp:: PASSED: - REQUIRE_THAT( int_vectors_list, NoneMatch(IsEmpty()) ) -with expansion: - { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match is empty - -MatchersRanges.tests.cpp:: 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 ------------------------------------------------------------------------------- @@ -15804,6 +16005,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 352 | 262 passed | 86 failed | 4 failed as expected -assertions: 2027 | 1858 passed | 148 failed | 21 failed as expected +test cases: 354 | 264 passed | 86 failed | 4 failed as expected +assertions: 2054 | 1885 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 214e03e8..c7e3d02c 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -1280,12 +1280,21 @@ Exception.tests.cpp: + + + + + + + + + + + + - - - diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index ed78a3a9..736b1b4f 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -1265,12 +1265,21 @@ Matchers.tests.cpp: + + + + + + + + + + + + - - - diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 3b32341b..40fa0125 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -3161,6 +3161,96 @@ not ok {test-number} - unexpected exception with message: '3.14' ok {test-number} - bptr->i == 3 for: 3 == 3 # Upcasting special member functions ok {test-number} - bptr->i == 3 for: 3 == 3 +# Usage of AllMatch range matcher +ok {test-number} - data, 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 AllMatch range matcher +ok {test-number} - data, !AllMatch(Contains(0) && Contains(1)) 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 } } not all match ( contains element 0 and contains element 1 ) +# Usage of AllMatch range matcher +ok {test-number} - needs_adl, AllMatch( Predicate( []( int elem ) { return elem < 6; } ) ) for: { 1, 2, 3, 4, 5 } all match matches undescribed predicate +# Usage of AllMatch range matcher +ok {test-number} - mocked, allMatch for: { 1, 2, 3, 4, 5 } all match matches undescribed predicate +# Usage of AllMatch range matcher +ok {test-number} - mocked.derefed[0] for: true +# Usage of AllMatch range matcher +ok {test-number} - mocked.derefed[1] for: true +# Usage of AllMatch range matcher +ok {test-number} - mocked.derefed[2] for: true +# Usage of AllMatch range matcher +ok {test-number} - mocked.derefed[3] for: true +# Usage of AllMatch range matcher +ok {test-number} - mocked.derefed[4] for: true +# Usage of AllMatch range matcher +ok {test-number} - mocked, !allMatch for: { 1, 2, 3, 4, 5 } not all match matches undescribed predicate +# Usage of AllMatch range matcher +ok {test-number} - mocked.derefed[0] for: true +# Usage of AllMatch range matcher +ok {test-number} - mocked.derefed[1] for: true +# Usage of AllMatch range matcher +ok {test-number} - mocked.derefed[2] for: true +# Usage of AllMatch range matcher +ok {test-number} - !(mocked.derefed[3]) for: !false +# Usage of AllMatch range matcher +ok {test-number} - !(mocked.derefed[4]) for: !false +# Usage of AnyMatch range matcher +ok {test-number} - data, 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 AnyMatch range matcher +ok {test-number} - data, !AnyMatch(Contains(0) && Contains(10)) 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 } } not any match ( contains element 0 and contains element 10 ) +# Usage of AnyMatch range matcher +ok {test-number} - needs_adl, AnyMatch( Predicate( []( int elem ) { return elem < 3; } ) ) for: { 1, 2, 3, 4, 5 } any match matches undescribed predicate +# Usage of AnyMatch range matcher +ok {test-number} - mocked, !anyMatch for: { 1, 2, 3, 4, 5 } not any match matches undescribed predicate +# Usage of AnyMatch range matcher +ok {test-number} - mocked.derefed[0] for: true +# Usage of AnyMatch range matcher +ok {test-number} - mocked.derefed[1] for: true +# Usage of AnyMatch range matcher +ok {test-number} - mocked.derefed[2] for: true +# Usage of AnyMatch range matcher +ok {test-number} - mocked.derefed[3] for: true +# Usage of AnyMatch range matcher +ok {test-number} - mocked.derefed[4] for: true +# Usage of AnyMatch range matcher +ok {test-number} - mocked, anyMatch for: { 1, 2, 3, 4, 5 } any match matches undescribed predicate +# Usage of AnyMatch range matcher +ok {test-number} - mocked.derefed[0] for: true +# Usage of AnyMatch range matcher +ok {test-number} - !(mocked.derefed[1]) for: !false +# Usage of AnyMatch range matcher +ok {test-number} - !(mocked.derefed[2]) for: !false +# Usage of AnyMatch range matcher +ok {test-number} - !(mocked.derefed[3]) for: !false +# Usage of AnyMatch range matcher +ok {test-number} - !(mocked.derefed[4]) for: !false +# Usage of NoneMatch range matcher +ok {test-number} - data, NoneMatch(SizeIs(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 has size == 6 +# Usage of NoneMatch range matcher +ok {test-number} - data, !NoneMatch(Contains(0) && Contains(1)) 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 } } not none match ( contains element 0 and contains element 1 ) +# Usage of NoneMatch range matcher +ok {test-number} - needs_adl, NoneMatch( Predicate( []( int elem ) { return elem > 6; } ) ) for: { 1, 2, 3, 4, 5 } none match matches undescribed predicate +# Usage of NoneMatch range matcher +ok {test-number} - mocked, noneMatch for: { 1, 2, 3, 4, 5 } none match matches undescribed predicate +# Usage of NoneMatch range matcher +ok {test-number} - mocked.derefed[0] for: true +# Usage of NoneMatch range matcher +ok {test-number} - mocked.derefed[1] for: true +# Usage of NoneMatch range matcher +ok {test-number} - mocked.derefed[2] for: true +# Usage of NoneMatch range matcher +ok {test-number} - mocked.derefed[3] for: true +# Usage of NoneMatch range matcher +ok {test-number} - mocked.derefed[4] for: true +# Usage of NoneMatch range matcher +ok {test-number} - mocked, !noneMatch for: { 1, 2, 3, 4, 5 } not none match matches undescribed predicate +# Usage of NoneMatch range matcher +ok {test-number} - mocked.derefed[0] for: true +# Usage of NoneMatch range matcher +ok {test-number} - !(mocked.derefed[1]) for: !false +# Usage of NoneMatch range matcher +ok {test-number} - !(mocked.derefed[2]) for: !false +# Usage of NoneMatch range matcher +ok {test-number} - !(mocked.derefed[3]) for: !false +# Usage of NoneMatch range matcher +ok {test-number} - !(mocked.derefed[4]) for: !false # Usage of the SizeIs range matcher ok {test-number} - empty_vec, SizeIs(0) for: { } has size == 0 # Usage of the SizeIs range matcher @@ -3179,42 +3269,6 @@ 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 @@ -4046,5 +4100,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2027 +1..2054 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index 09b426b7..413e5153 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -577,10 +577,14 @@ Exception.tests.cpp:|nunexpected exception with message:|n "3.14"' ##teamcity[testFinished name='Unexpected exceptions can be translated' duration="{duration}"] ##teamcity[testStarted name='Upcasting special member functions'] ##teamcity[testFinished name='Upcasting special member functions' duration="{duration}"] +##teamcity[testStarted name='Usage of AllMatch range matcher'] +##teamcity[testFinished name='Usage of AllMatch range matcher' duration="{duration}"] +##teamcity[testStarted name='Usage of AnyMatch range matcher'] +##teamcity[testFinished name='Usage of AnyMatch range matcher' duration="{duration}"] +##teamcity[testStarted name='Usage of NoneMatch range matcher'] +##teamcity[testFinished name='Usage of NoneMatch range matcher' 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 a9de7c7e..ecaa869b 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -14536,6 +14536,429 @@ There is no extra whitespace here + +
+ + + data, AllMatch(SizeIs(5)) + + + { { 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 + + + + + data, !AllMatch(Contains(0) && Contains(1)) + + + { { 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 } } not all match ( contains element 0 and contains element 1 ) + + + +
+
+ + + needs_adl, AllMatch( Predicate<int>( []( int elem ) { return elem < 6; } ) ) + + + { 1, 2, 3, 4, 5 } all match matches undescribed predicate + + + +
+
+
+ + + mocked, allMatch + + + { 1, 2, 3, 4, 5 } all match matches undescribed predicate + + + + + mocked.derefed[0] + + + true + + + + + mocked.derefed[1] + + + true + + + + + mocked.derefed[2] + + + true + + + + + mocked.derefed[3] + + + true + + + + + mocked.derefed[4] + + + true + + + +
+ +
+
+
+ + + mocked, !allMatch + + + { 1, 2, 3, 4, 5 } not all match matches undescribed predicate + + + + + mocked.derefed[0] + + + true + + + + + mocked.derefed[1] + + + true + + + + + mocked.derefed[2] + + + true + + + + + !(mocked.derefed[3]) + + + !false + + + + + !(mocked.derefed[4]) + + + !false + + + +
+ +
+ +
+ +
+ + + data, AnyMatch(SizeIs(5)) + + + { { 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 + + + + + data, !AnyMatch(Contains(0) && Contains(10)) + + + { { 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 } } not any match ( contains element 0 and contains element 10 ) + + + +
+
+ + + needs_adl, AnyMatch( Predicate<int>( []( int elem ) { return elem < 3; } ) ) + + + { 1, 2, 3, 4, 5 } any match matches undescribed predicate + + + +
+
+
+ + + mocked, !anyMatch + + + { 1, 2, 3, 4, 5 } not any match matches undescribed predicate + + + + + mocked.derefed[0] + + + true + + + + + mocked.derefed[1] + + + true + + + + + mocked.derefed[2] + + + true + + + + + mocked.derefed[3] + + + true + + + + + mocked.derefed[4] + + + true + + + +
+ +
+
+
+ + + mocked, anyMatch + + + { 1, 2, 3, 4, 5 } any match matches undescribed predicate + + + + + mocked.derefed[0] + + + true + + + + + !(mocked.derefed[1]) + + + !false + + + + + !(mocked.derefed[2]) + + + !false + + + + + !(mocked.derefed[3]) + + + !false + + + + + !(mocked.derefed[4]) + + + !false + + + +
+ +
+ +
+ +
+ + + data, NoneMatch(SizeIs(6)) + + + { { 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 == 6 + + + + + data, !NoneMatch(Contains(0) && Contains(1)) + + + { { 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 } } not none match ( contains element 0 and contains element 1 ) + + + +
+
+ + + needs_adl, NoneMatch( Predicate<int>( []( int elem ) { return elem > 6; } ) ) + + + { 1, 2, 3, 4, 5 } none match matches undescribed predicate + + + +
+
+
+ + + mocked, noneMatch + + + { 1, 2, 3, 4, 5 } none match matches undescribed predicate + + + + + mocked.derefed[0] + + + true + + + + + mocked.derefed[1] + + + true + + + + + mocked.derefed[2] + + + true + + + + + mocked.derefed[3] + + + true + + + + + mocked.derefed[4] + + + true + + + +
+ +
+
+
+ + + mocked, !noneMatch + + + { 1, 2, 3, 4, 5 } not none match matches undescribed predicate + + + + + mocked.derefed[0] + + + true + + + + + !(mocked.derefed[1]) + + + !false + + + + + !(mocked.derefed[2]) + + + !false + + + + + !(mocked.derefed[3]) + + + !false + + + + + !(mocked.derefed[4]) + + + !false + + + +
+ +
+ +
@@ -14620,162 +15043,6 @@ There is no extra whitespace here
- -
- - - int_arr_arr, AllMatch(Contains(0)) - - - { { 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 - - - - - int_arr_arr, AllMatch(SizeIs(5)) - - - { { 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 - - - - - string_vector, AllMatch(StartsWith("C")) - - - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match starts with: "C" - - - - - string_vector, AllMatch(EndsWith("+")) - - - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } all match ends with: "+" - - - - - int_vectors_list, AllMatch(!IsEmpty()) - - - { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match not is empty - - - - - int_vectors_list, AllMatch(SizeIs(2)) - - - { { 1, 2 }, { 3, 4 }, { 5, 6 } } all match has size == 2 - - - -
-
- - - int_arr_arr, AnyMatch(Contains(-2)) - - - { { 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 - - - - - int_arr_arr, AnyMatch(SizeIs(5)) - - - { { 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 - - - - - string_vector, AnyMatch(StartsWith("CMak")) - - - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match starts with: "CMak" - - - - - string_vector, AnyMatch(EndsWith("++")) - - - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } any match ends with: "++" - - - - - int_vectors_list, AnyMatch(Contains(4)) - - - { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match contains element 4 - - - - - int_vectors_list, AnyMatch(SizeIs(2)) - - - { { 1, 2 }, { 3, 4 }, { 5, 6 } } any match has size == 2 - - - -
-
- - - int_arr_arr, NoneMatch(Contains(-6)) - - - { { 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 - - - - - int_arr_arr, NoneMatch(SizeIs(42)) - - - { { 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 - - - - - string_vector, NoneMatch(StartsWith("abd")) - - - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match starts with: "abd" - - - - - string_vector, NoneMatch(EndsWith("#!--")) - - - { "Command+", "Catch2+", "CMake+", "C++", "Console+" } none match ends with: "#!--" - - - - - int_vectors_list, NoneMatch(IsEmpty()) - - - { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match is empty - - - - - int_vectors_list, NoneMatch(SizeIs(3)) - - - { { 1, 2 }, { 3, 4 }, { 5, 6 } } none match has size == 3 - - - -
- -
@@ -18754,9 +19021,9 @@ loose text artifact - - + + - - + + diff --git a/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp b/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp index 13b546e3..912b5cdb 100644 --- a/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp +++ b/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -33,8 +34,143 @@ namespace unrelated { } }; } // end unrelated namespace + +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunused-function" +#endif + +class has_different_begin_end_types { + std::array elements{ {1, 2, 3, 4, 5} }; + + // Different type for the "end" iterator + struct iterator_end {}; + // Just a fake forward iterator, that only compares to a different + // type (so we can test two-type ranges). + struct iterator { + int const* start; + int const* end; + + using iterator_category = std::forward_iterator_tag; + using difference_type = std::ptrdiff_t; + using value_type = int; + using reference = int const&; + using pointer = int const*; + + + friend bool operator==( iterator iter, iterator_end ) { + return iter.start == iter.end; + } + friend bool operator!=( iterator iter, iterator_end ) { + return iter.start != iter.end; + } + iterator& operator++() { + ++start; + return *this; + } + iterator operator++(int) { + auto tmp(*this); + ++start; + return tmp; + } + reference operator*() const { + return *start; + } + pointer operator->() const { + return start; + } + }; + + +public: + iterator begin() const { + return { elements.data(), elements.data() + elements.size() }; + } + + iterator_end end() const { + return {}; + } +}; + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + + +struct with_mocked_iterator_access { + static constexpr size_t data_size = 5; + std::array elements{ {1, 2, 3, 4, 5} }; + std::array touched{}; + std::array derefed{}; + + // We want to check which elements were touched when iterating, so + // we can check whether iterator-using code traverses range correctly + struct iterator { + with_mocked_iterator_access* m_origin; + size_t m_origin_idx; + + using iterator_category = std::forward_iterator_tag; + using difference_type = std::ptrdiff_t; + using value_type = int; + using reference = int const&; + using pointer = int const*; + + friend bool operator==(iterator lhs, iterator rhs) { + return lhs.m_origin == rhs.m_origin + && lhs.m_origin_idx == rhs.m_origin_idx; + } + friend bool operator!=(iterator lhs, iterator rhs) { + return !(lhs == rhs); + } + iterator& operator++() { + ++m_origin_idx; + assert(m_origin_idx < data_size + 1 && "Outside of valid alloc"); + if (m_origin_idx < data_size) { + m_origin->touched[m_origin_idx] = true; + } + return *this; + } + iterator operator++(int) { + auto tmp(*this); + ++(*this); + return tmp; + } + reference operator*() const { + assert(m_origin_idx < data_size && "Attempted to deref invalid position"); + m_origin->derefed[m_origin_idx] = true; + return m_origin->elements[m_origin_idx]; + } + pointer operator->() const { + assert(m_origin_idx < data_size && "Attempted to deref invalid position"); + return &m_origin->elements[m_origin_idx]; + } + + }; + + iterator begin() const { + // Const-cast away to avoid overcomplicating the iterators + // We should actually fix this over time + return { const_cast(this), 0 }; + } + iterator end() const { + return { const_cast(this), data_size }; + } + +}; + } // end anon namespace +namespace Catch { + template <> + struct StringMaker { + static std::string convert(with_mocked_iterator_access const& access) { + // We have to avoid the type's iterators, because we check + // their use in tests + return ::Catch::Detail::stringify(access.elements); + } + }; +} + struct MoveOnlyTestElement { int num = 0; MoveOnlyTestElement(int n) :num(n) {} @@ -220,55 +356,190 @@ TEST_CASE("Usage of the SizeIs range matcher", "[matchers][templated][size]") { } } -TEST_CASE("Usage of the quantifiers matchers", "[matchers][templated][quantifiers]") { + +TEST_CASE("Usage of AllMatch range matcher", "[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, 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 string_vector{ "Command+", "Catch2+", "CMake+", "C++", "Console+" }; - std::list> int_vectors_list{ { 1, 2 }, { 3, 4 }, { 5, 6 } }; + using Catch::Matchers::Predicate; - SECTION("Usage of the AllMatch range matcher") { - REQUIRE_THAT(int_arr_arr, AllMatch(Contains(0))); - REQUIRE_THAT(int_arr_arr, AllMatch(SizeIs(5))); + SECTION("Basic usage") { + using Catch::Matchers::Contains; + using Catch::Matchers::SizeIs; - REQUIRE_THAT(string_vector, AllMatch(StartsWith("C"))); - REQUIRE_THAT(string_vector, AllMatch(EndsWith("+"))); + std::array, 5> data{{ + {{ 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 }} + }}; - REQUIRE_THAT(int_vectors_list, AllMatch(!IsEmpty())); - REQUIRE_THAT(int_vectors_list, AllMatch(SizeIs(2))); + REQUIRE_THAT(data, AllMatch(SizeIs(5))); + REQUIRE_THAT(data, !AllMatch(Contains(0) && Contains(1))); } - 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("Type requires ADL found begin and end") { + unrelated::needs_ADL_begin needs_adl; + REQUIRE_THAT( needs_adl, AllMatch( Predicate( []( int elem ) { + return elem < 6; + } ) ) ); } - 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))); + SECTION("Shortcircuiting") { + with_mocked_iterator_access mocked; + SECTION("All are read") { + auto allMatch = AllMatch(Predicate([](int elem) { + return elem < 10; + })); + REQUIRE_THAT(mocked, allMatch); + REQUIRE(mocked.derefed[0]); + REQUIRE(mocked.derefed[1]); + REQUIRE(mocked.derefed[2]); + REQUIRE(mocked.derefed[3]); + REQUIRE(mocked.derefed[4]); + } + SECTION("Short-circuited") { + auto allMatch = AllMatch(Predicate([](int elem) { + return elem < 3; + })); + REQUIRE_THAT(mocked, !allMatch); + REQUIRE(mocked.derefed[0]); + REQUIRE(mocked.derefed[1]); + REQUIRE(mocked.derefed[2]); + REQUIRE_FALSE(mocked.derefed[3]); + REQUIRE_FALSE(mocked.derefed[4]); + } } } + +TEST_CASE("Usage of AnyMatch range matcher", "[matchers][templated][quantifiers]") { + using Catch::Matchers::AnyMatch; + using Catch::Matchers::Predicate; + + SECTION("Basic usage") { + using Catch::Matchers::Contains; + using Catch::Matchers::SizeIs; + + std::array, 5> data{ { + {{ 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 }} + } }; + + REQUIRE_THAT(data, AnyMatch(SizeIs(5))); + REQUIRE_THAT(data, !AnyMatch(Contains(0) && Contains(10))); + } + + SECTION("Type requires ADL found begin and end") { + unrelated::needs_ADL_begin needs_adl; + REQUIRE_THAT( needs_adl, AnyMatch( Predicate( []( int elem ) { + return elem < 3; + } ) ) ); + } + + SECTION("Shortcircuiting") { + with_mocked_iterator_access mocked; + SECTION("All are read") { + auto anyMatch = AnyMatch( + Predicate( []( int elem ) { return elem > 10; } ) ); + REQUIRE_THAT( mocked, !anyMatch ); + REQUIRE( mocked.derefed[0] ); + REQUIRE( mocked.derefed[1] ); + REQUIRE( mocked.derefed[2] ); + REQUIRE( mocked.derefed[3] ); + REQUIRE( mocked.derefed[4] ); + } + SECTION("Short-circuited") { + auto anyMatch = AnyMatch( + Predicate( []( int elem ) { return elem < 3; } ) ); + REQUIRE_THAT( mocked, anyMatch ); + REQUIRE( mocked.derefed[0] ); + REQUIRE_FALSE( mocked.derefed[1] ); + REQUIRE_FALSE( mocked.derefed[2] ); + REQUIRE_FALSE( mocked.derefed[3] ); + REQUIRE_FALSE( mocked.derefed[4] ); + } + } +} + +TEST_CASE("Usage of NoneMatch range matcher", "[matchers][templated][quantifiers]") { + using Catch::Matchers::NoneMatch; + using Catch::Matchers::Predicate; + + SECTION("Basic usage") { + using Catch::Matchers::Contains; + using Catch::Matchers::SizeIs; + + std::array, 5> data{ { + {{ 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 }} + } }; + + REQUIRE_THAT(data, NoneMatch(SizeIs(6))); + REQUIRE_THAT(data, !NoneMatch(Contains(0) && Contains(1))); + } + + SECTION( "Type requires ADL found begin and end" ) { + unrelated::needs_ADL_begin needs_adl; + REQUIRE_THAT( needs_adl, NoneMatch( Predicate( []( int elem ) { + return elem > 6; + } ) ) ); + } + + SECTION("Shortcircuiting") { + with_mocked_iterator_access mocked; + SECTION("All are read") { + auto noneMatch = NoneMatch( + Predicate([](int elem) { return elem > 10; })); + REQUIRE_THAT(mocked, noneMatch); + REQUIRE(mocked.derefed[0]); + REQUIRE(mocked.derefed[1]); + REQUIRE(mocked.derefed[2]); + REQUIRE(mocked.derefed[3]); + REQUIRE(mocked.derefed[4]); + } + SECTION("Short-circuited") { + auto noneMatch = NoneMatch( + Predicate([](int elem) { return elem < 3; })); + REQUIRE_THAT(mocked, !noneMatch); + REQUIRE(mocked.derefed[0]); + REQUIRE_FALSE(mocked.derefed[1]); + REQUIRE_FALSE(mocked.derefed[2]); + REQUIRE_FALSE(mocked.derefed[3]); + REQUIRE_FALSE(mocked.derefed[4]); + } + } +} + + +// This is a C++17 extension, and GCC refuses to compile such code +// unless it is set to C++17 or later +#if defined(CATCH_CPP17_OR_GREATER) + +TEST_CASE( "The quantifier range matchers support types with different types returned from begin and end", + "[matchers][templated][quantifiers][approvals]" ) { + using Catch::Matchers::AllMatch; + using Catch::Matchers::AnyMatch; + using Catch::Matchers::NoneMatch; + + using Catch::Matchers::Predicate; + + has_different_begin_end_types diff_types; + REQUIRE_THAT( diff_types, !AllMatch( Predicate( []( int elem ) { + return elem < 3; + } ) ) ); + + REQUIRE_THAT( diff_types, AnyMatch( Predicate( []( int elem ) { + return elem < 2; + } ) ) ); + + REQUIRE_THAT( diff_types, !NoneMatch( Predicate( []( int elem ) { + return elem < 3; + } ) ) ); +} + +#endif