Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/catch2/catch_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char>(names[start]))) {
++start;
Expand Down Expand Up @@ -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
37 changes: 26 additions & 11 deletions src/catch2/catch_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ namespace Catch {
std::vector<MessageInfo> 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;
Expand Down Expand Up @@ -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 )
Expand All @@ -120,28 +131,32 @@ 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)

#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 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


Expand Down
4 changes: 4 additions & 0 deletions tests/SelfTest/Baselines/automake.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/SelfTest/Baselines/automake.sw.multi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions tests/SelfTest/Baselines/compact.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,8 @@ MatchersRanges.tests.cpp:<line number>: passed: a, !RangeEquals( b ) for: { 1, 2
MatchersRanges.tests.cpp:<line number>: passed: a, UnorderedRangeEquals( b ) for: { 1, 2, 3 } unordered elements are { 3, 2, 1 }
MatchersRanges.tests.cpp:<line number>: passed: vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } elements are { 2, 3, 4 }
MatchersRanges.tests.cpp:<line number>: passed: vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 }
Message.tests.cpp:<line number>: passed: with 7 messages: '1' and '2' and '3' and '3' and '3' and 'true' and 'true'
Message.tests.cpp:<line number>: 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:<line number>: failed: unexpected exception with message: '3.14000000000000012'
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
Expand Down Expand Up @@ -2720,6 +2722,9 @@ Skip.tests.cpp:<line number>: skipped: 'skipping because answer = 43'
StringManip.tests.cpp:<line number>: passed: splitStringRef("", ','), Equals(std::vector<StringRef>()) for: { } Equals: { }
StringManip.tests.cpp:<line number>: passed: splitStringRef("abc", ','), Equals(std::vector<StringRef>{"abc"}) for: { abc } Equals: { abc }
StringManip.tests.cpp:<line number>: passed: splitStringRef("abc,def", ','), Equals(std::vector<StringRef>{"abc", "def"}) for: { abc, def } Equals: { abc, def }
Message.tests.cpp:<line number>: failed: false with 1 message: '{ 7, 8, 9 }'
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 1 to 3..."' and '1' and '2' and '3'
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 4 to 6..."' and '4' and '5' and '6'
Message.tests.cpp:<line number>: failed: false with 4 messages: 'Count 1 to 3...' and '1' and '2' and '3'
Message.tests.cpp:<line number>: failed: false with 4 messages: 'Count 4 to 6...' and '4' and '5' and '6'
StringManip.tests.cpp:<line number>: passed: !(startsWith("", 'c')) for: !false
Expand Down Expand Up @@ -2884,7 +2889,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
Misc.tests.cpp:<line number>: passed:
Misc.tests.cpp:<line number>: passed:
test cases: 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


9 changes: 7 additions & 2 deletions tests/SelfTest/Baselines/compact.sw.multi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,8 @@ MatchersRanges.tests.cpp:<line number>: passed: a, !RangeEquals( b ) for: { 1, 2
MatchersRanges.tests.cpp:<line number>: passed: a, UnorderedRangeEquals( b ) for: { 1, 2, 3 } unordered elements are { 3, 2, 1 }
MatchersRanges.tests.cpp:<line number>: passed: vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } elements are { 2, 3, 4 }
MatchersRanges.tests.cpp:<line number>: passed: vector_a, UnorderedRangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } unordered elements are { 2, 3, 4 }
Message.tests.cpp:<line number>: passed: with 7 messages: '1' and '2' and '3' and '3' and '3' and 'true' and 'true'
Message.tests.cpp:<line number>: 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:<line number>: failed: unexpected exception with message: '3.14000000000000012'
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
Expand Down Expand Up @@ -2709,6 +2711,9 @@ Skip.tests.cpp:<line number>: skipped: 'skipping because answer = 43'
StringManip.tests.cpp:<line number>: passed: splitStringRef("", ','), Equals(std::vector<StringRef>()) for: { } Equals: { }
StringManip.tests.cpp:<line number>: passed: splitStringRef("abc", ','), Equals(std::vector<StringRef>{"abc"}) for: { abc } Equals: { abc }
StringManip.tests.cpp:<line number>: passed: splitStringRef("abc,def", ','), Equals(std::vector<StringRef>{"abc", "def"}) for: { abc, def } Equals: { abc, def }
Message.tests.cpp:<line number>: failed: false with 1 message: '{ 7, 8, 9 }'
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 1 to 3..."' and '1' and '2' and '3'
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 4 to 6..."' and '4' and '5' and '6'
Message.tests.cpp:<line number>: failed: false with 4 messages: 'Count 1 to 3...' and '1' and '2' and '3'
Message.tests.cpp:<line number>: failed: false with 4 messages: 'Count 4 to 6...' and '4' and '5' and '6'
StringManip.tests.cpp:<line number>: passed: !(startsWith("", 'c')) for: !false
Expand Down Expand Up @@ -2873,7 +2878,7 @@ InternalBenchmark.tests.cpp:<line number>: passed: med == 18. for: 18.0 == 18.0
InternalBenchmark.tests.cpp:<line number>: passed: q3 == 23. for: 23.0 == 23.0
Misc.tests.cpp:<line number>: passed:
Misc.tests.cpp:<line number>: passed:
test cases: 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


37 changes: 35 additions & 2 deletions tests/SelfTest/Baselines/console.std.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,39 @@ Skip.tests.cpp:<line number>: SKIPPED:
explicitly with message:
skipping because answer = 43

-------------------------------------------------------------------------------
stacks unscoped capture for vector
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
...............................................................................

Message.tests.cpp:<line number>: FAILED:
CHECK( false )
with message:
{ 7, 8, 9 }

-------------------------------------------------------------------------------
stacks unscoped capture in loops
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
...............................................................................

Message.tests.cpp:<line number>: FAILED:
CHECK( false )
with messages:
"Count 1 to 3..."
1
2
3

Message.tests.cpp:<line number>: FAILED:
CHECK( false )
with messages:
"Count 4 to 6..."
4
5
6

-------------------------------------------------------------------------------
stacks unscoped info in loops
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -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

73 changes: 71 additions & 2 deletions tests/SelfTest/Baselines/console.sw.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14232,6 +14232,42 @@ MatchersRanges.tests.cpp:<line number>: PASSED:
with expansion:
{ 1, 2, 3 } unordered elements are { 2, 3, 4 }

-------------------------------------------------------------------------------
UNSCOPED CAPTURE can deal with complex expressions
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
...............................................................................

Message.tests.cpp:<line number>: PASSED:
with messages:
1
2
3
3
3
true
true

-------------------------------------------------------------------------------
UNSCOPED_CAPTURE parses string and character constants
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
...............................................................................

Message.tests.cpp:<line number>: PASSED:
with messages:
"escaped, ", "
"single quote in string,',"
"some escapes, \,\\"
"some, ), unmatched, } prenheses {[<"
'"'
'''
','
'}'
')'
'('
'{'

-------------------------------------------------------------------------------
Unexpected exceptions can be translated
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -18117,6 +18153,39 @@ StringManip.tests.cpp:<line number>: PASSED:
with expansion:
{ abc, def } Equals: { abc, def }

-------------------------------------------------------------------------------
stacks unscoped capture for vector
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
...............................................................................

Message.tests.cpp:<line number>: FAILED:
CHECK( false )
with message:
{ 7, 8, 9 }

-------------------------------------------------------------------------------
stacks unscoped capture in loops
-------------------------------------------------------------------------------
Message.tests.cpp:<line number>
...............................................................................

Message.tests.cpp:<line number>: FAILED:
CHECK( false )
with messages:
"Count 1 to 3..."
1
2
3

Message.tests.cpp:<line number>: FAILED:
CHECK( false )
with messages:
"Count 4 to 6..."
4
5
6

-------------------------------------------------------------------------------
stacks unscoped info in loops
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -19267,6 +19336,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: 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

Loading