diff --git a/include/internal/catch_test_case_tracker.cpp b/include/internal/catch_test_case_tracker.cpp index 7839a71b..8c188457 100644 --- a/include/internal/catch_test_case_tracker.cpp +++ b/include/internal/catch_test_case_tracker.cpp @@ -190,6 +190,17 @@ namespace TestCaseTracking { } } + bool SectionTracker::isComplete() const { + bool complete = true; + + if ((m_filters.empty() || m_filters[0] == "") || + std::find(m_filters.begin(), m_filters.end(), + m_nameAndLocation.name) != m_filters.end()) + complete = TrackerBase::isComplete(); + return complete; + + } + bool SectionTracker::isSectionTracker() const { return true; } SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) { diff --git a/include/internal/catch_test_case_tracker.h b/include/internal/catch_test_case_tracker.h index 72b506a9..485118ed 100644 --- a/include/internal/catch_test_case_tracker.h +++ b/include/internal/catch_test_case_tracker.h @@ -140,6 +140,8 @@ namespace TestCaseTracking { bool isSectionTracker() const override; + bool isComplete() const override; + static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ); void tryOpen(); diff --git a/misc/coverage-helper.cpp b/misc/coverage-helper.cpp index 17218905..a6643838 100644 --- a/misc/coverage-helper.cpp +++ b/misc/coverage-helper.cpp @@ -9,6 +9,38 @@ #include #include +std::string escape_arg(const std::string& arg) { + if (arg.empty() == false && + arg.find_first_of(" \t\n\v\"") == arg.npos) { + return arg; + } + + std::string escaped; + escaped.push_back('"'); + for (auto it = arg.begin(); ; ++it) { + int num_backslashes = 0; + + while (it != arg.end() && *it == '\\') { + ++it; + ++num_backslashes; + } + + if (it == arg.end()) { + escaped.append(num_backslashes * 2, '\\'); + break; + } else if (*it == '"') { + escaped.append(num_backslashes * 2 + 1, '\\'); + escaped.push_back(*it); + } else { + escaped.append(num_backslashes, '\\'); + escaped.push_back(*it); + } + } + escaped.push_back('"'); + + return escaped; +} + void create_empty_file(std::string const& path) { std::ofstream ofs(path); @@ -60,8 +92,9 @@ std::string windowsify_path(std::string path) { void exec_cmd(std::string const& cmd, int log_num, std::string const& path) { std::array buffer; #if defined(_WIN32) + // cmd has already been escaped outside this function. auto real_cmd = "OpenCppCoverage --export_type binary:cov-report" + std::to_string(log_num) - + ".bin --quiet " + "--sources " + path + " --cover_children -- " + cmd; + + ".bin --quiet " + "--sources " + escape_arg(path) + " --cover_children -- " + cmd; std::cout << "=== Marker ===: Cmd: " << real_cmd << '\n'; std::shared_ptr pipe(_popen(real_cmd.c_str(), "r"), _pclose); #else // Just for testing, in the real world we will always work under WIN32 @@ -91,9 +124,9 @@ 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 + ' ' + rhs; + return lhs + ' ' + escape_arg(rhs); }); try { diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt index fbd3fd2e..62fa7167 100644 --- a/projects/CMakeLists.txt +++ b/projects/CMakeLists.txt @@ -345,10 +345,16 @@ set_tests_properties(NoAssertions PROPERTIES PASS_REGULAR_EXPRESSION "No asserti add_test(NAME NoTest COMMAND $ -w NoTests "___nonexistent_test___") set_tests_properties(NoTest PROPERTIES PASS_REGULAR_EXPRESSION "No test cases matched") +add_test(NAME FilteredSection-1 COMMAND $ \#1394 -c RunSection) +set_tests_properties(FilteredSection-1 PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran") +add_test(NAME FilteredSection-2 COMMAND $ \#1394\ nested -c NestedRunSection -c s1) +set_tests_properties(FilteredSection-2 PROPERTIES FAIL_REGULAR_EXPRESSION "No tests ran") + # AppVeyor has a Python 2.7 in path, but doesn't have .py files as autorunnable add_test(NAME ApprovalTests COMMAND ${PYTHON_EXECUTABLE} ${CATCH_DIR}/scripts/approvalTests.py $) set_tests_properties(ApprovalTests PROPERTIES FAIL_REGULAR_EXPRESSION "Results differed") + if (CATCH_USE_VALGRIND) add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $) add_test(NAME ValgrindListTests COMMAND valgrind --leak-check=full --error-exitcode=1 $ --list-tests --verbosity high) diff --git a/projects/SelfTest/IntrospectiveTests/PartTracker.tests.cpp b/projects/SelfTest/IntrospectiveTests/PartTracker.tests.cpp index 7e7f14b4..12dcca91 100644 --- a/projects/SelfTest/IntrospectiveTests/PartTracker.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/PartTracker.tests.cpp @@ -324,3 +324,33 @@ TEST_CASE( "Tracker" ) { // two sections within a generator } } + +static bool previouslyRun = false; +static bool previouslyRunNested = false; + +TEST_CASE( "#1394", "[.][approvals][tracker]" ) { + // -- Don't re-run after specified section is done + REQUIRE(previouslyRun == false); + + SECTION( "RunSection" ) { + previouslyRun = true; + } + SECTION( "SkipSection" ) { + // cause an error if this section is called because it shouldn't be + REQUIRE(1 == 0); + } +} + +TEST_CASE( "#1394 nested", "[.][approvals][tracker]" ) { + REQUIRE(previouslyRunNested == false); + + SECTION( "NestedRunSection" ) { + SECTION( "s1" ) { + previouslyRunNested = true; + } + } + SECTION( "NestedSkipSection" ) { + // cause an error if this section is called because it shouldn't be + REQUIRE(1 == 0); + } +}