From 2bcff9dd3581708d50734d3f55949146e5ba0162 Mon Sep 17 00:00:00 2001 From: amitherman95 Date: Sat, 14 Sep 2019 12:38:47 +0300 Subject: [PATCH 1/3] Escape characters bug patch(v2.9.2) --- include/internal/catch_test_spec_parser.cpp | 22 ++++++++++++++++----- include/internal/catch_test_spec_parser.h | 7 +++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/internal/catch_test_spec_parser.cpp b/include/internal/catch_test_spec_parser.cpp index a910ac7e..5cbbdeb7 100644 --- a/include/internal/catch_test_spec_parser.cpp +++ b/include/internal/catch_test_spec_parser.cpp @@ -28,7 +28,12 @@ namespace Catch { return m_testSpec; } void TestSpecParser::visitChar( char c ) { - if( c == ',' ) { + if( (m_mode != EscapedName) && (c == '\\') ) { + escape(); + m_substring += c; + m_patternName += c; + return; + }else if((m_mode != EscapedName) && (c == ',') ) { endMode(); addFilter(); return; @@ -72,9 +77,6 @@ namespace Catch { case '"': startNewMode( QuotedName ); return false; - case '\\': - escape(); - return true; default: startNewMode( Name ); return false; @@ -107,13 +109,15 @@ namespace Catch { case Tag: return addPattern(); case EscapedName: - return startNewMode( Name ); + revertBackToLastMode(); + return; case None: default: return startNewMode( None ); } } void TestSpecParser::escape() { + saveLastMode(); m_mode = EscapedName; m_escapeChars.push_back( m_pos ); } @@ -141,6 +145,14 @@ namespace Catch { } } + void TestSpecParser::saveLastMode() { + lastMode = m_mode; + } + + void TestSpecParser::revertBackToLastMode() { + m_mode = lastMode; + } + TestSpec parseTestSpec( std::string const& arg ) { return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); } diff --git a/include/internal/catch_test_spec_parser.h b/include/internal/catch_test_spec_parser.h index 5b02bf6d..778da134 100644 --- a/include/internal/catch_test_spec_parser.h +++ b/include/internal/catch_test_spec_parser.h @@ -22,6 +22,7 @@ namespace Catch { class TestSpecParser { enum Mode{ None, Name, QuotedName, Tag, EscapedName }; Mode m_mode = None; + Mode lastMode = None; bool m_exclusion = false; std::size_t m_pos = 0; std::string m_arg; @@ -47,7 +48,9 @@ namespace Catch { void endMode(); void escape(); bool isControlChar( char c ) const; - + void saveLastMode(); + void revertBackToLastMode(); + template void addPattern() { std::string token = m_patternName; @@ -80,4 +83,4 @@ namespace Catch { #pragma clang diagnostic pop #endif -#endif // TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED +#endif // TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED \ No newline at end of file From fc2066bf18e4f20cc1609d1083adcfe3764866af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 21 Sep 2019 00:11:45 +0200 Subject: [PATCH 2/3] Add tests for escaping special characters in CLI --- projects/CMakeLists.txt | 3 +++ projects/SelfTest/Baselines/compact.sw.approved.txt | 1 + projects/SelfTest/Baselines/console.std.approved.txt | 4 ++-- projects/SelfTest/Baselines/console.sw.approved.txt | 12 ++++++++++-- projects/SelfTest/Baselines/junit.sw.approved.txt | 3 ++- projects/SelfTest/Baselines/xml.sw.approved.txt | 7 +++++-- .../SelfTest/IntrospectiveTests/CmdLine.tests.cpp | 5 +++++ 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt index 7105632b..0eb7cb56 100644 --- a/projects/CMakeLists.txt +++ b/projects/CMakeLists.txt @@ -429,6 +429,9 @@ set_tests_properties(LibIdentityTest PROPERTIES PASS_REGULAR_EXPRESSION "descrip add_test(NAME FilenameAsTagsTest COMMAND $ -\# --list-tags) set_tests_properties(FilenameAsTagsTest PROPERTIES PASS_REGULAR_EXPRESSION "\\[#Approx.tests\\]") +add_test(NAME EscapeSpecialCharactersInTestNames COMMAND $ "Test with special\\, characters \"in name") +set_tests_properties(EscapeSpecialCharactersInTestNames PROPERTIES PASS_REGULAR_EXPRESSION "1 assertion in 1 test case") + if (CATCH_USE_VALGRIND) add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $) diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 9a7abcef..03b49599 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -1235,6 +1235,7 @@ Misc.tests.cpp:: passed: v.size() == V for: 15 == 15 Misc.tests.cpp:: passed: v.capacity() >= V for: 15 >= 15 VariadicMacros.tests.cpp:: passed: with 1 message: 'no assertions' Tricky.tests.cpp:: passed: 0x == bit30and31 for: 3221225472 (0x) == 3221225472 +CmdLine.tests.cpp:: passed: Message.tests.cpp:: failed - but was ok: 1 == 2 Misc.tests.cpp:: passed: with 1 message: 'oops!' Exception.tests.cpp:: failed: unexpected exception with message: 'For some reason someone is throwing a string literal!' diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index d2b2165f..5798dcbe 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1380,6 +1380,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 300 | 226 passed | 70 failed | 4 failed as expected -assertions: 1568 | 1416 passed | 131 failed | 21 failed as expected +test cases: 301 | 227 passed | 70 failed | 4 failed as expected +assertions: 1569 | 1417 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 6eabf307..b4aba834 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -9321,6 +9321,14 @@ Tricky.tests.cpp:: PASSED: with expansion: 3221225472 (0x) == 3221225472 +------------------------------------------------------------------------------- +Test with special, characters "in name +------------------------------------------------------------------------------- +CmdLine.tests.cpp: +............................................................................... + +CmdLine.tests.cpp:: PASSED: + ------------------------------------------------------------------------------- The NO_FAIL macro reports a failure but does not fail the test ------------------------------------------------------------------------------- @@ -12520,6 +12528,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 300 | 210 passed | 86 failed | 4 failed as expected -assertions: 1585 | 1416 passed | 148 failed | 21 failed as expected +test cases: 301 | 211 passed | 86 failed | 4 failed as expected +assertions: 1586 | 1417 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index e764d1f6..a768f1e6 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -808,6 +808,7 @@ Misc.tests.cpp: + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index b58684d7..c4e5a75e 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -11269,6 +11269,9 @@ Message from section two + + + @@ -14912,7 +14915,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp index 6ecc3a14..60eb97af 100644 --- a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp @@ -506,3 +506,8 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]" } } } + +TEST_CASE("Test with special, characters \"in name", "[cli][regression]") { + // This test case succeeds if we can invoke it from the CLI + SUCCEED(); +} From de42f8a93e2febf11bfac74067250e344be24adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sat, 21 Sep 2019 23:19:45 +0200 Subject: [PATCH 3/3] Fix escaping of quotes in coverage helper --- misc/coverage-helper.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/misc/coverage-helper.cpp b/misc/coverage-helper.cpp index b9558b75..a31e927f 100644 --- a/misc/coverage-helper.cpp +++ b/misc/coverage-helper.cpp @@ -29,7 +29,8 @@ std::string escape_arg(const std::string& arg) { escaped.append(num_backslashes * 2, '\\'); break; } else if (*it == '"') { - escaped.append(num_backslashes * 2 + 1, '\\'); + escaped.append((num_backslashes + 1) * 2, '\\'); + escaped.push_back('"'); escaped.push_back(*it); } else { escaped.append(num_backslashes, '\\'); @@ -97,7 +98,7 @@ int exec_cmd(std::string const& cmd, int log_num, std::string const& path) { + ".bin --quiet " + "--sources " + escape_arg(path) + " --cover_children -- " + cmd; std::cout << "=== Marker ===: Cmd: " << real_cmd << '\n'; auto pipe = _popen(real_cmd.c_str(), "r"); - + if (!pipe) { throw std::runtime_error("popen() failed!"); } @@ -106,12 +107,12 @@ int exec_cmd(std::string const& cmd, int log_num, std::string const& path) { std::cout << buffer.data(); } } - + auto ret = _pclose(pipe); if (ret == -1) { throw std::runtime_error("underlying error in pclose()"); } - + return ret; } @@ -127,7 +128,7 @@ int main(int argc, char** argv) { assert(sep - begin(args) == 2 && "Structure differs from expected!"); auto num = parse_log_file_arg(args[1]); - + auto cmdline = std::accumulate(++sep, end(args), std::string{}, [] (const std::string& lhs, const std::string& rhs) { return lhs + ' ' + escape_arg(rhs); });