Fix tests for C++23's multi-arg index operator

Closes #2744
This commit is contained in:
Martin Hořeňovský 2023-10-28 21:49:49 +02:00
parent 6ebc013b8c
commit 79d39a1954
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
10 changed files with 33 additions and 20 deletions

View File

@ -46,7 +46,6 @@ function(add_warnings_to_targets targets)
set(CHECKED_WARNING_FLAGS set(CHECKED_WARNING_FLAGS
"-Wabsolute-value" "-Wabsolute-value"
"-Wall" "-Wall"
"-Wc++20-compat"
"-Wcall-to-pure-virtual-from-ctor-dtor" "-Wcall-to-pure-virtual-from-ctor-dtor"
"-Wcast-align" "-Wcast-align"
"-Wcatch-value" "-Wcatch-value"

View File

@ -331,7 +331,7 @@ MatchersRanges.tests.cpp:<line number>: passed: inner_lists_are_empty.front(), I
MatchersRanges.tests.cpp:<line number>: passed: has_empty{}, !IsEmpty() for: {?} not is empty MatchersRanges.tests.cpp:<line number>: passed: has_empty{}, !IsEmpty() for: {?} not is empty
MatchersRanges.tests.cpp:<line number>: passed: unrelated::ADL_empty{}, IsEmpty() for: {?} is empty MatchersRanges.tests.cpp:<line number>: passed: unrelated::ADL_empty{}, IsEmpty() for: {?} is empty
Message.tests.cpp:<line number>: passed: with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true' Message.tests.cpp:<line number>: passed: with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true'
Message.tests.cpp:<line number>: passed: with 7 messages: 'std::vector<int>{1, 2, 3}[0, 1, 2] := 3' and 'std::vector<int>{1, 2, 3}[(0, 1)] := 2' and 'std::vector<int>{1, 2, 3}[0] := 1' and '(helper_1436<int, int>{12, -12}) := { 12, -12 }' and '(helper_1436<int, int>(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3' Message.tests.cpp:<line number>: passed: with 7 messages: 'custom_index_op<int>{1, 2, 3}[0, 1, 2] := 0' and 'custom_index_op<int>{1, 2, 3}[(0, 1)] := 0' and 'custom_index_op<int>{1, 2, 3}[0] := 0' and '(helper_1436<int, int>{12, -12}) := { 12, -12 }' and '(helper_1436<int, int>(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3'
Message.tests.cpp:<line number>: passed: with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{'' Message.tests.cpp:<line number>: passed: with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{''
ToStringGeneral.tests.cpp:<line number>: passed: true with 1 message: 'i := 2' ToStringGeneral.tests.cpp:<line number>: passed: true with 1 message: 'i := 2'
ToStringGeneral.tests.cpp:<line number>: passed: true with 1 message: '3' ToStringGeneral.tests.cpp:<line number>: passed: true with 1 message: '3'

View File

@ -329,7 +329,7 @@ MatchersRanges.tests.cpp:<line number>: passed: inner_lists_are_empty.front(), I
MatchersRanges.tests.cpp:<line number>: passed: has_empty{}, !IsEmpty() for: {?} not is empty MatchersRanges.tests.cpp:<line number>: passed: has_empty{}, !IsEmpty() for: {?} not is empty
MatchersRanges.tests.cpp:<line number>: passed: unrelated::ADL_empty{}, IsEmpty() for: {?} is empty MatchersRanges.tests.cpp:<line number>: passed: unrelated::ADL_empty{}, IsEmpty() for: {?} is empty
Message.tests.cpp:<line number>: passed: with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true' Message.tests.cpp:<line number>: passed: with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true'
Message.tests.cpp:<line number>: passed: with 7 messages: 'std::vector<int>{1, 2, 3}[0, 1, 2] := 3' and 'std::vector<int>{1, 2, 3}[(0, 1)] := 2' and 'std::vector<int>{1, 2, 3}[0] := 1' and '(helper_1436<int, int>{12, -12}) := { 12, -12 }' and '(helper_1436<int, int>(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3' Message.tests.cpp:<line number>: passed: with 7 messages: 'custom_index_op<int>{1, 2, 3}[0, 1, 2] := 0' and 'custom_index_op<int>{1, 2, 3}[(0, 1)] := 0' and 'custom_index_op<int>{1, 2, 3}[0] := 0' and '(helper_1436<int, int>{12, -12}) := { 12, -12 }' and '(helper_1436<int, int>(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3'
Message.tests.cpp:<line number>: passed: with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{'' Message.tests.cpp:<line number>: passed: with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{''
ToStringGeneral.tests.cpp:<line number>: passed: true with 1 message: 'i := 2' ToStringGeneral.tests.cpp:<line number>: passed: true with 1 message: 'i := 2'
ToStringGeneral.tests.cpp:<line number>: passed: true with 1 message: '3' ToStringGeneral.tests.cpp:<line number>: passed: true with 1 message: '3'

View File

@ -2740,9 +2740,9 @@ Message.tests.cpp:<line number>
Message.tests.cpp:<line number>: PASSED: Message.tests.cpp:<line number>: PASSED:
with messages: with messages:
std::vector<int>{1, 2, 3}[0, 1, 2] := 3 custom_index_op<int>{1, 2, 3}[0, 1, 2] := 0
std::vector<int>{1, 2, 3}[(0, 1)] := 2 custom_index_op<int>{1, 2, 3}[(0, 1)] := 0
std::vector<int>{1, 2, 3}[0] := 1 custom_index_op<int>{1, 2, 3}[0] := 0
(helper_1436<int, int>{12, -12}) := { 12, -12 } (helper_1436<int, int>{12, -12}) := { 12, -12 }
(helper_1436<int, int>(-12, 12)) := { -12, 12 } (helper_1436<int, int>(-12, 12)) := { -12, 12 }
(1, 2) := 2 (1, 2) := 2

View File

@ -2738,9 +2738,9 @@ Message.tests.cpp:<line number>
Message.tests.cpp:<line number>: PASSED: Message.tests.cpp:<line number>: PASSED:
with messages: with messages:
std::vector<int>{1, 2, 3}[0, 1, 2] := 3 custom_index_op<int>{1, 2, 3}[0, 1, 2] := 0
std::vector<int>{1, 2, 3}[(0, 1)] := 2 custom_index_op<int>{1, 2, 3}[(0, 1)] := 0
std::vector<int>{1, 2, 3}[0] := 1 custom_index_op<int>{1, 2, 3}[0] := 0
(helper_1436<int, int>{12, -12}) := { 12, -12 } (helper_1436<int, int>{12, -12}) := { 12, -12 }
(helper_1436<int, int>(-12, 12)) := { -12, 12 } (helper_1436<int, int>(-12, 12)) := { -12, 12 }
(1, 2) := 2 (1, 2) := 2

View File

@ -659,7 +659,7 @@ ok {test-number} - unrelated::ADL_empty{}, IsEmpty() for: {?} is empty
# CAPTURE can deal with complex expressions # CAPTURE can deal with complex expressions
ok {test-number} - with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true' ok {test-number} - with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true'
# CAPTURE can deal with complex expressions involving commas # CAPTURE can deal with complex expressions involving commas
ok {test-number} - with 7 messages: 'std::vector<int>{1, 2, 3}[0, 1, 2] := 3' and 'std::vector<int>{1, 2, 3}[(0, 1)] := 2' and 'std::vector<int>{1, 2, 3}[0] := 1' and '(helper_1436<int, int>{12, -12}) := { 12, -12 }' and '(helper_1436<int, int>(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3' ok {test-number} - with 7 messages: 'custom_index_op<int>{1, 2, 3}[0, 1, 2] := 0' and 'custom_index_op<int>{1, 2, 3}[(0, 1)] := 0' and 'custom_index_op<int>{1, 2, 3}[0] := 0' and '(helper_1436<int, int>{12, -12}) := { 12, -12 }' and '(helper_1436<int, int>(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3'
# CAPTURE parses string and character constants # CAPTURE parses string and character constants
ok {test-number} - with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{'' ok {test-number} - with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{''
# Capture and info messages # Capture and info messages

View File

@ -657,7 +657,7 @@ ok {test-number} - unrelated::ADL_empty{}, IsEmpty() for: {?} is empty
# CAPTURE can deal with complex expressions # CAPTURE can deal with complex expressions
ok {test-number} - with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true' ok {test-number} - with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true'
# CAPTURE can deal with complex expressions involving commas # CAPTURE can deal with complex expressions involving commas
ok {test-number} - with 7 messages: 'std::vector<int>{1, 2, 3}[0, 1, 2] := 3' and 'std::vector<int>{1, 2, 3}[(0, 1)] := 2' and 'std::vector<int>{1, 2, 3}[0] := 1' and '(helper_1436<int, int>{12, -12}) := { 12, -12 }' and '(helper_1436<int, int>(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3' ok {test-number} - with 7 messages: 'custom_index_op<int>{1, 2, 3}[0, 1, 2] := 0' and 'custom_index_op<int>{1, 2, 3}[(0, 1)] := 0' and 'custom_index_op<int>{1, 2, 3}[0] := 0' and '(helper_1436<int, int>{12, -12}) := { 12, -12 }' and '(helper_1436<int, int>(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3'
# CAPTURE parses string and character constants # CAPTURE parses string and character constants
ok {test-number} - with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{'' ok {test-number} - with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{''
# Capture and info messages # Capture and info messages

View File

@ -2911,13 +2911,13 @@ Nor would this
</TestCase> </TestCase>
<TestCase name="CAPTURE can deal with complex expressions involving commas" tags="[capture][messages]" filename="tests/<exe-name>/UsageTests/Message.tests.cpp" > <TestCase name="CAPTURE can deal with complex expressions involving commas" tags="[capture][messages]" filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" > <Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
std::vector&lt;int>{1, 2, 3}[0, 1, 2] := 3 custom_index_op&lt;int>{1, 2, 3}[0, 1, 2] := 0
</Info> </Info>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" > <Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
std::vector&lt;int>{1, 2, 3}[(0, 1)] := 2 custom_index_op&lt;int>{1, 2, 3}[(0, 1)] := 0
</Info> </Info>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" > <Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
std::vector&lt;int>{1, 2, 3}[0] := 1 custom_index_op&lt;int>{1, 2, 3}[0] := 0
</Info> </Info>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" > <Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
(helper_1436&lt;int, int>{12, -12}) := { 12, -12 } (helper_1436&lt;int, int>{12, -12}) := { 12, -12 }

View File

@ -2911,13 +2911,13 @@ Nor would this
</TestCase> </TestCase>
<TestCase name="CAPTURE can deal with complex expressions involving commas" tags="[capture][messages]" filename="tests/<exe-name>/UsageTests/Message.tests.cpp" > <TestCase name="CAPTURE can deal with complex expressions involving commas" tags="[capture][messages]" filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" > <Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
std::vector&lt;int>{1, 2, 3}[0, 1, 2] := 3 custom_index_op&lt;int>{1, 2, 3}[0, 1, 2] := 0
</Info> </Info>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" > <Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
std::vector&lt;int>{1, 2, 3}[(0, 1)] := 2 custom_index_op&lt;int>{1, 2, 3}[(0, 1)] := 0
</Info> </Info>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" > <Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
std::vector&lt;int>{1, 2, 3}[0] := 1 custom_index_op&lt;int>{1, 2, 3}[0] := 0
</Info> </Info>
<Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" > <Info filename="tests/<exe-name>/UsageTests/Message.tests.cpp" >
(helper_1436&lt;int, int>{12, -12}) := { 12, -12 } (helper_1436&lt;int, int>{12, -12}) := { 12, -12 }

View File

@ -255,10 +255,24 @@ std::ostream& operator<<(std::ostream& out, helper_1436<T1, T2> const& helper) {
#pragma clang diagnostic ignored "-Wunused-value" #pragma clang diagnostic ignored "-Wunused-value"
#endif #endif
namespace {
template <typename T>
struct custom_index_op {
constexpr custom_index_op( std::initializer_list<T> ) {}
constexpr T operator[]( size_t ) { return T{}; }
#if defined( __cpp_multidimensional_subscript ) && \
__cpp_multidimensional_subscript >= 202110L
constexpr T operator[]( size_t, size_t, size_t ) const noexcept {
return T{};
}
#endif
};
}
TEST_CASE("CAPTURE can deal with complex expressions involving commas", "[messages][capture]") { TEST_CASE("CAPTURE can deal with complex expressions involving commas", "[messages][capture]") {
CAPTURE(std::vector<int>{1, 2, 3}[0, 1, 2], CAPTURE(custom_index_op<int>{1, 2, 3}[0, 1, 2],
std::vector<int>{1, 2, 3}[(0, 1)], custom_index_op<int>{1, 2, 3}[(0, 1)],
std::vector<int>{1, 2, 3}[0]); custom_index_op<int>{1, 2, 3}[0]);
CAPTURE((helper_1436<int, int>{12, -12}), CAPTURE((helper_1436<int, int>{12, -12}),
(helper_1436<int, int>(-12, 12))); (helper_1436<int, int>(-12, 12)));
CAPTURE( (1, 2), (2, 3) ); CAPTURE( (1, 2), (2, 3) );