diff --git a/docs/configuration.md b/docs/configuration.md index 527a3f82..35867104 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -29,7 +29,7 @@ with the same name. ## Prefixing Catch macros CATCH_CONFIG_PREFIX_ALL // Prefix all macros with CATCH_ - CATCH_CONFIG_PREFIX_MESSAGES // Prefix only INFO, UNSCOPED_INFO, WARN and CAPTURE + CATCH_CONFIG_PREFIX_MESSAGES // Prefix only message macros ((UNSCOPED_)INFO, WARN, (UNSCOPED_)CAPTURE) To keep test code clean and uncluttered Catch uses short macro names (e.g. ```TEST_CASE``` and ```REQUIRE```). Occasionally these may conflict with identifiers from platform headers or the system under test. In this case the above identifier can be defined. This will cause all the Catch user macros to be prefixed with ```CATCH_``` (e.g. ```CATCH_TEST_CASE``` and ```CATCH_REQUIRE```). diff --git a/docs/logging.md b/docs/logging.md index 1da97749..371c80ad 100644 --- a/docs/logging.md +++ b/docs/logging.md @@ -26,19 +26,22 @@ started" and "Section B", while the third one will only report "Test case started" as the extra info. -## Logging without local scope +## Logging outside of current scope -> [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 2.7.0. +> `UNSCOPED_INFO` was [introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 2.7.0. -`UNSCOPED_INFO` is similar to `INFO` with two key differences: +> `UNSCOPED_CAPTURE` was introduced in Catch2 X.Y.Z. -- Lifetime of an unscoped message is not tied to its own scope. +The `UNSCOPED_X` macros are similar to their plain `X` macro counterparts, +with two key differences: + +- The lifetime of an unscoped message is not tied to its own scope. - An unscoped message can be reported by the first following assertion only, regardless of the result of that assertion. -In other words, lifetime of `UNSCOPED_INFO` is limited by the following assertion (or by the end of test case/section, whichever comes first) whereas lifetime of `INFO` is limited by its own scope. - -These differences make this macro useful for reporting information from helper functions or inner scopes. An example: +In other words, the `UNSCOPED_X` macros are useful to add extra information +to the next assertion, e.g. from helper functions or inner scopes. +An example: ```cpp void print_some_info() { UNSCOPED_INFO("Info from helper"); @@ -83,9 +86,16 @@ Second info Second unscoped info ``` +Note that unscoped messages are not passed between test cases, even if +there were no assertions between them. + + ## Streaming macros -All these macros allow heterogeneous sequences of values to be streaming using the insertion operator (```<<```) in the same way that std::ostream, std::cout, etc support it. +Apart from `CAPTURE` (and its close sibling, `UNSCOPED_CAPTURE`), message +macros support gradual streaming of messages and values in the same way +that the standard streams do. + E.g.: ```c++ @@ -99,9 +109,6 @@ These macros come in three forms: The message is logged to a buffer, but only reported with next assertions that are logged. This allows you to log contextual information in case of failures which is not shown during a successful test run (for the console reporter, without -s). Messages are removed from the buffer at the end of their scope, so may be used, for example, in loops. -_Note that in Catch2 2.x.x `INFO` can be used without a trailing semicolon as there is a trailing semicolon inside macro. -This semicolon will be removed with next major version. It is highly advised to use a trailing semicolon after `INFO` macro._ - **UNSCOPED_INFO(** _message expression_ **)** > [Introduced](https://github.com/catchorg/Catch2/issues/1522) in Catch2 2.7.0. @@ -128,6 +135,10 @@ AS `FAIL`, but does not abort the test **CAPTURE(** _expression1_, _expression2_, ... **)** +**UNSCOPED_CAPTURE(** _expression1_, _expression2_, ... **)** + +> `UNSCOPED_CAPTURE` was introduced in Catch2 X.Y.Z. + Sometimes you just want to log a value of variable, or expression. For convenience, we provide the `CAPTURE` macro, that can take a variable, or an expression, and prints out that variable/expression and its value diff --git a/src/catch2/catch_message.cpp b/src/catch2/catch_message.cpp index dc7d5678..870651e3 100644 --- a/src/catch2/catch_message.cpp +++ b/src/catch2/catch_message.cpp @@ -38,7 +38,9 @@ namespace Catch { Capturer::Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, - StringRef names ) { + StringRef names, + bool isScoped): + m_isScoped(isScoped) { auto trimmed = [&] (size_t start, size_t end) { while (names[start] == ',' || isspace(static_cast(names[start]))) { ++start; @@ -99,15 +101,21 @@ namespace Catch { } Capturer::~Capturer() { assert( m_captured == m_messages.size() ); - for (auto const& message : m_messages) { - IResultCapture::popScopedMessage( message.sequence ); + if ( m_isScoped ) { + for ( auto const& message : m_messages ) { + IResultCapture::popScopedMessage( message.sequence ); + } } } void Capturer::captureValue( size_t index, std::string const& value ) { assert( index < m_messages.size() ); m_messages[index].message += value; - IResultCapture::pushScopedMessage( CATCH_MOVE( m_messages[index] ) ); + if ( m_isScoped ) { + IResultCapture::pushScopedMessage( CATCH_MOVE( m_messages[index] ) ); + } else { + IResultCapture::addUnscopedMessage( CATCH_MOVE( m_messages[index] ) ); + } m_captured++; } diff --git a/src/catch2/catch_message.hpp b/src/catch2/catch_message.hpp index 44b07476..9e868516 100644 --- a/src/catch2/catch_message.hpp +++ b/src/catch2/catch_message.hpp @@ -64,8 +64,9 @@ namespace Catch { class Capturer { std::vector m_messages; size_t m_captured = 0; + bool m_isScoped = false; public: - Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names ); + Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names, bool isScoped ); Capturer(Capturer const&) = delete; Capturer& operator=(Capturer const&) = delete; @@ -97,11 +98,12 @@ namespace Catch { } while( false ) /////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \ - Catch::Capturer varName( macroName##_catch_sr, \ - CATCH_INTERNAL_LINEINFO, \ - Catch::ResultWas::Info, \ - #__VA_ARGS__##_catch_sr ); \ +#define INTERNAL_CATCH_CAPTURE( varName, macroName, scopedCapture, ... ) \ + Catch::Capturer varName( macroName##_catch_sr, \ + CATCH_INTERNAL_LINEINFO, \ + Catch::ResultWas::Info, \ + #__VA_ARGS__##_catch_sr, \ + scopedCapture ); \ varName.captureValues( 0, __VA_ARGS__ ) /////////////////////////////////////////////////////////////////////////////// @@ -118,28 +120,32 @@ namespace Catch { #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg ) #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_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE", true, __VA_ARGS__ ) + #define CATCH_UNSCOPED_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_UNSCOPED_CAPTURE", false, __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) #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg ) #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 CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE", true, __VA_ARGS__ ) + #define UNSCOPED_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "UNSCOPED_CAPTURE", false, __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) + #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/src/catch2/interfaces/catch_interfaces_capture.hpp b/src/catch2/interfaces/catch_interfaces_capture.hpp index 4e27a985..79062cad 100644 --- a/src/catch2/interfaces/catch_interfaces_capture.hpp +++ b/src/catch2/interfaces/catch_interfaces_capture.hpp @@ -65,6 +65,7 @@ namespace Catch { static void pushScopedMessage( MessageInfo&& message ); static void popScopedMessage( unsigned int messageId ); + static void addUnscopedMessage( MessageInfo&& message ); static void emplaceUnscopedMessage( MessageBuilder&& builder ); virtual void handleFatalErrorCondition( StringRef message ) = 0; diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index d63f19ac..5e5f95a4 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -211,15 +211,18 @@ namespace Catch { // we only keep around the raw msg ids. ~MessageHolder() = default; - - void addUnscopedMessage(MessageBuilder&& builder) { + void addUnscopedMessage( MessageInfo&& info ) { repairUnscopedMessageInvariant(); - MessageInfo info( CATCH_MOVE( builder.m_info ) ); - info.message = builder.m_stream.str(); unscoped_ids.push_back( info.sequence ); messages.push_back( CATCH_MOVE( info ) ); } + void addUnscopedMessage(MessageBuilder&& builder) { + MessageInfo info( CATCH_MOVE( builder.m_info ) ); + info.message = builder.m_stream.str(); + addUnscopedMessage( CATCH_MOVE( info ) ); + } + void addScopedMessage(MessageInfo&& info) { messages.push_back( CATCH_MOVE( info ) ); } @@ -894,6 +897,10 @@ namespace Catch { Detail::g_messageHolder().addUnscopedMessage( CATCH_MOVE( builder ) ); } + void IResultCapture::addUnscopedMessage( MessageInfo&& message ) { + Detail::g_messageHolder().addUnscopedMessage( CATCH_MOVE( message ) ); + } + void seedRng(IConfig const& config) { sharedRng().seed(config.rngSeed()); } diff --git a/tests/ExtraTests/X01-PrefixedMacros.cpp b/tests/ExtraTests/X01-PrefixedMacros.cpp index d1c246ec..d2d05528 100644 --- a/tests/ExtraTests/X01-PrefixedMacros.cpp +++ b/tests/ExtraTests/X01-PrefixedMacros.cpp @@ -67,6 +67,7 @@ CATCH_TEST_CASE("PrefixedMacros") { int i = 1; CATCH_CAPTURE( i ); CATCH_CAPTURE( i, i + 1 ); + CATCH_UNSCOPED_CAPTURE( i + 2, i + 3 ); CATCH_DYNAMIC_SECTION("Dynamic section: " << i) { CATCH_FAIL_CHECK( "failure" ); } diff --git a/tests/ExtraTests/X02-DisabledMacros.cpp b/tests/ExtraTests/X02-DisabledMacros.cpp index 231adfb0..0c051acc 100644 --- a/tests/ExtraTests/X02-DisabledMacros.cpp +++ b/tests/ExtraTests/X02-DisabledMacros.cpp @@ -48,6 +48,7 @@ TEST_CASE( "Disabled Macros" ) { CAPTURE( 1 ); CAPTURE( 1, "captured" ); + UNSCOPED_CAPTURE( 3 ); REQUIRE_THAT( 1, Catch::Matchers::Predicate( []( int ) { return false; } ) ); @@ -68,6 +69,7 @@ TEST_CASE_PERSISTENT_FIXTURE( DisabledFixture, "Disabled Persistent Fixture" ) { CAPTURE( 1 ); CAPTURE( 1, "captured" ); + UNSCOPED_CAPTURE( 3 ); REQUIRE_THAT( 1, Catch::Matchers::Predicate( []( int ) { return false; } ) ); diff --git a/tests/SelfTest/Baselines/automake.sw.approved.txt b/tests/SelfTest/Baselines/automake.sw.approved.txt index 6b0ac614..05c6384b 100644 --- a/tests/SelfTest/Baselines/automake.sw.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.approved.txt @@ -299,6 +299,7 @@ Message from section two :test-result: PASS Trim strings :test-result: PASS Type conversions of RangeEquals and similar :test-result: FAIL Unexpected exceptions can be translated +:test-result: FAIL Unscoped capture outlives scope :test-result: PASS Upcasting special member functions :test-result: PASS Usage of AllMatch range matcher :test-result: PASS Usage of AllTrue range matcher diff --git a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt index 54d1c58f..75c116d5 100644 --- a/tests/SelfTest/Baselines/automake.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/automake.sw.multi.approved.txt @@ -292,6 +292,7 @@ :test-result: PASS Trim strings :test-result: PASS Type conversions of RangeEquals and similar :test-result: FAIL Unexpected exceptions can be translated +:test-result: FAIL Unscoped capture outlives scope :test-result: PASS Upcasting special member functions :test-result: PASS Usage of AllMatch range matcher :test-result: PASS Usage of AllTrue range matcher diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index 29a1017c..ea8d519a 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -2205,6 +2205,7 @@ MatchersRanges.tests.cpp:: passed: a, UnorderedRangeEquals( b ) for 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 } Exception.tests.cpp:: failed: unexpected exception with message: '3.14000000000000012' +Message.tests.cpp:: failed: false with 3 messages: 'i := 1' and 'j := 2' and 'i + j := 3' UniquePtr.tests.cpp:: passed: bptr->i == 3 for: 3 == 3 UniquePtr.tests.cpp:: passed: bptr->i == 3 for: 3 == 3 MatchersRanges.tests.cpp:: passed: data, AllMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match has size == 5 @@ -2894,7 +2895,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: 436 | 317 passed | 95 failed | 6 skipped | 18 failed as expected -assertions: 2309 | 2110 passed | 157 failed | 42 failed as expected +test cases: 437 | 317 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2311 | 2110 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt index 5e9a32c7..dbfab609 100644 --- a/tests/SelfTest/Baselines/compact.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.multi.approved.txt @@ -2198,6 +2198,7 @@ MatchersRanges.tests.cpp:: passed: a, UnorderedRangeEquals( b ) for 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 } Exception.tests.cpp:: failed: unexpected exception with message: '3.14000000000000012' +Message.tests.cpp:: failed: false with 3 messages: 'i := 1' and 'j := 2' and 'i + j := 3' UniquePtr.tests.cpp:: passed: bptr->i == 3 for: 3 == 3 UniquePtr.tests.cpp:: passed: bptr->i == 3 for: 3 == 3 MatchersRanges.tests.cpp:: passed: data, AllMatch(SizeIs(5)) for: { { 0, 1, 2, 3, 5 }, { 4, -3, -2, 5, 0 }, { 0, 0, 0, 5, 0 }, { 0, -5, 0, 5, 0 }, { 1, 0, 0, -1, 5 } } all match has size == 5 @@ -2883,7 +2884,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: 436 | 317 passed | 95 failed | 6 skipped | 18 failed as expected -assertions: 2309 | 2110 passed | 157 failed | 42 failed as expected +test cases: 437 | 317 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2311 | 2110 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index 8c7f79da..7de7b1f9 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1203,6 +1203,19 @@ Exception.tests.cpp:: FAILED: due to unexpected exception with message: 3.14000000000000012 +------------------------------------------------------------------------------- +Unscoped capture outlives scope +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with messages: + i := 1 + j := 2 + i + j := 3 + ------------------------------------------------------------------------------- Vector Approx matcher -- failing Empty and non empty vectors are not approx equal @@ -1730,6 +1743,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 436 | 335 passed | 76 failed | 7 skipped | 18 failed as expected -assertions: 2288 | 2110 passed | 136 failed | 42 failed as expected +test cases: 437 | 335 passed | 76 failed | 7 skipped | 19 failed as expected +assertions: 2289 | 2110 passed | 136 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index d6e61ff6..ab18d08c 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -14324,6 +14324,29 @@ Exception.tests.cpp:: FAILED: due to unexpected exception with message: 3.14000000000000012 +------------------------------------------------------------------------------- +Unscoped capture outlives scope + A +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + + +No assertions in section 'A' + +------------------------------------------------------------------------------- +Unscoped capture outlives scope +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with messages: + i := 1 + j := 2 + i + j := 3 + ------------------------------------------------------------------------------- Upcasting special member functions Move constructor @@ -19349,6 +19372,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 436 | 317 passed | 95 failed | 6 skipped | 18 failed as expected -assertions: 2309 | 2110 passed | 157 failed | 42 failed as expected +test cases: 437 | 317 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2311 | 2110 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.multi.approved.txt b/tests/SelfTest/Baselines/console.sw.multi.approved.txt index 9bd865da..05d6eb6c 100644 --- a/tests/SelfTest/Baselines/console.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.multi.approved.txt @@ -14317,6 +14317,29 @@ Exception.tests.cpp:: FAILED: due to unexpected exception with message: 3.14000000000000012 +------------------------------------------------------------------------------- +Unscoped capture outlives scope + A +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + + +No assertions in section 'A' + +------------------------------------------------------------------------------- +Unscoped capture outlives scope +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: FAILED: + REQUIRE( false ) +with messages: + i := 1 + j := 2 + i + j := 3 + ------------------------------------------------------------------------------- Upcasting special member functions Move constructor @@ -19338,6 +19361,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 436 | 317 passed | 95 failed | 6 skipped | 18 failed as expected -assertions: 2309 | 2110 passed | 157 failed | 42 failed as expected +test cases: 437 | 317 passed | 96 failed | 6 skipped | 18 failed as expected +assertions: 2311 | 2110 passed | 158 failed | 43 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index 24d16a96..10523416 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -1694,6 +1694,18 @@ FAILED: at Exception.tests.cpp: + + + +FAILED: + REQUIRE( false ) +i := 1 +j := 2 +i + j := 3 +at Message.tests.cpp: + + + diff --git a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt index 21e6a885..2199b7f7 100644 --- a/tests/SelfTest/Baselines/junit.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/junit.sw.multi.approved.txt @@ -1,6 +1,6 @@ - + @@ -1693,6 +1693,18 @@ FAILED: at Exception.tests.cpp: + + + +FAILED: + REQUIRE( false ) +i := 1 +j := 2 +i + j := 3 +at Message.tests.cpp: + + + diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index 184bdf71..27dc2cdd 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -1833,6 +1833,17 @@ at Message.tests.cpp: + + +FAILED: + REQUIRE( false ) +i := 1 +j := 2 +i + j := 3 +at Message.tests.cpp: + + + FAILED: diff --git a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt index c7dc1ce0..93e3bcc8 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.multi.approved.txt @@ -1832,6 +1832,17 @@ at Message.tests.cpp: + + +FAILED: + REQUIRE( false ) +i := 1 +j := 2 +i + j := 3 +at Message.tests.cpp: + + + FAILED: diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index c9498ec5..0b5e1c91 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -3417,6 +3417,8 @@ ok {test-number} - vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { ok {test-number} - vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 } # Unexpected exceptions can be translated not ok {test-number} - unexpected exception with message: '3.14000000000000012' +# Unscoped capture outlives scope +not ok {test-number} - false with 3 messages: 'i := 1' and 'j := 2' and 'i + j := 3' # Upcasting special member functions ok {test-number} - bptr->i == 3 for: 3 == 3 # Upcasting special member functions @@ -4639,5 +4641,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2321 +1..2323 diff --git a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt index 4d86c1c1..de5c68fb 100644 --- a/tests/SelfTest/Baselines/tap.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.multi.approved.txt @@ -3410,6 +3410,8 @@ ok {test-number} - vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { ok {test-number} - vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 } # Unexpected exceptions can be translated not ok {test-number} - unexpected exception with message: '3.14000000000000012' +# Unscoped capture outlives scope +not ok {test-number} - false with 3 messages: 'i := 1' and 'j := 2' and 'i + j := 3' # Upcasting special member functions ok {test-number} - bptr->i == 3 for: 3 == 3 # Upcasting special member functions @@ -4628,5 +4630,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2321 +1..2323 diff --git a/tests/SelfTest/Baselines/teamcity.sw.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.approved.txt index e911941c..45e97905 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.approved.txt @@ -727,6 +727,9 @@ ##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}"] +##teamcity[testStarted name='Unscoped capture outlives scope'] +##teamcity[testIgnored name='Unscoped capture outlives scope' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with messages:|n "i := 1"|n "j := 2"|n "i + j := 3"|n REQUIRE( false )|nwith expansion:|n false|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testFinished name='Unscoped capture outlives scope' duration="{duration}"] ##teamcity[testStarted name='Upcasting special member functions'] ##teamcity[testFinished name='Upcasting special member functions' duration="{duration}"] ##teamcity[testStarted name='Usage of AllMatch range matcher'] diff --git a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt index 2c7f78e2..787bd222 100644 --- a/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/teamcity.sw.multi.approved.txt @@ -727,6 +727,9 @@ ##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}"] +##teamcity[testStarted name='Unscoped capture outlives scope'] +##teamcity[testIgnored name='Unscoped capture outlives scope' message='Message.tests.cpp:|n...............................................................................|n|nMessage.tests.cpp:|nexpression failed with messages:|n "i := 1"|n "j := 2"|n "i + j := 3"|n REQUIRE( false )|nwith expansion:|n false|n- failure ignore as test marked as |'ok to fail|'|n'] +##teamcity[testFinished name='Unscoped capture outlives scope' duration="{duration}"] ##teamcity[testStarted name='Upcasting special member functions'] ##teamcity[testFinished name='Upcasting special member functions' duration="{duration}"] ##teamcity[testStarted name='Usage of AllMatch range matcher'] diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index d2fea72f..95a7cb2f 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -16561,6 +16561,29 @@ There is no extra whitespace here + +
+ +
+ + i := 1 + + + j := 2 + + + i + j := 3 + + + + false + + + false + + + +
@@ -22393,6 +22416,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 43afc154..68ae54fe 100644 --- a/tests/SelfTest/Baselines/xml.sw.multi.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.multi.approved.txt @@ -16561,6 +16561,29 @@ There is no extra whitespace here
+ +
+ +
+ + i := 1 + + + j := 2 + + + i + j := 3 + + + + false + + + false + + + +
@@ -22392,6 +22415,6 @@ Approx( -1.95996398454005449 )
- - + + diff --git a/tests/SelfTest/UsageTests/Message.tests.cpp b/tests/SelfTest/UsageTests/Message.tests.cpp index 594e8892..9d2a2f5e 100644 --- a/tests/SelfTest/UsageTests/Message.tests.cpp +++ b/tests/SelfTest/UsageTests/Message.tests.cpp @@ -369,3 +369,13 @@ TEST_CASE( UNSCOPED_INFO( "b" ); REQUIRE( false ); } + +TEST_CASE( "Unscoped capture outlives scope", + "[messages][unscoped][capture][!shouldfail]" ) { + int i = 1; + SECTION( "A" ) { + int j = 2; + UNSCOPED_CAPTURE( i, j, i + j ); + } + REQUIRE( false ); +}