mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
parent
c1720d0c42
commit
d084162b2f
35
examples/300-FilteredSection.cpp
Normal file
35
examples/300-FilteredSection.cpp
Normal file
@ -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 <catch2/catch.hpp>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ set( REPORTER_HEADER_DIR ${CATCH_DIR}/include/reporters )
|
|||||||
set( SOURCES_SINGLE_FILE
|
set( SOURCES_SINGLE_FILE
|
||||||
010-TestCase.cpp
|
010-TestCase.cpp
|
||||||
231-Cfg-OutputStreams.cpp
|
231-Cfg-OutputStreams.cpp
|
||||||
|
300-FilteredSection.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# multiple-file modules:
|
# multiple-file modules:
|
||||||
|
8
examples/runFilteredSection.sh
Executable file
8
examples/runFilteredSection.sh
Executable file
@ -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
|
@ -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; }
|
bool SectionTracker::isSectionTracker() const { return true; }
|
||||||
|
|
||||||
SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) {
|
SectionTracker& SectionTracker::acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) {
|
||||||
|
@ -140,6 +140,8 @@ namespace TestCaseTracking {
|
|||||||
|
|
||||||
bool isSectionTracker() const override;
|
bool isSectionTracker() const override;
|
||||||
|
|
||||||
|
bool isComplete() const override;
|
||||||
|
|
||||||
static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation );
|
static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation );
|
||||||
|
|
||||||
void tryOpen();
|
void tryOpen();
|
||||||
|
Loading…
Reference in New Issue
Block a user