diff --git a/src/catch2/catch_message.cpp b/src/catch2/catch_message.cpp index d3914a8059..ba269cfb80 100644 --- a/src/catch2/catch_message.cpp +++ b/src/catch2/catch_message.cpp @@ -39,8 +39,9 @@ namespace Catch { Capturer::Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, - StringRef names ): + StringRef names, bool scoped): m_resultCapture( getResultCapture() ) { + isScoped = scoped; auto trimmed = [&] (size_t start, size_t end) { while (names[start] == ',' || isspace(static_cast(names[start]))) { ++start; @@ -106,10 +107,20 @@ namespace Catch { } void Capturer::captureValue( size_t index, std::string const& value ) { - assert( index < m_messages.size() ); - m_messages[index].message += value; - m_resultCapture.pushScopedMessage( m_messages[index] ); - m_captured++; + if(isScoped){ + assert( index < m_messages.size() ); + m_messages[index].message += value; + m_resultCapture.pushScopedMessage( m_messages[index] ); + m_captured++; + } else { + getResultCapture().emplaceUnscopedMessage(Catch::MessageBuilder( + m_messages[index].macroName, + m_messages[index].lineInfo, + m_messages[index].type) << value); + if(index == m_messages.size() - 1){ + m_messages.clear(); + } + } } } // end namespace Catch diff --git a/src/catch2/catch_message.hpp b/src/catch2/catch_message.hpp index 0a738341c2..fef2a65e48 100644 --- a/src/catch2/catch_message.hpp +++ b/src/catch2/catch_message.hpp @@ -65,8 +65,9 @@ namespace Catch { std::vector m_messages; IResultCapture& m_resultCapture; size_t m_captured = 0; + bool isScoped; public: - Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ); + Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names, bool scoped ); Capturer(Capturer const&) = delete; Capturer& operator=(Capturer const&) = delete; @@ -102,9 +103,19 @@ namespace Catch { Catch::Capturer varName( macroName##_catch_sr, \ CATCH_INTERNAL_LINEINFO, \ Catch::ResultWas::Info, \ - #__VA_ARGS__##_catch_sr ); \ + #__VA_ARGS__##_catch_sr, \ + true ); \ varName.captureValues( 0, __VA_ARGS__ ) +/////////////////////////////////////////////////////////////////////////////// +#define INTERNAL_CATCH_UNSCOPED_CAPTURE( varName, macroName, ... ) \ + Catch::Capturer varName( macroName##_catch_sr, \ + CATCH_INTERNAL_LINEINFO, \ + Catch::ResultWas::Info, \ + #__VA_ARGS__##_catch_sr, \ + false ); \ + varName.captureValues( 0, __VA_ARGS__ ); + /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_INFO( macroName, log ) \ const Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log ) @@ -120,13 +131,15 @@ namespace Catch { #define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg ) #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) #define CATCH_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE", __VA_ARGS__ ) + #define CATCH_UNSCOPED_CAPTURE( ... ) INTERNAL_CATCH_UNSCOPED_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_UNSCOPED_CAPTURE", __VA_ARGS__ ) #elif defined(CATCH_CONFIG_PREFIX_MESSAGES) && defined(CATCH_CONFIG_DISABLE) - #define CATCH_INFO( msg ) (void)(0) - #define CATCH_UNSCOPED_INFO( msg ) (void)(0) - #define CATCH_WARN( msg ) (void)(0) - #define CATCH_CAPTURE( ... ) (void)(0) + #define CATCH_INFO( msg ) (void)(0) + #define CATCH_UNSCOPED_INFO( msg ) (void)(0) + #define CATCH_WARN( msg ) (void)(0) + #define CATCH_CAPTURE( ... ) (void)(0) + #define CATCH_UNSCOPED_CAPTURE( ... ) (void)(0) #elif !defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE) @@ -134,14 +147,16 @@ namespace Catch { #define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg ) #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg ) #define CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE", __VA_ARGS__ ) + #define UNSCOPED_CAPTURE( ... ) INTERNAL_CATCH_UNSCOPED_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "UNSCOPED_CAPTURE", __VA_ARGS__ ) -#elif !defined(CATCH_CONFIG_PREFIX_MESSAGES) && defined(CATCH_CONFIG_DISABLE) - #define INFO( msg ) (void)(0) - #define UNSCOPED_INFO( msg ) (void)(0) - #define WARN( msg ) (void)(0) - #define CAPTURE( ... ) (void)(0) +#elif !defined(CATCH_CONFIG_PREFIX_MESSAGES) && defined(CATCH_CONFIG_DISABLE) + #define INFO(msg) (void)(0) + #define UNSCOPED_INFO(msg) (void)(0) + #define WARN(msg) (void)(0) + #define CAPTURE(...) (void)(0) + #define UNSCOPED_CAPTURE(...) (void)(0) #endif // end of user facing macro declarations diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index 4a6886d6c2..e21373a89b 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -297,6 +297,8 @@ Message from section two :test-result: PASS Tracker :test-result: PASS Trim strings :test-result: PASS Type conversions of RangeEquals and similar +:test-result: PASS UNSCOPED CAPTURE can deal with complex expressions +:test-result: PASS UNSCOPED_CAPTURE parses string and character constants :test-result: FAIL Unexpected exceptions can be translated :test-result: PASS Upcasting special member functions :test-result: PASS Usage of AllMatch range matcher @@ -396,6 +398,8 @@ b1! :test-result: PASS shortened hide tags are split apart :test-result: SKIP skipped tests can optionally provide a reason :test-result: PASS splitString +:test-result: FAIL stacks unscoped capture for vector +:test-result: FAIL stacks unscoped capture in loops :test-result: FAIL stacks unscoped info in loops :test-result: PASS startsWith :test-result: PASS std::map is convertible string diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index b0d30b87d9..e0769e6d57 100644 --- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -290,6 +290,8 @@ :test-result: PASS Tracker :test-result: PASS Trim strings :test-result: PASS Type conversions of RangeEquals and similar +:test-result: PASS UNSCOPED CAPTURE can deal with complex expressions +:test-result: PASS UNSCOPED_CAPTURE parses string and character constants :test-result: FAIL Unexpected exceptions can be translated :test-result: PASS Upcasting special member functions :test-result: PASS Usage of AllMatch range matcher @@ -385,6 +387,8 @@ :test-result: PASS shortened hide tags are split apart :test-result: SKIP skipped tests can optionally provide a reason :test-result: PASS splitString +:test-result: FAIL stacks unscoped capture for vector +:test-result: FAIL stacks unscoped capture in loops :test-result: FAIL stacks unscoped info in loops :test-result: PASS startsWith :test-result: PASS std::map is convertible string diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 323da08ee7..2dfa1cb302 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -2194,6 +2194,8 @@ MatchersRanges.tests.cpp:: passed: a, !RangeEquals( b ) for: { 1, 2 MatchersRanges.tests.cpp:: passed: a, UnorderedRangeEquals( b ) for: { 1, 2, 3 } unordered elements are { 3, 2, 1 } MatchersRanges.tests.cpp:: passed: vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } elements are { 2, 3, 4 } MatchersRanges.tests.cpp:: passed: vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 } +Message.tests.cpp:: passed: with 7 messages: '1' and '2' and '3' and '3' and '3' and 'true' and 'true' +Message.tests.cpp:: passed: with 11 messages: '"escaped, ", "' and '"single quote in string,',"' and '"some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<"' and ''"'' and ''''' and '','' and ''}'' and '')'' and ''('' and ''{'' Exception.tests.cpp:: failed: unexpected exception with message: '3.14000000000000012' UniquePtr.tests.cpp:: passed: bptr->i == 3 for: 3 == 3 UniquePtr.tests.cpp:: passed: bptr->i == 3 for: 3 == 3 @@ -2720,6 +2722,9 @@ Skip.tests.cpp:: skipped: 'skipping because answer = 43' StringManip.tests.cpp:: passed: splitStringRef("", ','), Equals(std::vector()) for: { } Equals: { } StringManip.tests.cpp:: passed: splitStringRef("abc", ','), Equals(std::vector{"abc"}) for: { abc } Equals: { abc } StringManip.tests.cpp:: passed: splitStringRef("abc,def", ','), Equals(std::vector{"abc", "def"}) for: { abc, def } Equals: { abc, def } +Message.tests.cpp:: failed: false with 1 message: '{ 7, 8, 9 }' +Message.tests.cpp:: failed: false with 4 messages: '"Count 1 to 3..."' and '1' and '2' and '3' +Message.tests.cpp:: failed: false with 4 messages: '"Count 4 to 6..."' and '4' and '5' and '6' Message.tests.cpp:: failed: false with 4 messages: 'Count 1 to 3...' and '1' and '2' and '3' Message.tests.cpp:: failed: false with 4 messages: 'Count 4 to 6...' and '4' and '5' and '6' StringManip.tests.cpp:: passed: !(startsWith("", 'c')) for: !false @@ -2884,7 +2889,7 @@ InternalBenchmark.tests.cpp:: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: -test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected -assertions: 2299 | 2101 passed | 157 failed | 41 failed as expected +test cases: 439 | 319 passed | 97 failed | 6 skipped | 17 failed as expected +assertions: 2304 | 2103 passed | 160 failed | 41 failed as expected diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index 57b54ce1d9..7491f920c5 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -2187,6 +2187,8 @@ MatchersRanges.tests.cpp:: passed: a, !RangeEquals( b ) for: { 1, 2 MatchersRanges.tests.cpp:: passed: a, UnorderedRangeEquals( b ) for: { 1, 2, 3 } unordered elements are { 3, 2, 1 } MatchersRanges.tests.cpp:: passed: vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } elements are { 2, 3, 4 } MatchersRanges.tests.cpp:: passed: vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 } +Message.tests.cpp:: passed: with 7 messages: '1' and '2' and '3' and '3' and '3' and 'true' and 'true' +Message.tests.cpp:: passed: with 11 messages: '"escaped, ", "' and '"single quote in string,',"' and '"some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<"' and ''"'' and ''''' and '','' and ''}'' and '')'' and ''('' and ''{'' Exception.tests.cpp:: failed: unexpected exception with message: '3.14000000000000012' UniquePtr.tests.cpp:: passed: bptr->i == 3 for: 3 == 3 UniquePtr.tests.cpp:: passed: bptr->i == 3 for: 3 == 3 @@ -2709,6 +2711,9 @@ Skip.tests.cpp:: skipped: 'skipping because answer = 43' StringManip.tests.cpp:: passed: splitStringRef("", ','), Equals(std::vector()) for: { } Equals: { } StringManip.tests.cpp:: passed: splitStringRef("abc", ','), Equals(std::vector{"abc"}) for: { abc } Equals: { abc } StringManip.tests.cpp:: passed: splitStringRef("abc,def", ','), Equals(std::vector{"abc", "def"}) for: { abc, def } Equals: { abc, def } +Message.tests.cpp:: failed: false with 1 message: '{ 7, 8, 9 }' +Message.tests.cpp:: failed: false with 4 messages: '"Count 1 to 3..."' and '1' and '2' and '3' +Message.tests.cpp:: failed: false with 4 messages: '"Count 4 to 6..."' and '4' and '5' and '6' Message.tests.cpp:: failed: false with 4 messages: 'Count 1 to 3...' and '1' and '2' and '3' Message.tests.cpp:: failed: false with 4 messages: 'Count 4 to 6...' and '4' and '5' and '6' StringManip.tests.cpp:: passed: !(startsWith("", 'c')) for: !false @@ -2873,7 +2878,7 @@ InternalBenchmark.tests.cpp:: passed: med == 18. for: 18.0 == 18.0 InternalBenchmark.tests.cpp:: passed: q3 == 23. for: 23.0 == 23.0 Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: -test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected -assertions: 2299 | 2101 passed | 157 failed | 41 failed as expected +test cases: 439 | 319 passed | 97 failed | 6 skipped | 17 failed as expected +assertions: 2304 | 2103 passed | 160 failed | 41 failed as expected diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index c849d5ee4d..1f36082f9f 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1678,6 +1678,39 @@ Skip.tests.cpp:: SKIPPED: explicitly with message: skipping because answer = 43 +------------------------------------------------------------------------------- +stacks unscoped capture for vector +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with message: + { 7, 8, 9 } + +------------------------------------------------------------------------------- +stacks unscoped capture in loops +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with messages: + "Count 1 to 3..." + 1 + 2 + 3 + +Message.tests.cpp:: FAILED: + CHECK( false ) +with messages: + "Count 4 to 6..." + 4 + 5 + 6 + ------------------------------------------------------------------------------- stacks unscoped info in loops ------------------------------------------------------------------------------- @@ -1719,6 +1752,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 435 | 335 passed | 76 failed | 7 skipped | 17 failed as expected -assertions: 2278 | 2101 passed | 136 failed | 41 failed as expected +test cases: 439 | 337 passed | 78 failed | 7 skipped | 17 failed as expected +assertions: 2283 | 2103 passed | 139 failed | 41 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index 394c4182f1..8390d91f17 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -14232,6 +14232,42 @@ MatchersRanges.tests.cpp:: PASSED: with expansion: { 1, 2, 3 } unordered elements are { 2, 3, 4 } +------------------------------------------------------------------------------- +UNSCOPED CAPTURE can deal with complex expressions +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: PASSED: +with messages: + 1 + 2 + 3 + 3 + 3 + true + true + +------------------------------------------------------------------------------- +UNSCOPED_CAPTURE parses string and character constants +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: PASSED: +with messages: + "escaped, ", " + "single quote in string,'," + "some escapes, \,\\" + "some, ), unmatched, } prenheses {[<" + '"' + ''' + ',' + '}' + ')' + '(' + '{' + ------------------------------------------------------------------------------- Unexpected exceptions can be translated ------------------------------------------------------------------------------- @@ -18117,6 +18153,39 @@ StringManip.tests.cpp:: PASSED: with expansion: { abc, def } Equals: { abc, def } +------------------------------------------------------------------------------- +stacks unscoped capture for vector +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with message: + { 7, 8, 9 } + +------------------------------------------------------------------------------- +stacks unscoped capture in loops +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with messages: + "Count 1 to 3..." + 1 + 2 + 3 + +Message.tests.cpp:: FAILED: + CHECK( false ) +with messages: + "Count 4 to 6..." + 4 + 5 + 6 + ------------------------------------------------------------------------------- stacks unscoped info in loops ------------------------------------------------------------------------------- @@ -19267,6 +19336,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected -assertions: 2299 | 2101 passed | 157 failed | 41 failed as expected +test cases: 439 | 319 passed | 97 failed | 6 skipped | 17 failed as expected +assertions: 2304 | 2103 passed | 160 failed | 41 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index 018864fe8d..7a6ea12b21 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -14225,6 +14225,42 @@ MatchersRanges.tests.cpp:: PASSED: with expansion: { 1, 2, 3 } unordered elements are { 2, 3, 4 } +------------------------------------------------------------------------------- +UNSCOPED CAPTURE can deal with complex expressions +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: PASSED: +with messages: + 1 + 2 + 3 + 3 + 3 + true + true + +------------------------------------------------------------------------------- +UNSCOPED_CAPTURE parses string and character constants +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: PASSED: +with messages: + "escaped, ", " + "single quote in string,'," + "some escapes, \,\\" + "some, ), unmatched, } prenheses {[<" + '"' + ''' + ',' + '}' + ')' + '(' + '{' + ------------------------------------------------------------------------------- Unexpected exceptions can be translated ------------------------------------------------------------------------------- @@ -18106,6 +18142,39 @@ StringManip.tests.cpp:: PASSED: with expansion: { abc, def } Equals: { abc, def } +------------------------------------------------------------------------------- +stacks unscoped capture for vector +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with message: + { 7, 8, 9 } + +------------------------------------------------------------------------------- +stacks unscoped capture in loops +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + CHECK( false ) +with messages: + "Count 1 to 3..." + 1 + 2 + 3 + +Message.tests.cpp:: FAILED: + CHECK( false ) +with messages: + "Count 4 to 6..." + 4 + 5 + 6 + ------------------------------------------------------------------------------- stacks unscoped info in loops ------------------------------------------------------------------------------- @@ -19256,6 +19325,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 435 | 317 passed | 95 failed | 6 skipped | 17 failed as expected -assertions: 2299 | 2101 passed | 157 failed | 41 failed as expected +test cases: 439 | 319 passed | 97 failed | 6 skipped | 17 failed as expected +assertions: 2304 | 2103 passed | 160 failed | 41 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 42a98dd0a4..3496927757 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -1675,6 +1675,8 @@ at Exception.tests.cpp: + + FAILED: @@ -2292,6 +2294,34 @@ at Skip.tests.cpp: + + +FAILED: + CHECK( false ) +{ 7, 8, 9 } +at Message.tests.cpp: + + + + +FAILED: + CHECK( false ) +"Count 1 to 3..." +1 +2 +3 +at Message.tests.cpp: + + +FAILED: + CHECK( false ) +"Count 4 to 6..." +4 +5 +6 +at Message.tests.cpp: + + FAILED: diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index 5f17b49dc5..20fea80b4f 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ - + @@ -1674,6 +1674,8 @@ at Exception.tests.cpp: + + FAILED: @@ -2291,6 +2293,34 @@ at Skip.tests.cpp: + + +FAILED: + CHECK( false ) +{ 7, 8, 9 } +at Message.tests.cpp: + + + + +FAILED: + CHECK( false ) +"Count 1 to 3..." +1 +2 +3 +at Message.tests.cpp: + + +FAILED: + CHECK( false ) +"Count 4 to 6..." +4 +5 +6 +at Message.tests.cpp: + + FAILED: diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 9f1fbda6ee..13e8dbecb6 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -1822,6 +1822,8 @@ at Message.tests.cpp: + + FAILED: @@ -1871,6 +1873,34 @@ FAILED: REQUIRE( false ) hi i := 7 +at Message.tests.cpp: + + + + +FAILED: + CHECK( false ) +{ 7, 8, 9 } +at Message.tests.cpp: + + + + +FAILED: + CHECK( false ) +"Count 1 to 3..." +1 +2 +3 +at Message.tests.cpp: + + +FAILED: + CHECK( false ) +"Count 4 to 6..." +4 +5 +6 at Message.tests.cpp: diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index ce9bd5343e..9d61b0d4ad 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -1821,6 +1821,8 @@ at Message.tests.cpp: + + FAILED: @@ -1870,6 +1872,34 @@ FAILED: REQUIRE( false ) hi i := 7 +at Message.tests.cpp: + + + + +FAILED: + CHECK( false ) +{ 7, 8, 9 } +at Message.tests.cpp: + + + + +FAILED: + CHECK( false ) +"Count 1 to 3..." +1 +2 +3 +at Message.tests.cpp: + + +FAILED: + CHECK( false ) +"Count 4 to 6..." +4 +5 +6 at Message.tests.cpp: diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 699d78c2cd..7282bf7c12 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -3395,6 +3395,10 @@ ok {test-number} - a, UnorderedRangeEquals( b ) for: { 1, 2, 3 } unordered eleme ok {test-number} - vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } elements are { 2, 3, 4 } # Type conversions of RangeEquals and similar ok {test-number} - vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 } +# UNSCOPED CAPTURE can deal with complex expressions +ok {test-number} - with 7 messages: '1' and '2' and '3' and '3' and '3' and 'true' and 'true' +# UNSCOPED_CAPTURE parses string and character constants +ok {test-number} - with 11 messages: '"escaped, ", "' and '"single quote in string,',"' and '"some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<"' and ''"'' and ''''' and '','' and ''}'' and '')'' and ''('' and ''{'' # Unexpected exceptions can be translated not ok {test-number} - unexpected exception with message: '3.14000000000000012' # Upcasting special member functions @@ -4363,6 +4367,12 @@ ok {test-number} - splitStringRef("", ','), Equals(std::vector()) for ok {test-number} - splitStringRef("abc", ','), Equals(std::vector{"abc"}) for: { abc } Equals: { abc } # splitString ok {test-number} - splitStringRef("abc,def", ','), Equals(std::vector{"abc", "def"}) for: { abc, def } Equals: { abc, def } +# stacks unscoped capture for vector +not ok {test-number} - false with 1 message: '{ 7, 8, 9 }' +# stacks unscoped capture in loops +not ok {test-number} - false with 4 messages: '"Count 1 to 3..."' and '1' and '2' and '3' +# stacks unscoped capture in loops +not ok {test-number} - false with 4 messages: '"Count 4 to 6..."' and '4' and '5' and '6' # stacks unscoped info in loops not ok {test-number} - false with 4 messages: 'Count 1 to 3...' and '1' and '2' and '3' # stacks unscoped info in loops @@ -4619,5 +4629,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2311 +1..2316 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 6b18914c11..7231067303 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -3388,6 +3388,10 @@ ok {test-number} - a, UnorderedRangeEquals( b ) for: { 1, 2, 3 } unordered eleme ok {test-number} - vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } elements are { 2, 3, 4 } # Type conversions of RangeEquals and similar ok {test-number} - vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 } +# UNSCOPED CAPTURE can deal with complex expressions +ok {test-number} - with 7 messages: '1' and '2' and '3' and '3' and '3' and 'true' and 'true' +# UNSCOPED_CAPTURE parses string and character constants +ok {test-number} - with 11 messages: '"escaped, ", "' and '"single quote in string,',"' and '"some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<"' and ''"'' and ''''' and '','' and ''}'' and '')'' and ''('' and ''{'' # Unexpected exceptions can be translated not ok {test-number} - unexpected exception with message: '3.14000000000000012' # Upcasting special member functions @@ -4352,6 +4356,12 @@ ok {test-number} - splitStringRef("", ','), Equals(std::vector()) for ok {test-number} - splitStringRef("abc", ','), Equals(std::vector{"abc"}) for: { abc } Equals: { abc } # splitString ok {test-number} - splitStringRef("abc,def", ','), Equals(std::vector{"abc", "def"}) for: { abc, def } Equals: { abc, def } +# stacks unscoped capture for vector +not ok {test-number} - false with 1 message: '{ 7, 8, 9 }' +# stacks unscoped capture in loops +not ok {test-number} - false with 4 messages: '"Count 1 to 3..."' and '1' and '2' and '3' +# stacks unscoped capture in loops +not ok {test-number} - false with 4 messages: '"Count 4 to 6..."' and '4' and '5' and '6' # stacks unscoped info in loops not ok {test-number} - false with 4 messages: 'Count 1 to 3...' and '1' and '2' and '3' # stacks unscoped info in loops @@ -4608,5 +4618,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2311 +1..2316 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index 853f3d8048..eea630607e 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -721,6 +721,10 @@ ##teamcity[testFinished name='Trim strings' duration="{duration}"] ##teamcity[testStarted name='Type conversions of RangeEquals and similar'] ##teamcity[testFinished name='Type conversions of RangeEquals and similar' duration="{duration}"] +##teamcity[testStarted name='UNSCOPED CAPTURE can deal with complex expressions'] +##teamcity[testFinished name='UNSCOPED CAPTURE can deal with complex expressions' duration="{duration}"] +##teamcity[testStarted name='UNSCOPED_CAPTURE parses string and character constants'] +##teamcity[testFinished name='UNSCOPED_CAPTURE parses string and character constants' duration="{duration}"] ##teamcity[testStarted name='Unexpected exceptions can be translated'] ##teamcity[testFailed name='Unexpected exceptions can be translated' message='Exception.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with message:|n "3.14000000000000012"'] ##teamcity[testFinished name='Unexpected exceptions can be translated' duration="{duration}"] @@ -965,6 +969,13 @@ loose text artifact ##teamcity[testFinished name='skipped tests can optionally provide a reason' duration="{duration}"] ##teamcity[testStarted name='splitString'] ##teamcity[testFinished name='splitString' duration="{duration}"] +##teamcity[testStarted name='stacks unscoped capture for vector'] +##teamcity[testFailed name='stacks unscoped capture for vector' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "{ 7, 8, 9 }"|n CHECK( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='stacks unscoped capture for vector' duration="{duration}"] +##teamcity[testStarted name='stacks unscoped capture in loops'] +##teamcity[testFailed name='stacks unscoped capture in loops' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with messages:|n ""Count 1 to 3...""|n "1"|n "2"|n "3"|n CHECK( false )|nwith expansion:|n false|n'] +##teamcity[testFailed name='stacks unscoped capture in loops' message='Message.tests.cpp:|nexpression failed with messages:|n ""Count 4 to 6...""|n "4"|n "5"|n "6"|n CHECK( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='stacks unscoped capture in loops' duration="{duration}"] ##teamcity[testStarted name='stacks unscoped info in loops'] ##teamcity[testFailed name='stacks unscoped info in loops' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with messages:|n "Count 1 to 3..."|n "1"|n "2"|n "3"|n CHECK( false )|nwith expansion:|n false|n'] ##teamcity[testFailed name='stacks unscoped info in loops' message='Message.tests.cpp:|nexpression failed with messages:|n "Count 4 to 6..."|n "4"|n "5"|n "6"|n CHECK( false )|nwith expansion:|n false|n'] diff --git a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt index 10e318de5c..690833f732 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt @@ -721,6 +721,10 @@ ##teamcity[testFinished name='Trim strings' duration="{duration}"] ##teamcity[testStarted name='Type conversions of RangeEquals and similar'] ##teamcity[testFinished name='Type conversions of RangeEquals and similar' duration="{duration}"] +##teamcity[testStarted name='UNSCOPED CAPTURE can deal with complex expressions'] +##teamcity[testFinished name='UNSCOPED CAPTURE can deal with complex expressions' duration="{duration}"] +##teamcity[testStarted name='UNSCOPED_CAPTURE parses string and character constants'] +##teamcity[testFinished name='UNSCOPED_CAPTURE parses string and character constants' duration="{duration}"] ##teamcity[testStarted name='Unexpected exceptions can be translated'] ##teamcity[testFailed name='Unexpected exceptions can be translated' message='Exception.tests.cpp:|n...............................................................................|n|nException.tests.cpp:|nunexpected exception with message:|n "3.14000000000000012"'] ##teamcity[testFinished name='Unexpected exceptions can be translated' duration="{duration}"] @@ -964,6 +968,13 @@ ##teamcity[testFinished name='skipped tests can optionally provide a reason' duration="{duration}"] ##teamcity[testStarted name='splitString'] ##teamcity[testFinished name='splitString' duration="{duration}"] +##teamcity[testStarted name='stacks unscoped capture for vector'] +##teamcity[testFailed name='stacks unscoped capture for vector' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with message:|n "{ 7, 8, 9 }"|n CHECK( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='stacks unscoped capture for vector' duration="{duration}"] +##teamcity[testStarted name='stacks unscoped capture in loops'] +##teamcity[testFailed name='stacks unscoped capture in loops' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with messages:|n ""Count 1 to 3...""|n "1"|n "2"|n "3"|n CHECK( false )|nwith expansion:|n false|n'] +##teamcity[testFailed name='stacks unscoped capture in loops' message='Message.tests.cpp:|nexpression failed with messages:|n ""Count 4 to 6...""|n "4"|n "5"|n "6"|n CHECK( false )|nwith expansion:|n false|n'] +##teamcity[testFinished name='stacks unscoped capture in loops' duration="{duration}"] ##teamcity[testStarted name='stacks unscoped info in loops'] ##teamcity[testFailed name='stacks unscoped info in loops' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with messages:|n "Count 1 to 3..."|n "1"|n "2"|n "3"|n CHECK( false )|nwith expansion:|n false|n'] ##teamcity[testFailed name='stacks unscoped info in loops' message='Message.tests.cpp:|nexpression failed with messages:|n "Count 4 to 6..."|n "4"|n "5"|n "6"|n CHECK( false )|nwith expansion:|n false|n'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index 48b0e26061..5a2892e565 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -16448,6 +16448,66 @@ There is no extra whitespace here + + + 1 + + + 2 + + + 3 + + + 3 + + + 3 + + + true + + + true + + + + + + "escaped, ", " + + + "single quote in string,'," + + + "some escapes, \,\\" + + + "some, ), unmatched, } prenheses {[<" + + + '"' + + + ''' + + + ',' + + + '}' + + + ')' + + + '(' + + + '{' + + + 3.14000000000000012 @@ -21020,6 +21080,63 @@ Approx( -1.95996398454005449 ) + + + { 7, 8, 9 } + + + + false + + + false + + + + + + + "Count 1 to 3..." + + + 1 + + + 2 + + + 3 + + + + false + + + false + + + + "Count 4 to 6..." + + + 4 + + + 5 + + + 6 + + + + false + + + false + + + + Count 1 to 3... @@ -22286,6 +22403,6 @@ Approx( -1.95996398454005449 ) - - + + diff --git a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt index f0498aff54..6d111b1d5f 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -16448,6 +16448,66 @@ There is no extra whitespace here + + + 1 + + + 2 + + + 3 + + + 3 + + + 3 + + + true + + + true + + + + + + "escaped, ", " + + + "single quote in string,'," + + + "some escapes, \,\\" + + + "some, ), unmatched, } prenheses {[<" + + + '"' + + + ''' + + + ',' + + + '}' + + + ')' + + + '(' + + + '{' + + + 3.14000000000000012 @@ -21019,6 +21079,63 @@ Approx( -1.95996398454005449 ) + + + { 7, 8, 9 } + + + + false + + + false + + + + + + + "Count 1 to 3..." + + + 1 + + + 2 + + + 3 + + + + false + + + false + + + + "Count 4 to 6..." + + + 4 + + + 5 + + + 6 + + + + false + + + false + + + + Count 1 to 3... @@ -22285,6 +22402,6 @@ Approx( -1.95996398454005449 ) - - + + diff --git a/tests/SelfTest/UsageTests/Message.tests.cpp b/tests/SelfTest/UsageTests/Message.tests.cpp index 07d3ee7b13..a552a6727d 100644 --- a/tests/SelfTest/UsageTests/Message.tests.cpp +++ b/tests/SelfTest/UsageTests/Message.tests.cpp @@ -212,6 +212,38 @@ TEST_CASE( "CAPTURE can deal with complex expressions", "[messages][capture]" ) SUCCEED(); } +TEST_CASE( "UNSCOPED CAPTURE can deal with complex expressions", "[messages][unscoped][capture]" ) { + int a = 1; + int b = 2; + int c = 3; + UNSCOPED_CAPTURE( a, b, c, a + b, a+b, c > b, a == 1 ); + SUCCEED(); +} +template < typename T> +static void unscoped_capture( T input ) { UNSCOPED_CAPTURE(input) } + +TEST_CASE( "stacks unscoped capture in loops", "[failing][.][unscoped][capture]" ) { + UNSCOPED_CAPTURE( "Count 1 to 3..." ); + for ( int i = 1; i <= 3; i++ ) { + unscoped_capture( i ); + } + CHECK( false ); + UNSCOPED_CAPTURE( "Count 4 to 6..." ); + for ( int i = 4; i <= 6; i++ ) { + unscoped_capture( i ); + } + CHECK( false ); +} + +TEST_CASE( "stacks unscoped capture for vector", "[failing][.][unscoped][capture]" ) { + { + std::vector vec { 7, 8, 9 }; + unscoped_capture( vec ); + } + CHECK( false ); +} + + #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-value" // In (1, 2), the "1" is unused ... @@ -290,6 +322,13 @@ TEST_CASE("CAPTURE parses string and character constants", "[messages][capture]" SUCCEED(); } +TEST_CASE("UNSCOPED_CAPTURE parses string and character constants", "[messages][capture]") { + UNSCOPED_CAPTURE(("comma, in string", "escaped, \", "), "single quote in string,',", "some escapes, \\,\\\\"); + UNSCOPED_CAPTURE( "some, ), unmatched, } prenheses {[<" ); + UNSCOPED_CAPTURE( '"', '\'', ',', '}', ')', '(', '{' ); + SUCCEED(); +} + #ifdef __clang__ #pragma clang diagnostic pop #endif