catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Provide overloads for {Unordered}RangeEquals taking a std::initializer_list
- Commit
69d62abc9a48033177b99ae79c13a6f1b280e94c- Author
- Stefan Haller ·
- Committer
- Martin Hořeňovský
- Parents
1e0ccb1b2150
Changes
.../matchers/catch_matchers_range_equals.hpp | 32 +++++++++++++++++ tests/SelfTest/Baselines/compact.sw.approved.txt | 6 +++- .../Baselines/compact.sw.multi.approved.txt | 6 +++- tests/SelfTest/Baselines/console.std.approved.txt | 2 +- tests/SelfTest/Baselines/console.sw.approved.txt | 36 ++++++++++++++++++- .../Baselines/console.sw.multi.approved.txt | 36 ++++++++++++++++++- tests/SelfTest/Baselines/junit.sw.approved.txt | 4 ++- .../SelfTest/Baselines/junit.sw.multi.approved.txt | 4 ++- tests/SelfTest/Baselines/sonarqube.sw.approved.txt | 2 ++ .../Baselines/sonarqube.sw.multi.approved.txt | 2 ++ tests/SelfTest/Baselines/tap.sw.approved.txt | 10 +++++- tests/SelfTest/Baselines/tap.sw.multi.approved.txt | 10 +++++- tests/SelfTest/Baselines/xml.sw.approved.txt | 40 +++++++++++++++++++++- tests/SelfTest/Baselines/xml.sw.multi.approved.txt | 40 +++++++++++++++++++++- tests/SelfTest/UsageTests/MatchersRanges.tests.cpp | 19 ++++++++++ 15 files changed, 238 insertions(+), 11 deletions(-) diff --git a/src/catch2/matchers/catch_matchers_range_equals.hpp b/src/catch2/matchers/catch_matchers_range_equals.hpp index 49ba19b5..8130f604 100644 --- a/src/catch2/matchers/catch_matchers_range_equals.hpp +++ b/src/catch2/matchers/catch_matchers_range_equals.hpp @@ -108,6 +108,22 @@ namespace Catch { return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) }; } + /** + * Creates a matcher that checks if all elements in a range are equal + * to all elements in an initializer list. + * + * Uses the provided predicate `predicate` to do the comparisons + * (defaulting to `std::equal_to`) + */ + template <typename T, + typename Equality = decltype( std::equal_to<>{} )> + constexpr + RangeEqualsMatcher<std::initializer_list<T>, Equality> + RangeEquals( std::initializer_list<T> range, + Equality&& predicate = std::equal_to<>{} ) { + return { range, CATCH_FORWARD( predicate ) }; + } + /** * Creates a matcher that checks if all elements in a range are equal * to all elements in another range, in some permutation. @@ -123,6 +139,22 @@ namespace Catch { Equality&& predicate = std::equal_to<>{} ) { return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) }; } + + /** + * Creates a matcher that checks if all elements in a range are equal + * to all elements in an initializer list, in some permutation. + * + * Uses the provided predicate `predicate` to do the comparisons + * (defaulting to `std::equal_to`) + */ + template <typename T, + typename Equality = decltype( std::equal_to<>{} )> + constexpr + UnorderedRangeEqualsMatcher<std::initializer_list<T>, Equality> + UnorderedRangeEquals( std::initializer_list<T> range, + Equality&& predicate = std::equal_to<>{} ) { + return { range, CATCH_FORWARD( predicate ) }; + } } // namespace Matchers } // namespace Catch diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 1f0dd012..b7f48cbc 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -2284,6 +2284,8 @@ MatchersRanges.tests.cpp:<line number>: passed: vector_a, RangeEquals( vector_a_ MatchersRanges.tests.cpp:<line number>: passed: vector_a, !RangeEquals( vector_b, close_enough ) for: { 1, 2, 3 } not elements are { 3, 3, 4 } MatchersRanges.tests.cpp:<line number>: passed: needs_adl1, RangeEquals( needs_adl2 ) for: { 1, 2, 3, 4, 5 } elements are { 1, 2, 3, 4, 5 } MatchersRanges.tests.cpp:<line number>: passed: needs_adl1, RangeEquals( needs_adl3, []( int l, int r ) { return l + 1 == r; } ) for: { 1, 2, 3, 4, 5 } elements are { 2, 3, 4, 5, 6 } +MatchersRanges.tests.cpp:<line number>: passed: array_a, RangeEquals( { 1, 2, 3 } ) for: { 1, 2, 3 } elements are { 1, 2, 3 } +MatchersRanges.tests.cpp:<line number>: passed: array_a, RangeEquals( { 2, 4, 6 }, []( int l, int r ) { return l * 2 == r; } ) for: { 1, 2, 3 } elements are { 2, 4, 6 } MatchersRanges.tests.cpp:<line number>: passed: mocked1, !RangeEquals( arr ) for: { 1, 2, 3, 4 } not elements are { 1, 2, 4, 4 } MatchersRanges.tests.cpp:<line number>: passed: mocked1.m_derefed[0] for: true MatchersRanges.tests.cpp:<line number>: passed: mocked1.m_derefed[1] for: true @@ -2304,6 +2306,8 @@ MatchersRanges.tests.cpp:<line number>: passed: vector_a, !UnorderedRangeEquals( MatchersRanges.tests.cpp:<line number>: passed: vector_a, UnorderedRangeEquals( vector_a_plus_1, close_enough ) for: { 1, 10, 20 } unordered elements are { 11, 21, 2 } MatchersRanges.tests.cpp:<line number>: passed: vector_a, !UnorderedRangeEquals( vector_b, close_enough ) for: { 1, 10, 21 } not unordered elements are { 11, 21, 3 } MatchersRanges.tests.cpp:<line number>: passed: needs_adl1, UnorderedRangeEquals( needs_adl2 ) for: { 1, 2, 3, 4, 5 } unordered elements are { 1, 2, 3, 4, 5 } +MatchersRanges.tests.cpp:<line number>: passed: array_a, UnorderedRangeEquals( { 10, 20, 1 } ) for: { 1, 10, 20 } unordered elements are { 10, 20, 1 } +MatchersRanges.tests.cpp:<line number>: passed: array_a, UnorderedRangeEquals( { 11, 21, 2 }, []( int l, int r ) { return std::abs( l - r ) <= 1; } ) for: { 1, 10, 20 } unordered elements are { 11, 21, 2 } MatchersRanges.tests.cpp:<line number>: passed: empty_vec, SizeIs(0) for: { } has size == 0 MatchersRanges.tests.cpp:<line number>: passed: empty_vec, !SizeIs(2) for: { } not has size == 2 MatchersRanges.tests.cpp:<line number>: passed: empty_vec, SizeIs(Lt(2)) for: { } size matches is less than 2 @@ -2851,6 +2855,6 @@ InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:<line number>: passed: Misc.tests.cpp:<line number>: passed: test cases: 419 | 313 passed | 86 failed | 6 skipped | 14 failed as expected -assertions: 2265 | 2083 passed | 147 failed | 35 failed as expected +assertions: 2269 | 2087 passed | 147 failed | 35 failed as expected diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index 77812a62..9e3e5372 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -2277,6 +2277,8 @@ MatchersRanges.tests.cpp:<line number>: passed: vector_a, RangeEquals( vector_a_ MatchersRanges.tests.cpp:<line number>: passed: vector_a, !RangeEquals( vector_b, close_enough ) for: { 1, 2, 3 } not elements are { 3, 3, 4 } MatchersRanges.tests.cpp:<line number>: passed: needs_adl1, RangeEquals( needs_adl2 ) for: { 1, 2, 3, 4, 5 } elements are { 1, 2, 3, 4, 5 } MatchersRanges.tests.cpp:<line number>: passed: needs_adl1, RangeEquals( needs_adl3, []( int l, int r ) { return l + 1 == r; } ) for: { 1, 2, 3, 4, 5 } elements are { 2, 3, 4, 5, 6 } +MatchersRanges.tests.cpp:<line number>: passed: array_a, RangeEquals( { 1, 2, 3 } ) for: { 1, 2, 3 } elements are { 1, 2, 3 } +MatchersRanges.tests.cpp:<line number>: passed: array_a, RangeEquals( { 2, 4, 6 }, []( int l, int r ) { return l * 2 == r; } ) for: { 1, 2, 3 } elements are { 2, 4, 6 } MatchersRanges.tests.cpp:<line number>: passed: mocked1, !RangeEquals( arr ) for: { 1, 2, 3, 4 } not elements are { 1, 2, 4, 4 } MatchersRanges.tests.cpp:<line number>: passed: mocked1.m_derefed[0] for: true MatchersRanges.tests.cpp:<line number>: passed: mocked1.m_derefed[1] for: true @@ -2297,6 +2299,8 @@ MatchersRanges.tests.cpp:<line number>: passed: vector_a, !UnorderedRangeEquals( MatchersRanges.tests.cpp:<line number>: passed: vector_a, UnorderedRangeEquals( vector_a_plus_1, close_enough ) for: { 1, 10, 20 } unordered elements are { 11, 21, 2 } MatchersRanges.tests.cpp:<line number>: passed: vector_a, !UnorderedRangeEquals( vector_b, close_enough ) for: { 1, 10, 21 } not unordered elements are { 11, 21, 3 } MatchersRanges.tests.cpp:<line number>: passed: needs_adl1, UnorderedRangeEquals( needs_adl2 ) for: { 1, 2, 3, 4, 5 } unordered elements are { 1, 2, 3, 4, 5 } +MatchersRanges.tests.cpp:<line number>: passed: array_a, UnorderedRangeEquals( { 10, 20, 1 } ) for: { 1, 10, 20 } unordered elements are { 10, 20, 1 } +MatchersRanges.tests.cpp:<line number>: passed: array_a, UnorderedRangeEquals( { 11, 21, 2 }, []( int l, int r ) { return std::abs( l - r ) <= 1; } ) for: { 1, 10, 20 } unordered elements are { 11, 21, 2 } MatchersRanges.tests.cpp:<line number>: passed: empty_vec, SizeIs(0) for: { } has size == 0 MatchersRanges.tests.cpp:<line number>: passed: empty_vec, !SizeIs(2) for: { } not has size == 2 MatchersRanges.tests.cpp:<line number>: passed: empty_vec, SizeIs(Lt(2)) for: { } size matches is less than 2 @@ -2840,6 +2844,6 @@ InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:<line number>: passed: Misc.tests.cpp:<line number>: passed: test cases: 419 | 313 passed | 86 failed | 6 skipped | 14 failed as expected -assertions: 2265 | 2083 passed | 147 failed | 35 failed as expected +assertions: 2269 | 2087 passed | 147 failed | 35 failed as expected diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 1003e549..495264b4 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1611,5 +1611,5 @@ due to unexpected exception with message: =============================================================================== test cases: 419 | 327 passed | 71 failed | 7 skipped | 14 failed as expected -assertions: 2248 | 2083 passed | 130 failed | 35 failed as expected +assertions: 2252 | 2087 passed | 130 failed | 35 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 3519b771..d7e31e73 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -14981,6 +14981,23 @@ MatchersRanges.tests.cpp:<line number>: PASSED: with expansion: { 1, 2, 3, 4, 5 } elements are { 2, 3, 4, 5, 6 } +------------------------------------------------------------------------------- +Usage of RangeEquals range matcher + Compare against std::initializer_list +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp:<line number> +............................................................................... + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( array_a, RangeEquals( { 1, 2, 3 } ) ) +with expansion: + { 1, 2, 3 } elements are { 1, 2, 3 } + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( array_a, RangeEquals( { 2, 4, 6 }, []( int l, int r ) { return l * 2 == r; } ) ) +with expansion: + { 1, 2, 3 } elements are { 2, 4, 6 } + ------------------------------------------------------------------------------- Usage of RangeEquals range matcher Check short-circuiting behaviour @@ -15168,6 +15185,23 @@ MatchersRanges.tests.cpp:<line number>: PASSED: with expansion: { 1, 2, 3, 4, 5 } unordered elements are { 1, 2, 3, 4, 5 } +------------------------------------------------------------------------------- +Usage of UnorderedRangeEquals range matcher + Compare against std::initializer_list +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp:<line number> +............................................................................... + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( array_a, UnorderedRangeEquals( { 10, 20, 1 } ) ) +with expansion: + { 1, 10, 20 } unordered elements are { 10, 20, 1 } + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( array_a, UnorderedRangeEquals( { 11, 21, 2 }, []( int l, int r ) { return std::abs( l - r ) <= 1; } ) ) +with expansion: + { 1, 10, 20 } unordered elements are { 11, 21, 2 } + ------------------------------------------------------------------------------- Usage of the SizeIs range matcher Some with stdlib containers @@ -18979,5 +19013,5 @@ Misc.tests.cpp:<line number>: PASSED: =============================================================================== test cases: 419 | 313 passed | 86 failed | 6 skipped | 14 failed as expected -assertions: 2265 | 2083 passed | 147 failed | 35 failed as expected +assertions: 2269 | 2087 passed | 147 failed | 35 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index 1fe0b73e..2c1460af 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -14974,6 +14974,23 @@ MatchersRanges.tests.cpp:<line number>: PASSED: with expansion: { 1, 2, 3, 4, 5 } elements are { 2, 3, 4, 5, 6 } +------------------------------------------------------------------------------- +Usage of RangeEquals range matcher + Compare against std::initializer_list +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp:<line number> +............................................................................... + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( array_a, RangeEquals( { 1, 2, 3 } ) ) +with expansion: + { 1, 2, 3 } elements are { 1, 2, 3 } + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( array_a, RangeEquals( { 2, 4, 6 }, []( int l, int r ) { return l * 2 == r; } ) ) +with expansion: + { 1, 2, 3 } elements are { 2, 4, 6 } + ------------------------------------------------------------------------------- Usage of RangeEquals range matcher Check short-circuiting behaviour @@ -15161,6 +15178,23 @@ MatchersRanges.tests.cpp:<line number>: PASSED: with expansion: { 1, 2, 3, 4, 5 } unordered elements are { 1, 2, 3, 4, 5 } +------------------------------------------------------------------------------- +Usage of UnorderedRangeEquals range matcher + Compare against std::initializer_list +------------------------------------------------------------------------------- +MatchersRanges.tests.cpp:<line number> +............................................................................... + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( array_a, UnorderedRangeEquals( { 10, 20, 1 } ) ) +with expansion: + { 1, 10, 20 } unordered elements are { 10, 20, 1 } + +MatchersRanges.tests.cpp:<line number>: PASSED: + REQUIRE_THAT( array_a, UnorderedRangeEquals( { 11, 21, 2 }, []( int l, int r ) { return std::abs( l - r ) <= 1; } ) ) +with expansion: + { 1, 10, 20 } unordered elements are { 11, 21, 2 } + ------------------------------------------------------------------------------- Usage of the SizeIs range matcher Some with stdlib containers @@ -18968,5 +19002,5 @@ Misc.tests.cpp:<line number>: PASSED: =============================================================================== test cases: 419 | 313 passed | 86 failed | 6 skipped | 14 failed as expected -assertions: 2265 | 2083 passed | 147 failed | 35 failed as expected +assertions: 2269 | 2087 passed | 147 failed | 35 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 33f207c5..5c5407ad 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="130" skipped="12" tests="2277" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="130" skipped="12" tests="2281" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <properties> <property name="random-seed" value="1"/> <property name="filters" value=""*" ~[!nonportable] ~[!benchmark] ~[approvals]"/> @@ -1652,6 +1652,7 @@ at Exception.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Custom predicate/Two equal non-empty containers (close enough)" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Custom predicate/Two non-equal non-empty containers (close enough)" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Ranges that need ADL begin/end" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Compare against std::initializer_list" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Check short-circuiting behaviour" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Check short-circuiting behaviour/Check short-circuits on failure" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Check short-circuiting behaviour/All elements are checked on success" time="{duration}" status="run"/> @@ -1667,6 +1668,7 @@ at Exception.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="Usage of UnorderedRangeEquals range matcher/Custom predicate/Two equal non-empty containers (close enough)" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of UnorderedRangeEquals range matcher/Custom predicate/Two non-equal non-empty containers (close enough)" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of UnorderedRangeEquals range matcher/Ranges that need ADL begin/end" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="Usage of UnorderedRangeEquals range matcher/Compare against std::initializer_list" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher" time="{duration}" status="run"/> <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"/> diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index 876a4db4..f44369e5 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuites> - <testsuite name="<exe-name>" errors="17" failures="130" skipped="12" tests="2277" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="130" skipped="12" tests="2281" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <properties> <property name="random-seed" value="1"/> <property name="filters" value=""*" ~[!nonportable] ~[!benchmark] ~[approvals]"/> @@ -1651,6 +1651,7 @@ at Exception.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Custom predicate/Two equal non-empty containers (close enough)" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Custom predicate/Two non-equal non-empty containers (close enough)" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Ranges that need ADL begin/end" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Compare against std::initializer_list" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Check short-circuiting behaviour" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Check short-circuiting behaviour/Check short-circuits on failure" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of RangeEquals range matcher/Check short-circuiting behaviour/All elements are checked on success" time="{duration}" status="run"/> @@ -1666,6 +1667,7 @@ at Exception.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="Usage of UnorderedRangeEquals range matcher/Custom predicate/Two equal non-empty containers (close enough)" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of UnorderedRangeEquals range matcher/Custom predicate/Two non-equal non-empty containers (close enough)" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of UnorderedRangeEquals range matcher/Ranges that need ADL begin/end" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="Usage of UnorderedRangeEquals range matcher/Compare against std::initializer_list" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Usage of the SizeIs range matcher" time="{duration}" status="run"/> <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"/> diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 18397240..9e26a142 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -1607,6 +1607,7 @@ at Matchers.tests.cpp:<line number> <testCase name="Usage of RangeEquals range matcher/Custom predicate/Two equal non-empty containers (close enough)" duration="{duration}"/> <testCase name="Usage of RangeEquals range matcher/Custom predicate/Two non-equal non-empty containers (close enough)" duration="{duration}"/> <testCase name="Usage of RangeEquals range matcher/Ranges that need ADL begin/end" duration="{duration}"/> + <testCase name="Usage of RangeEquals range matcher/Compare against std::initializer_list" duration="{duration}"/> <testCase name="Usage of RangeEquals range matcher/Check short-circuiting behaviour" duration="{duration}"/> <testCase name="Usage of RangeEquals range matcher/Check short-circuiting behaviour/Check short-circuits on failure" duration="{duration}"/> <testCase name="Usage of RangeEquals range matcher/Check short-circuiting behaviour/All elements are checked on success" duration="{duration}"/> @@ -1622,6 +1623,7 @@ at Matchers.tests.cpp:<line number> <testCase name="Usage of UnorderedRangeEquals range matcher/Custom predicate/Two equal non-empty containers (close enough)" duration="{duration}"/> <testCase name="Usage of UnorderedRangeEquals range matcher/Custom predicate/Two non-equal non-empty containers (close enough)" duration="{duration}"/> <testCase name="Usage of UnorderedRangeEquals range matcher/Ranges that need ADL begin/end" duration="{duration}"/> + <testCase name="Usage of UnorderedRangeEquals range matcher/Compare against std::initializer_list" duration="{duration}"/> <testCase name="Usage of the SizeIs range matcher" duration="{duration}"/> <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}"/> diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index 77348788..7e6a7502 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -1606,6 +1606,7 @@ at Matchers.tests.cpp:<line number> <testCase name="Usage of RangeEquals range matcher/Custom predicate/Two equal non-empty containers (close enough)" duration="{duration}"/> <testCase name="Usage of RangeEquals range matcher/Custom predicate/Two non-equal non-empty containers (close enough)" duration="{duration}"/> <testCase name="Usage of RangeEquals range matcher/Ranges that need ADL begin/end" duration="{duration}"/> + <testCase name="Usage of RangeEquals range matcher/Compare against std::initializer_list" duration="{duration}"/> <testCase name="Usage of RangeEquals range matcher/Check short-circuiting behaviour" duration="{duration}"/> <testCase name="Usage of RangeEquals range matcher/Check short-circuiting behaviour/Check short-circuits on failure" duration="{duration}"/> <testCase name="Usage of RangeEquals range matcher/Check short-circuiting behaviour/All elements are checked on success" duration="{duration}"/> @@ -1621,6 +1622,7 @@ at Matchers.tests.cpp:<line number> <testCase name="Usage of UnorderedRangeEquals range matcher/Custom predicate/Two equal non-empty containers (close enough)" duration="{duration}"/> <testCase name="Usage of UnorderedRangeEquals range matcher/Custom predicate/Two non-equal non-empty containers (close enough)" duration="{duration}"/> <testCase name="Usage of UnorderedRangeEquals range matcher/Ranges that need ADL begin/end" duration="{duration}"/> + <testCase name="Usage of UnorderedRangeEquals range matcher/Compare against std::initializer_list" duration="{duration}"/> <testCase name="Usage of the SizeIs range matcher" duration="{duration}"/> <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}"/> diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index ea53d421..19b968b8 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -3580,6 +3580,10 @@ ok {test-number} - needs_adl1, RangeEquals( needs_adl2 ) for: { 1, 2, 3, 4, 5 } # Usage of RangeEquals range matcher ok {test-number} - needs_adl1, RangeEquals( needs_adl3, []( int l, int r ) { return l + 1 == r; } ) for: { 1, 2, 3, 4, 5 } elements are { 2, 3, 4, 5, 6 } # Usage of RangeEquals range matcher +ok {test-number} - array_a, RangeEquals( { 1, 2, 3 } ) for: { 1, 2, 3 } elements are { 1, 2, 3 } +# Usage of RangeEquals range matcher +ok {test-number} - array_a, RangeEquals( { 2, 4, 6 }, []( int l, int r ) { return l * 2 == r; } ) for: { 1, 2, 3 } elements are { 2, 4, 6 } +# Usage of RangeEquals range matcher ok {test-number} - mocked1, !RangeEquals( arr ) for: { 1, 2, 3, 4 } not elements are { 1, 2, 4, 4 } # Usage of RangeEquals range matcher ok {test-number} - mocked1.m_derefed[0] for: true @@ -3619,6 +3623,10 @@ ok {test-number} - vector_a, UnorderedRangeEquals( vector_a_plus_1, close_enough ok {test-number} - vector_a, !UnorderedRangeEquals( vector_b, close_enough ) for: { 1, 10, 21 } not unordered elements are { 11, 21, 3 } # Usage of UnorderedRangeEquals range matcher ok {test-number} - needs_adl1, UnorderedRangeEquals( needs_adl2 ) for: { 1, 2, 3, 4, 5 } unordered elements are { 1, 2, 3, 4, 5 } +# Usage of UnorderedRangeEquals range matcher +ok {test-number} - array_a, UnorderedRangeEquals( { 10, 20, 1 } ) for: { 1, 10, 20 } unordered elements are { 10, 20, 1 } +# Usage of UnorderedRangeEquals range matcher +ok {test-number} - array_a, UnorderedRangeEquals( { 11, 21, 2 }, []( int l, int r ) { return std::abs( l - r ) <= 1; } ) for: { 1, 10, 20 } unordered elements are { 11, 21, 2 } # Usage of the SizeIs range matcher ok {test-number} - empty_vec, SizeIs(0) for: { } has size == 0 # Usage of the SizeIs range matcher @@ -4559,5 +4567,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2277 +1..2281 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 3f8f72eb..d92b1276 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -3573,6 +3573,10 @@ ok {test-number} - needs_adl1, RangeEquals( needs_adl2 ) for: { 1, 2, 3, 4, 5 } # Usage of RangeEquals range matcher ok {test-number} - needs_adl1, RangeEquals( needs_adl3, []( int l, int r ) { return l + 1 == r; } ) for: { 1, 2, 3, 4, 5 } elements are { 2, 3, 4, 5, 6 } # Usage of RangeEquals range matcher +ok {test-number} - array_a, RangeEquals( { 1, 2, 3 } ) for: { 1, 2, 3 } elements are { 1, 2, 3 } +# Usage of RangeEquals range matcher +ok {test-number} - array_a, RangeEquals( { 2, 4, 6 }, []( int l, int r ) { return l * 2 == r; } ) for: { 1, 2, 3 } elements are { 2, 4, 6 } +# Usage of RangeEquals range matcher ok {test-number} - mocked1, !RangeEquals( arr ) for: { 1, 2, 3, 4 } not elements are { 1, 2, 4, 4 } # Usage of RangeEquals range matcher ok {test-number} - mocked1.m_derefed[0] for: true @@ -3612,6 +3616,10 @@ ok {test-number} - vector_a, UnorderedRangeEquals( vector_a_plus_1, close_enough ok {test-number} - vector_a, !UnorderedRangeEquals( vector_b, close_enough ) for: { 1, 10, 21 } not unordered elements are { 11, 21, 3 } # Usage of UnorderedRangeEquals range matcher ok {test-number} - needs_adl1, UnorderedRangeEquals( needs_adl2 ) for: { 1, 2, 3, 4, 5 } unordered elements are { 1, 2, 3, 4, 5 } +# Usage of UnorderedRangeEquals range matcher +ok {test-number} - array_a, UnorderedRangeEquals( { 10, 20, 1 } ) for: { 1, 10, 20 } unordered elements are { 10, 20, 1 } +# Usage of UnorderedRangeEquals range matcher +ok {test-number} - array_a, UnorderedRangeEquals( { 11, 21, 2 }, []( int l, int r ) { return std::abs( l - r ) <= 1; } ) for: { 1, 10, 20 } unordered elements are { 11, 21, 2 } # Usage of the SizeIs range matcher ok {test-number} - empty_vec, SizeIs(0) for: { } has size == 0 # Usage of the SizeIs range matcher @@ -4548,5 +4556,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2277 +1..2281 diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index c64c5a7b..397eb487 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -17383,6 +17383,25 @@ There is no extra whitespace here </Expression> <OverallResults successes="2" failures="0" expectedFailures="0" skipped="false"/> </Section> + <Section name="Compare against std::initializer_list" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + array_a, RangeEquals( { 1, 2, 3 } ) + </Original> + <Expanded> + { 1, 2, 3 } elements are { 1, 2, 3 } + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + array_a, RangeEquals( { 2, 4, 6 }, []( int l, int r ) { return l * 2 == r; } ) + </Original> + <Expanded> + { 1, 2, 3 } elements are { 2, 4, 6 } + </Expanded> + </Expression> + <OverallResults successes="2" failures="0" expectedFailures="0" skipped="false"/> + </Section> <Section name="Check short-circuiting behaviour" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > <Section name="Check short-circuits on failure" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > @@ -17609,6 +17628,25 @@ There is no extra whitespace here </Expression> <OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/> </Section> + <Section name="Compare against std::initializer_list" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + array_a, UnorderedRangeEquals( { 10, 20, 1 } ) + </Original> + <Expanded> + { 1, 10, 20 } unordered elements are { 10, 20, 1 } + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + array_a, UnorderedRangeEquals( { 11, 21, 2 }, []( int l, int r ) { return std::abs( l - r ) <= 1; } ) + </Original> + <Expanded> + { 1, 10, 20 } unordered elements are { 11, 21, 2 } + </Expanded> + </Expression> + <OverallResults successes="2" failures="0" expectedFailures="0" skipped="false"/> + </Section> <OverallResult success="true" skips="0"/> </TestCase> <TestCase name="Usage of the SizeIs range matcher" tags="[matchers][size][templated]" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > @@ -21933,6 +21971,6 @@ Approx( -1.95996398454005449 ) </Section> <OverallResult success="true" skips="0"/> </TestCase> - <OverallResults successes="2083" failures="147" expectedFailures="35" skips="12"/> + <OverallResults successes="2087" failures="147" expectedFailures="35" skips="12"/> <OverallResultsCases successes="313" failures="86" expectedFailures="14" skips="6"/> </Catch2TestRun> diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt index d35ba1af..56e3e8bf 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -17383,6 +17383,25 @@ There is no extra whitespace here </Expression> <OverallResults successes="2" failures="0" expectedFailures="0" skipped="false"/> </Section> + <Section name="Compare against std::initializer_list" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + array_a, RangeEquals( { 1, 2, 3 } ) + </Original> + <Expanded> + { 1, 2, 3 } elements are { 1, 2, 3 } + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + array_a, RangeEquals( { 2, 4, 6 }, []( int l, int r ) { return l * 2 == r; } ) + </Original> + <Expanded> + { 1, 2, 3 } elements are { 2, 4, 6 } + </Expanded> + </Expression> + <OverallResults successes="2" failures="0" expectedFailures="0" skipped="false"/> + </Section> <Section name="Check short-circuiting behaviour" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > <Section name="Check short-circuits on failure" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > @@ -17609,6 +17628,25 @@ There is no extra whitespace here </Expression> <OverallResults successes="1" failures="0" expectedFailures="0" skipped="false"/> </Section> + <Section name="Compare against std::initializer_list" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + array_a, UnorderedRangeEquals( { 10, 20, 1 } ) + </Original> + <Expanded> + { 1, 10, 20 } unordered elements are { 10, 20, 1 } + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THAT" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > + <Original> + array_a, UnorderedRangeEquals( { 11, 21, 2 }, []( int l, int r ) { return std::abs( l - r ) <= 1; } ) + </Original> + <Expanded> + { 1, 10, 20 } unordered elements are { 11, 21, 2 } + </Expanded> + </Expression> + <OverallResults successes="2" failures="0" expectedFailures="0" skipped="false"/> + </Section> <OverallResult success="true" skips="0"/> </TestCase> <TestCase name="Usage of the SizeIs range matcher" tags="[matchers][size][templated]" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" > @@ -21932,6 +21970,6 @@ Approx( -1.95996398454005449 ) </Section> <OverallResult success="true" skips="0"/> </TestCase> - <OverallResults successes="2083" failures="147" expectedFailures="35" skips="12"/> + <OverallResults successes="2087" failures="147" expectedFailures="35" skips="12"/> <OverallResultsCases successes="313" failures="86" expectedFailures="14" skips="6"/> </Catch2TestRun> diff --git a/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp b/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp index cc8c54f8..4f906b99 100644 --- a/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp +++ b/tests/SelfTest/UsageTests/MatchersRanges.tests.cpp @@ -727,6 +727,15 @@ TEST_CASE( "Usage of RangeEquals range matcher", "[matchers][templated][quantifi } ) ); } + SECTION( "Compare against std::initializer_list" ) { + const std::array<int, 3> array_a{ { 1, 2, 3 } }; + + REQUIRE_THAT( array_a, RangeEquals( { 1, 2, 3 } ) ); + REQUIRE_THAT( array_a, RangeEquals( { 2, 4, 6 }, []( int l, int r ) { + return l * 2 == r; + } ) ); + } + SECTION("Check short-circuiting behaviour") { with_mocked_iterator_access<int> const mocked1{ 1, 2, 3, 4 }; @@ -820,6 +829,16 @@ TEST_CASE( "Usage of UnorderedRangeEquals range matcher", REQUIRE_THAT( needs_adl1, UnorderedRangeEquals( needs_adl2 ) ); } + + SECTION( "Compare against std::initializer_list" ) { + const std::array<int, 3> array_a{ { 1, 10, 20 } }; + + REQUIRE_THAT( array_a, UnorderedRangeEquals( { 10, 20, 1 } ) ); + REQUIRE_THAT( array_a, + UnorderedRangeEquals( { 11, 21, 2 }, []( int l, int r ) { + return std::abs( l - r ) <= 1; + } ) ); + } } /**