From d084162b2f41a319adb3d988f15a3aa3f127b936 Mon Sep 17 00:00:00 2001 From: Lotte Steenbrink Date: Mon, 7 Jan 2019 16:40:23 +0100 Subject: [PATCH] Avoid superfluous re-run when specific section is selected Fixes #1394 --- examples/300-FilteredSection.cpp | 35 ++++++++++++++++++++ examples/CMakeLists.txt | 1 + examples/runFilteredSection.sh | 8 +++++ include/internal/catch_test_case_tracker.cpp | 11 ++++++ include/internal/catch_test_case_tracker.h | 2 ++ 5 files changed, 57 insertions(+) create mode 100644 examples/300-FilteredSection.cpp create mode 100755 examples/runFilteredSection.sh diff --git a/examples/300-FilteredSection.cpp b/examples/300-FilteredSection.cpp new file mode 100644 index 00000000..7057ed10 --- /dev/null +++ b/examples/300-FilteredSection.cpp @@ -0,0 +1,35 @@ +// Provide a basis to check whether section selection via the `-c` command line +// option works as intended. + +#define CATCH_CONFIG_MAIN +#include + +bool previouslyRun = false; +bool previouslyRunNested = false; + +TEST_CASE( "#1394" ) { + // -- 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" ) { + 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); + } +} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 2551e77c..c889b087 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -21,6 +21,7 @@ set( REPORTER_HEADER_DIR ${CATCH_DIR}/include/reporters ) set( SOURCES_SINGLE_FILE 010-TestCase.cpp 231-Cfg-OutputStreams.cpp + 300-FilteredSection.cpp ) # multiple-file modules: diff --git a/examples/runFilteredSection.sh b/examples/runFilteredSection.sh new file mode 100755 index 00000000..2bd88392 --- /dev/null +++ b/examples/runFilteredSection.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# make sure single-file header was regenerated +../scripts/generateSingleHeader.py + +# run Test case with specified section to trigger bug #1394 +../cmake-build-debug/examples/300-FilteredSection \#1394 -c RunSection +../cmake-build-debug/examples/300-FilteredSection \#1394\ nested -c NestedRunSection -c s1 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();