Skip to content

Commit d1ede1a

Browse files
committed
Refactoring Code to Adjust Scoped Logic into the common constructor for Capturer
1 parent abfdfcf commit d1ede1a

18 files changed

+212
-230
lines changed

src/catch2/catch_message.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ namespace Catch {
3939
Capturer::Capturer( StringRef macroName,
4040
SourceLineInfo const& lineInfo,
4141
ResultWas::OfType resultType,
42-
StringRef names ):
42+
StringRef names, bool scoped):
4343
m_resultCapture( getResultCapture() ) {
44+
isScoped = scoped;
4445
auto trimmed = [&] (size_t start, size_t end) {
4546
while (names[start] == ',' || isspace(static_cast<unsigned char>(names[start]))) {
4647
++start;
@@ -106,20 +107,19 @@ namespace Catch {
106107
}
107108

108109
void Capturer::captureValue( size_t index, std::string const& value ) {
109-
assert( index < m_messages.size() );
110-
m_messages[index].message += value;
111-
m_resultCapture.pushScopedMessage( m_messages[index] );
112-
m_captured++;
113-
}
114-
115-
void Capturer::captureUnscopedValue( size_t index, std::string const& value ) {
116-
m_messages[index].message += value;
117-
getResultCapture().emplaceUnscopedMessage(Catch::MessageBuilder(
118-
m_messages[index].macroName,
119-
m_messages[index].lineInfo,
120-
m_messages[index].type) << m_messages[index].message);
121-
if(index == m_messages.size() - 1){
122-
m_messages.clear();
110+
if(isScoped){
111+
assert( index < m_messages.size() );
112+
m_messages[index].message += value;
113+
m_resultCapture.pushScopedMessage( m_messages[index] );
114+
m_captured++;
115+
} else {
116+
getResultCapture().emplaceUnscopedMessage(Catch::MessageBuilder(
117+
m_messages[index].macroName,
118+
m_messages[index].lineInfo,
119+
m_messages[index].type) << value);
120+
if(index == m_messages.size() - 1){
121+
m_messages.clear();
122+
}
123123
}
124124
}
125125

src/catch2/catch_message.hpp

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,27 +65,15 @@ namespace Catch {
6565
std::vector<MessageInfo> m_messages;
6666
IResultCapture& m_resultCapture;
6767
size_t m_captured = 0;
68+
bool isScoped;
6869
public:
69-
Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names );
70+
Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names, bool scoped );
7071

7172
Capturer(Capturer const&) = delete;
7273
Capturer& operator=(Capturer const&) = delete;
7374

7475
~Capturer();
7576

76-
void captureUnscopedValue( size_t index, std::string const& value );
77-
78-
template<typename T>
79-
void captureUnscopedValues( size_t index, T const& value ) {
80-
captureUnscopedValue( index, Catch::Detail::stringify( value ) );
81-
}
82-
83-
template<typename T, typename... Ts>
84-
void captureUnscopedValues( size_t index, T const& value, Ts const&... values ) {
85-
captureUnscopedValue( index, Catch::Detail::stringify(value) );
86-
captureUnscopedValues( index+1, values... );
87-
}
88-
8977
void captureValue( size_t index, std::string const& value );
9078

9179
template<typename T>
@@ -98,10 +86,6 @@ namespace Catch {
9886
captureValue( index, Catch::Detail::stringify(value) );
9987
captureValues( index+1, values... );
10088
}
101-
102-
std::vector<MessageInfo> getMessageDetails() const {
103-
return m_messages;
104-
}
10589
};
10690

10791
} // end namespace Catch
@@ -119,16 +103,18 @@ namespace Catch {
119103
Catch::Capturer varName( macroName##_catch_sr, \
120104
CATCH_INTERNAL_LINEINFO, \
121105
Catch::ResultWas::Info, \
122-
#__VA_ARGS__##_catch_sr ); \
106+
#__VA_ARGS__##_catch_sr, \
107+
true ); \
123108
varName.captureValues( 0, __VA_ARGS__ )
124109

125110
///////////////////////////////////////////////////////////////////////////////
126111
#define INTERNAL_CATCH_UNSCOPED_CAPTURE( varName, macroName, ... ) \
127112
Catch::Capturer varName( macroName##_catch_sr, \
128113
CATCH_INTERNAL_LINEINFO, \
129114
Catch::ResultWas::Info, \
130-
#__VA_ARGS__##_catch_sr ); \
131-
varName.captureUnscopedValues( 0, __VA_ARGS__ );
115+
#__VA_ARGS__##_catch_sr, \
116+
false ); \
117+
varName.captureValues( 0, __VA_ARGS__ );
132118

133119
///////////////////////////////////////////////////////////////////////////////
134120
#define INTERNAL_CATCH_INFO( macroName, log ) \
@@ -149,12 +135,11 @@ namespace Catch {
149135

150136
#elif defined(CATCH_CONFIG_PREFIX_MESSAGES) && defined(CATCH_CONFIG_DISABLE)
151137

152-
#define CATCH_INFO( msg ) (void)(0)
153-
#define CATCH_UNSCOPED_INFO( msg ) (void)(0)
154-
#define CATCH_WARN( msg ) (void)(0)
155-
#define CATCH_CAPTURE( ... ) (void)(0)
156-
#define CATCH_UNSCOPED_CAPTURE( ... ) (void)(0)
157-
138+
#define CATCH_INFO( msg ) (void)(0)
139+
#define CATCH_UNSCOPED_INFO( msg ) (void)(0)
140+
#define CATCH_WARN( msg ) (void)(0)
141+
#define CATCH_CAPTURE( ... ) (void)(0)
142+
#define CATCH_UNSCOPED_CAPTURE( ... ) (void)(0)
158143

159144
#elif !defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE)
160145

@@ -167,12 +152,11 @@ namespace Catch {
167152

168153
#elif !defined(CATCH_CONFIG_PREFIX_MESSAGES) && defined(CATCH_CONFIG_DISABLE)
169154

170-
#define INFO( msg ) (void)(0)
171-
#define UNSCOPED_INFO( msg ) (void)(0)
172-
#define WARN( msg ) (void)(0)
173-
#define CAPTURE( ... ) (void)(0)
174-
#define UNSCOPED_CAPTURE( ... ) (void)(0)
175-
155+
#define INFO(msg) (void)(0)
156+
#define UNSCOPED_INFO(msg) (void)(0)
157+
#define WARN(msg) (void)(0)
158+
#define CAPTURE(...) (void)(0)
159+
#define UNSCOPED_CAPTURE(...) (void)(0)
176160
#endif // end of user facing macro declarations
177161

178162

tests/SelfTest/Baselines/compact.sw.approved.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,8 +2187,8 @@ MatchersRanges.tests.cpp:<line number>: passed: a, !RangeEquals( b ) for: { 1, 2
21872187
MatchersRanges.tests.cpp:<line number>: passed: a, UnorderedRangeEquals( b ) for: { 1, 2, 3 } unordered elements are { 3, 2, 1 }
21882188
MatchersRanges.tests.cpp:<line number>: passed: vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } elements are { 2, 3, 4 }
21892189
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 }
2190-
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'
2191-
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 ''{' := '{''
2190+
Message.tests.cpp:<line number>: passed: with 7 messages: '1' and '2' and '3' and '3' and '3' and 'true' and 'true'
2191+
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 ''{''
21922192
Exception.tests.cpp:<line number>: failed: unexpected exception with message: '3.14000000000000012'
21932193
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
21942194
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
@@ -2715,9 +2715,9 @@ Skip.tests.cpp:<line number>: skipped: 'skipping because answer = 43'
27152715
StringManip.tests.cpp:<line number>: passed: splitStringRef("", ','), Equals(std::vector<StringRef>()) for: { } Equals: { }
27162716
StringManip.tests.cpp:<line number>: passed: splitStringRef("abc", ','), Equals(std::vector<StringRef>{"abc"}) for: { abc } Equals: { abc }
27172717
StringManip.tests.cpp:<line number>: passed: splitStringRef("abc,def", ','), Equals(std::vector<StringRef>{"abc", "def"}) for: { abc, def } Equals: { abc, def }
2718-
Message.tests.cpp:<line number>: failed: false with 1 message: 'input := { 7, 8, 9 }'
2719-
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 1 to 3..." := "Count 1 to 3..."' and 'input := 1' and 'input := 2' and 'input := 3'
2720-
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 4 to 6..." := "Count 4 to 6..."' and 'input := 4' and 'input := 5' and 'input := 6'
2718+
Message.tests.cpp:<line number>: failed: false with 1 message: '{ 7, 8, 9 }'
2719+
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 1 to 3..."' and '1' and '2' and '3'
2720+
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 4 to 6..."' and '4' and '5' and '6'
27212721
Message.tests.cpp:<line number>: failed: false with 4 messages: 'Count 1 to 3...' and '1' and '2' and '3'
27222722
Message.tests.cpp:<line number>: failed: false with 4 messages: 'Count 4 to 6...' and '4' and '5' and '6'
27232723
StringManip.tests.cpp:<line number>: passed: !(startsWith("", 'c')) for: !false

tests/SelfTest/Baselines/compact.sw.multi.approved.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,8 +2180,8 @@ MatchersRanges.tests.cpp:<line number>: passed: a, !RangeEquals( b ) for: { 1, 2
21802180
MatchersRanges.tests.cpp:<line number>: passed: a, UnorderedRangeEquals( b ) for: { 1, 2, 3 } unordered elements are { 3, 2, 1 }
21812181
MatchersRanges.tests.cpp:<line number>: passed: vector_a, RangeEquals( array_a_plus_1, close_enough ) for: { 1, 2, 3 } elements are { 2, 3, 4 }
21822182
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 }
2183-
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'
2184-
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 ''{' := '{''
2183+
Message.tests.cpp:<line number>: passed: with 7 messages: '1' and '2' and '3' and '3' and '3' and 'true' and 'true'
2184+
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 ''{''
21852185
Exception.tests.cpp:<line number>: failed: unexpected exception with message: '3.14000000000000012'
21862186
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
21872187
UniquePtr.tests.cpp:<line number>: passed: bptr->i == 3 for: 3 == 3
@@ -2704,9 +2704,9 @@ Skip.tests.cpp:<line number>: skipped: 'skipping because answer = 43'
27042704
StringManip.tests.cpp:<line number>: passed: splitStringRef("", ','), Equals(std::vector<StringRef>()) for: { } Equals: { }
27052705
StringManip.tests.cpp:<line number>: passed: splitStringRef("abc", ','), Equals(std::vector<StringRef>{"abc"}) for: { abc } Equals: { abc }
27062706
StringManip.tests.cpp:<line number>: passed: splitStringRef("abc,def", ','), Equals(std::vector<StringRef>{"abc", "def"}) for: { abc, def } Equals: { abc, def }
2707-
Message.tests.cpp:<line number>: failed: false with 1 message: 'input := { 7, 8, 9 }'
2708-
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 1 to 3..." := "Count 1 to 3..."' and 'input := 1' and 'input := 2' and 'input := 3'
2709-
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 4 to 6..." := "Count 4 to 6..."' and 'input := 4' and 'input := 5' and 'input := 6'
2707+
Message.tests.cpp:<line number>: failed: false with 1 message: '{ 7, 8, 9 }'
2708+
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 1 to 3..."' and '1' and '2' and '3'
2709+
Message.tests.cpp:<line number>: failed: false with 4 messages: '"Count 4 to 6..."' and '4' and '5' and '6'
27102710
Message.tests.cpp:<line number>: failed: false with 4 messages: 'Count 1 to 3...' and '1' and '2' and '3'
27112711
Message.tests.cpp:<line number>: failed: false with 4 messages: 'Count 4 to 6...' and '4' and '5' and '6'
27122712
StringManip.tests.cpp:<line number>: passed: !(startsWith("", 'c')) for: !false

tests/SelfTest/Baselines/console.std.approved.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ Message.tests.cpp:<line number>
16871687
Message.tests.cpp:<line number>: FAILED:
16881688
CHECK( false )
16891689
with message:
1690-
input := { 7, 8, 9 }
1690+
{ 7, 8, 9 }
16911691

16921692
-------------------------------------------------------------------------------
16931693
stacks unscoped capture in loops
@@ -1698,18 +1698,18 @@ Message.tests.cpp:<line number>
16981698
Message.tests.cpp:<line number>: FAILED:
16991699
CHECK( false )
17001700
with messages:
1701-
"Count 1 to 3..." := "Count 1 to 3..."
1702-
input := 1
1703-
input := 2
1704-
input := 3
1701+
"Count 1 to 3..."
1702+
1
1703+
2
1704+
3
17051705

17061706
Message.tests.cpp:<line number>: FAILED:
17071707
CHECK( false )
17081708
with messages:
1709-
"Count 4 to 6..." := "Count 4 to 6..."
1710-
input := 4
1711-
input := 5
1712-
input := 6
1709+
"Count 4 to 6..."
1710+
4
1711+
5
1712+
6
17131713

17141714
-------------------------------------------------------------------------------
17151715
stacks unscoped info in loops

tests/SelfTest/Baselines/console.sw.approved.txt

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14199,13 +14199,13 @@ Message.tests.cpp:<line number>
1419914199

1420014200
Message.tests.cpp:<line number>: PASSED:
1420114201
with messages:
14202-
a := 1
14203-
b := 2
14204-
c := 3
14205-
a + b := 3
14206-
a+b := 3
14207-
c > b := true
14208-
a == 1 := true
14202+
1
14203+
2
14204+
3
14205+
3
14206+
3
14207+
true
14208+
true
1420914209

1421014210
-------------------------------------------------------------------------------
1421114211
UNSCOPED_CAPTURE parses string and character constants
@@ -14215,18 +14215,17 @@ Message.tests.cpp:<line number>
1421514215

1421614216
Message.tests.cpp:<line number>: PASSED:
1421714217
with messages:
14218-
("comma, in string", "escaped, \", ") := "escaped, ", "
14219-
"single quote in string,'," := "single quote in string,',"
14220-
"some escapes, \\,\\\\" := "some escapes, \,\\"
14221-
"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[
14222-
<"
14223-
'"' := '"'
14224-
'\'' := '''
14225-
',' := ','
14226-
'}' := '}'
14227-
')' := ')'
14228-
'(' := '('
14229-
'{' := '{'
14218+
"escaped, ", "
14219+
"single quote in string,',"
14220+
"some escapes, \,\\"
14221+
"some, ), unmatched, } prenheses {[<"
14222+
'"'
14223+
'''
14224+
','
14225+
'}'
14226+
')'
14227+
'('
14228+
'{'
1423014229

1423114230
-------------------------------------------------------------------------------
1423214231
Unexpected exceptions can be translated
@@ -18122,7 +18121,7 @@ Message.tests.cpp:<line number>
1812218121
Message.tests.cpp:<line number>: FAILED:
1812318122
CHECK( false )
1812418123
with message:
18125-
input := { 7, 8, 9 }
18124+
{ 7, 8, 9 }
1812618125

1812718126
-------------------------------------------------------------------------------
1812818127
stacks unscoped capture in loops
@@ -18133,18 +18132,18 @@ Message.tests.cpp:<line number>
1813318132
Message.tests.cpp:<line number>: FAILED:
1813418133
CHECK( false )
1813518134
with messages:
18136-
"Count 1 to 3..." := "Count 1 to 3..."
18137-
input := 1
18138-
input := 2
18139-
input := 3
18135+
"Count 1 to 3..."
18136+
1
18137+
2
18138+
3
1814018139

1814118140
Message.tests.cpp:<line number>: FAILED:
1814218141
CHECK( false )
1814318142
with messages:
18144-
"Count 4 to 6..." := "Count 4 to 6..."
18145-
input := 4
18146-
input := 5
18147-
input := 6
18143+
"Count 4 to 6..."
18144+
4
18145+
5
18146+
6
1814818147

1814918148
-------------------------------------------------------------------------------
1815018149
stacks unscoped info in loops

0 commit comments

Comments
 (0)