diff --git a/include/internal/catch_message.cpp b/include/internal/catch_message.cpp index fa7e8746..69e48211 100644 --- a/include/internal/catch_message.cpp +++ b/include/internal/catch_message.cpp @@ -9,6 +9,7 @@ #include "catch_message.h" #include "catch_interfaces_capture.h" #include "catch_uncaught_exceptions.h" +#include "catch_enforce.h" #include #include @@ -76,6 +77,15 @@ namespace Catch { } return names.substr(start, end - start + 1); }; + auto skipq = [&] (size_t start, char quote) { + for (auto i = start + 1; i < names.size() ; ++i) { + if (names[i] == quote) + return i; + if (names[i] == '\\') + ++i; + } + CATCH_INTERNAL_ERROR("CAPTURE parsing encountered unmatched parentheses"); + }; size_t start = 0; std::stack openings; @@ -96,6 +106,10 @@ namespace Catch { // case '>': openings.pop(); break; + case '"': + case '\'': + pos = skipq(pos, c); + break; case ',': if (start != pos && openings.size() == 0) { m_messages.emplace_back(macroName, lineInfo, resultType); diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 3755dd95..259954e4 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -230,6 +230,7 @@ Tricky.tests.cpp:: passed: y.v == 0 for: 0 == 0 Tricky.tests.cpp:: passed: 0 == y.v for: 0 == 0 Message.tests.cpp:: passed: with 7 messages: 'a := 1' and 'b := 2' and 'c := 3' and 'a + b := 3' and 'a+b := 3' and 'c > b := true' and 'a == 1 := true' Message.tests.cpp:: passed: with 7 messages: 'std::vector{1, 2, 3}[0, 1, 2] := 3' and 'std::vector{1, 2, 3}[(0, 1)] := 2' and 'std::vector{1, 2, 3}[0] := 1' and '(helper_1436{12, -12}) := { 12, -12 }' and '(helper_1436(-12, 12)) := { -12, 12 }' and '(1, 2) := 2' and '(2, 3) := 3' +Message.tests.cpp:: passed: with 11 messages: '("comma, in string", "escaped, \", ") := "escaped, ", "' and '"single quote in string,'," := "single quote in string,',"' and '"some escapes, \\,\\\\" := "some escapes, \,\\"' and '"some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<"' and ''"' := '"'' and ''\'' := '''' and '',' := ','' and ''}' := '}'' and '')' := ')'' and ''(' := '('' and ''{' := '{'' ToStringGeneral.tests.cpp:: passed: true with 1 message: 'i := 2' ToStringGeneral.tests.cpp:: passed: true with 1 message: '3' ToStringGeneral.tests.cpp:: passed: tab == '\t' for: '\t' == '\t' diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 8e86cb2e..0a4de923 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1299,6 +1299,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 265 | 198 passed | 63 failed | 4 failed as expected -assertions: 1448 | 1303 passed | 124 failed | 21 failed as expected +test cases: 266 | 199 passed | 63 failed | 4 failed as expected +assertions: 1449 | 1304 passed | 124 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index d5c143b2..2b998afc 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -1786,6 +1786,27 @@ with messages: (1, 2) := 2 (2, 3) := 3 +------------------------------------------------------------------------------- +CAPTURE parses string and character constants +------------------------------------------------------------------------------- +Message.tests.cpp: +............................................................................... + +Message.tests.cpp:: PASSED: +with messages: + ("comma, in string", "escaped, \", ") := "escaped, ", " + "single quote in string,'," := "single quote in string,'," + "some escapes, \\,\\\\" := "some escapes, \,\\" + "some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[ + <" + '"' := '"' + '\'' := ''' + ',' := ',' + '}' := '}' + ')' := ')' + '(' := '(' + '{' := '{' + ------------------------------------------------------------------------------- Capture and info messages Capture should stringify like assertions @@ -11368,6 +11389,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 265 | 182 passed | 79 failed | 4 failed as expected -assertions: 1465 | 1303 passed | 141 failed | 21 failed as expected +test cases: 266 | 183 passed | 79 failed | 4 failed as expected +assertions: 1466 | 1304 passed | 141 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 709171f2..7f4b43db 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -189,6 +189,7 @@ Exception.tests.cpp: + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index c704406f..fa078ac8 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -2049,6 +2049,42 @@ Nor would this + + + ("comma, in string", "escaped, \", ") := "escaped, ", " + + + "single quote in string,'," := "single quote in string,'," + + + "some escapes, \\,\\\\" := "some escapes, \,\\" + + + "some, ), unmatched, } prenheses {[<" := "some, ), unmatched, } prenheses {[<" + + + '"' := '"' + + + '\'' := ''' + + + ',' := ',' + + + '}' := '}' + + + ')' := ')' + + + '(' := '(' + + + '{' := '{' + + +
@@ -13692,7 +13728,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/UsageTests/Message.tests.cpp b/projects/SelfTest/UsageTests/Message.tests.cpp index ccb7ac2f..93347084 100644 --- a/projects/SelfTest/UsageTests/Message.tests.cpp +++ b/projects/SelfTest/UsageTests/Message.tests.cpp @@ -251,6 +251,13 @@ TEST_CASE("CAPTURE can deal with complex expressions involving commas", "[messag SUCCEED(); } +TEST_CASE("CAPTURE parses string and character constants", "[messages][capture]") { + CAPTURE(("comma, in string", "escaped, \", "), "single quote in string,',", "some escapes, \\,\\\\"); + CAPTURE("some, ), unmatched, } prenheses {[<"); + CAPTURE('"', '\'', ',', '}', ')', '(', '{'); + SUCCEED(); +} + #ifdef __clang__ #pragma clang diagnostic pop #endif