Skip to content

Commit

Permalink
Use a non-concepts method of checking random-access iterators
Browse files Browse the repository at this point in the history
This means C++20 isn't needed and we can always test this.
  • Loading branch information
johnbeard committed Mar 6, 2022
1 parent 4aebfd6 commit 9080853
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 23 deletions.
1 change: 1 addition & 0 deletions tests/SelfTest/Baselines/compact.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,7 @@ MatchersRanges.tests.cpp:<line number>: passed: array_int_3, !ElementsAre( array
MatchersRanges.tests.cpp:<line number>: passed: array_int_3, !UnorderedElementsAre( array_int_4 ) for: { 1, 2, 3 } not unordered elements are { 1, 2, 3, 4 }
MatchersRanges.tests.cpp:<line number>: passed: array_int_a, ElementsAre( vector_char_a ) for: { 1, 2, 3 } elements are { 1, 2, 3 }
MatchersRanges.tests.cpp:<line number>: passed: array_int_a, UnorderedElementsAre( vector_char_a ) for: { 1, 2, 3 } unordered elements are { 1, 2, 3 }
MatchersRanges.tests.cpp:<line number>: passed: with 1 message: 'ContainerIsRandomAccess( array_int_a ) != ContainerIsRandomAccess( list_char_a )'
MatchersRanges.tests.cpp:<line number>: passed: array_int_a, ElementsAre( list_char_a ) for: { 1, 2, 3 } elements are { 1, 2, 3 }
MatchersRanges.tests.cpp:<line number>: passed: array_int_a, UnorderedElementsAre( list_char_a ) for: { 1, 2, 3 } unordered elements are { 1, 2, 3 }
MatchersRanges.tests.cpp:<line number>: passed: vector_int_a, ElementsAre( vector_char_a ) for: { 1, 2, 3 } elements are { 1, 2, 3 }
Expand Down
1 change: 1 addition & 0 deletions tests/SelfTest/Baselines/compact.sw.multi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,7 @@ MatchersRanges.tests.cpp:<line number>: passed: array_int_3, !ElementsAre( array
MatchersRanges.tests.cpp:<line number>: passed: array_int_3, !UnorderedElementsAre( array_int_4 ) for: { 1, 2, 3 } not unordered elements are { 1, 2, 3, 4 }
MatchersRanges.tests.cpp:<line number>: passed: array_int_a, ElementsAre( vector_char_a ) for: { 1, 2, 3 } elements are { 1, 2, 3 }
MatchersRanges.tests.cpp:<line number>: passed: array_int_a, UnorderedElementsAre( vector_char_a ) for: { 1, 2, 3 } unordered elements are { 1, 2, 3 }
MatchersRanges.tests.cpp:<line number>: passed: with 1 message: 'ContainerIsRandomAccess( array_int_a ) != ContainerIsRandomAccess( list_char_a )'
MatchersRanges.tests.cpp:<line number>: passed: array_int_a, ElementsAre( list_char_a ) for: { 1, 2, 3 } elements are { 1, 2, 3 }
MatchersRanges.tests.cpp:<line number>: passed: array_int_a, UnorderedElementsAre( list_char_a ) for: { 1, 2, 3 } unordered elements are { 1, 2, 3 }
MatchersRanges.tests.cpp:<line number>: passed: vector_int_a, ElementsAre( vector_char_a ) for: { 1, 2, 3 } elements are { 1, 2, 3 }
Expand Down
2 changes: 1 addition & 1 deletion tests/SelfTest/Baselines/console.std.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1396,5 +1396,5 @@ due to unexpected exception with message:

===============================================================================
test cases: 386 | 310 passed | 69 failed | 7 failed as expected
assertions: 2246 | 2091 passed | 128 failed | 27 failed as expected
assertions: 2247 | 2092 passed | 128 failed | 27 failed as expected

7 changes: 6 additions & 1 deletion tests/SelfTest/Baselines/console.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13937,6 +13937,11 @@ Type conversions of ElementsAre and similar
MatchersRanges.tests.cpp:<line number>
...............................................................................

MatchersRanges.tests.cpp:<line number>: PASSED:
with message:
ContainerIsRandomAccess( array_int_a ) != ContainerIsRandomAccess(
list_char_a )

MatchersRanges.tests.cpp:<line number>: PASSED:
CHECK_THAT( array_int_a, ElementsAre( list_char_a ) )
with expansion:
Expand Down Expand Up @@ -18136,5 +18141,5 @@ Misc.tests.cpp:<line number>: PASSED:

===============================================================================
test cases: 386 | 296 passed | 83 failed | 7 failed as expected
assertions: 2261 | 2091 passed | 143 failed | 27 failed as expected
assertions: 2262 | 2092 passed | 143 failed | 27 failed as expected

7 changes: 6 additions & 1 deletion tests/SelfTest/Baselines/console.sw.multi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13930,6 +13930,11 @@ Type conversions of ElementsAre and similar
MatchersRanges.tests.cpp:<line number>
...............................................................................

MatchersRanges.tests.cpp:<line number>: PASSED:
with message:
ContainerIsRandomAccess( array_int_a ) != ContainerIsRandomAccess(
list_char_a )

MatchersRanges.tests.cpp:<line number>: PASSED:
CHECK_THAT( array_int_a, ElementsAre( list_char_a ) )
with expansion:
Expand Down Expand Up @@ -18128,5 +18133,5 @@ Misc.tests.cpp:<line number>: PASSED:

===============================================================================
test cases: 386 | 296 passed | 83 failed | 7 failed as expected
assertions: 2261 | 2091 passed | 143 failed | 27 failed as expected
assertions: 2262 | 2092 passed | 143 failed | 27 failed as expected

2 changes: 1 addition & 1 deletion tests/SelfTest/Baselines/junit.sw.approved.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="17" failures="126" tests="2261" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="126" tests="2262" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/SelfTest/Baselines/junit.sw.multi.approved.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="<exe-name>" errors="17" failures="126" tests="2261" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="17" failures="126" tests="2262" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties>
<property name="random-seed" value="1"/>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/>
Expand Down
4 changes: 3 additions & 1 deletion tests/SelfTest/Baselines/tap.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3486,6 +3486,8 @@ ok {test-number} - array_int_a, ElementsAre( vector_char_a ) for: { 1, 2, 3 } el
# Type conversions of ElementsAre and similar
ok {test-number} - array_int_a, UnorderedElementsAre( vector_char_a ) for: { 1, 2, 3 } unordered elements are { 1, 2, 3 }
# Type conversions of ElementsAre and similar
ok {test-number} - with 1 message: 'ContainerIsRandomAccess( array_int_a ) != ContainerIsRandomAccess( list_char_a )'
# Type conversions of ElementsAre and similar
ok {test-number} - array_int_a, ElementsAre( list_char_a ) for: { 1, 2, 3 } elements are { 1, 2, 3 }
# Type conversions of ElementsAre and similar
ok {test-number} - array_int_a, UnorderedElementsAre( list_char_a ) for: { 1, 2, 3 } unordered elements are { 1, 2, 3 }
Expand Down Expand Up @@ -4524,5 +4526,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2261
1..2262

4 changes: 3 additions & 1 deletion tests/SelfTest/Baselines/tap.sw.multi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3479,6 +3479,8 @@ ok {test-number} - array_int_a, ElementsAre( vector_char_a ) for: { 1, 2, 3 } el
# Type conversions of ElementsAre and similar
ok {test-number} - array_int_a, UnorderedElementsAre( vector_char_a ) for: { 1, 2, 3 } unordered elements are { 1, 2, 3 }
# Type conversions of ElementsAre and similar
ok {test-number} - with 1 message: 'ContainerIsRandomAccess( array_int_a ) != ContainerIsRandomAccess( list_char_a )'
# Type conversions of ElementsAre and similar
ok {test-number} - array_int_a, ElementsAre( list_char_a ) for: { 1, 2, 3 } elements are { 1, 2, 3 }
# Type conversions of ElementsAre and similar
ok {test-number} - array_int_a, UnorderedElementsAre( list_char_a ) for: { 1, 2, 3 } unordered elements are { 1, 2, 3 }
Expand Down Expand Up @@ -4516,5 +4518,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0
ok {test-number} -
# xmlentitycheck
ok {test-number} -
1..2261
1..2262

6 changes: 3 additions & 3 deletions tests/SelfTest/Baselines/xml.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16389,9 +16389,9 @@ There is no extra whitespace here
{ 1, 2, 3 } unordered elements are { 1, 2, 3 }
</Expanded>
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<Section name="Value type" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
<Section name="Two equal containers of different value types" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
Expand Down Expand Up @@ -21312,6 +21312,6 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="2091" failures="143" expectedFailures="27"/>
<OverallResults successes="2092" failures="143" expectedFailures="27"/>
<OverallResultsCases successes="296" failures="83" expectedFailures="7"/>
</Catch2TestRun>
6 changes: 3 additions & 3 deletions tests/SelfTest/Baselines/xml.sw.multi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16389,9 +16389,9 @@ There is no extra whitespace here
{ 1, 2, 3 } unordered elements are { 1, 2, 3 }
</Expanded>
</Expression>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<OverallResults successes="2" failures="0" expectedFailures="0"/>
<OverallResults successes="3" failures="0" expectedFailures="0"/>
</Section>
<Section name="Value type" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
<Section name="Two equal containers of different value types" filename="tests/<exe-name>/UsageTests/MatchersRanges.tests.cpp" >
Expand Down Expand Up @@ -21311,6 +21311,6 @@ There is no extra whitespace here
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="2091" failures="143" expectedFailures="27"/>
<OverallResults successes="2092" failures="143" expectedFailures="27"/>
<OverallResultsCases successes="296" failures="83" expectedFailures="7"/>
</Catch2TestRun>
24 changes: 14 additions & 10 deletions tests/SelfTest/UsageTests/MatchersRanges.tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
#include <map>
#include <vector>

#if defined(__cpp_concepts) && __cpp_concepts >= 201907L
#define CONCEPT_TESTING
#include <concepts>
#endif

namespace {
namespace unrelated {
class needs_ADL_begin {
Expand Down Expand Up @@ -683,6 +678,18 @@ TEST_CASE( "Usage of UnorderedElementsAre range matcher",
// are left to the STL implementation
}

/**
* Return true if the type given has a random access iterator type.
*/
template <typename Container>
static constexpr bool ContainerIsRandomAccess( const Container& ) {
using array_iter_category = typename std::iterator_traits<
typename Container::iterator>::iterator_category;

return std::is_base_of<std::random_access_iterator_tag,
array_iter_category>::value;
}

TEST_CASE( "Type conversions of ElementsAre and similar",
"[matchers][templated][quantifiers]" ) {
using Catch::Matchers::ElementsAre;
Expand Down Expand Up @@ -718,11 +725,9 @@ TEST_CASE( "Type conversions of ElementsAre and similar",
const std::array<int, 3> array_int_a{ { 1, 2, 3 } };
const std::list<int> list_char_a{ 1, 2, 3 };

#ifdef CONCEPT_TESTING
// Verify these types really are different in random access nature
static_assert( std::random_access_iterator<decltype(array_int_a)::iterator> );
static_assert( !std::random_access_iterator<decltype(list_char_a)::iterator> );
#endif
STATIC_REQUIRE( ContainerIsRandomAccess( array_int_a ) !=
ContainerIsRandomAccess( list_char_a ) );

CHECK_THAT( array_int_a, ElementsAre( list_char_a ) );
CHECK_THAT( array_int_a, UnorderedElementsAre( list_char_a ) );
Expand All @@ -744,7 +749,6 @@ TEST_CASE( "Type conversions of ElementsAre and similar",
}
}


SECTION( "Custom predicate" ) {

auto close_enough = []( int lhs, int rhs ) {
Expand Down

0 comments on commit 9080853

Please sign in to comment.