mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
support for printing test filters (PR #1585)
This commit is contained in:
parent
3816e99d0c
commit
8af8704089
@ -82,7 +82,7 @@ namespace Catch {
|
|||||||
std::string getProcessName() const;
|
std::string getProcessName() const;
|
||||||
std::string const& getReporterName() const;
|
std::string const& getReporterName() const;
|
||||||
|
|
||||||
std::vector<std::string> const& getTestsOrTags() const;
|
std::vector<std::string> const& getTestsOrTags() const override;
|
||||||
std::vector<std::string> const& getSectionsToRun() const override;
|
std::vector<std::string> const& getSectionsToRun() const override;
|
||||||
|
|
||||||
virtual TestSpec const& testSpec() const override;
|
virtual TestSpec const& testSpec() const override;
|
||||||
|
@ -69,6 +69,7 @@ namespace Catch {
|
|||||||
virtual ShowDurations::OrNot showDurations() const = 0;
|
virtual ShowDurations::OrNot showDurations() const = 0;
|
||||||
virtual TestSpec const& testSpec() const = 0;
|
virtual TestSpec const& testSpec() const = 0;
|
||||||
virtual bool hasTestFilters() const = 0;
|
virtual bool hasTestFilters() const = 0;
|
||||||
|
virtual std::vector<std::string> const& getTestsOrTags() const = 0;
|
||||||
virtual RunTests::InWhatOrder runOrder() const = 0;
|
virtual RunTests::InWhatOrder runOrder() const = 0;
|
||||||
virtual unsigned int rngSeed() const = 0;
|
virtual unsigned int rngSeed() const = 0;
|
||||||
virtual int benchmarkResolutionMultiple() const = 0;
|
virtual int benchmarkResolutionMultiple() const = 0;
|
||||||
|
@ -41,6 +41,20 @@ namespace Catch {
|
|||||||
return std::string(buffer);
|
return std::string(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string serializeFilters( std::vector<std::string> const& container ) {
|
||||||
|
ReusableStringStream oss;
|
||||||
|
bool first = true;
|
||||||
|
for (auto&& filter : container)
|
||||||
|
{
|
||||||
|
if (!first)
|
||||||
|
oss << ' ';
|
||||||
|
else
|
||||||
|
first = false;
|
||||||
|
|
||||||
|
oss << filter;
|
||||||
|
}
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config)
|
TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config)
|
||||||
:StreamingReporterBase(_config) {}
|
:StreamingReporterBase(_config) {}
|
||||||
|
@ -25,6 +25,8 @@ namespace Catch {
|
|||||||
// Returns double formatted as %.3f (format expected on output)
|
// Returns double formatted as %.3f (format expected on output)
|
||||||
std::string getFormattedDuration( double duration );
|
std::string getFormattedDuration( double duration );
|
||||||
|
|
||||||
|
std::string serializeFilters( std::vector<std::string> const& container );
|
||||||
|
|
||||||
template<typename DerivedT>
|
template<typename DerivedT>
|
||||||
struct StreamingReporterBase : IStreamingReporter {
|
struct StreamingReporterBase : IStreamingReporter {
|
||||||
|
|
||||||
@ -52,6 +54,7 @@ namespace Catch {
|
|||||||
void testRunStarting(TestRunInfo const& _testRunInfo) override {
|
void testRunStarting(TestRunInfo const& _testRunInfo) override {
|
||||||
currentTestRunInfo = _testRunInfo;
|
currentTestRunInfo = _testRunInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void testGroupStarting(GroupInfo const& _groupInfo) override {
|
void testGroupStarting(GroupInfo const& _groupInfo) override {
|
||||||
currentGroupInfo = _groupInfo;
|
currentGroupInfo = _groupInfo;
|
||||||
}
|
}
|
||||||
|
@ -441,6 +441,10 @@ void ConsoleReporter::testRunEnded(TestRunStats const& _testRunStats) {
|
|||||||
stream << std::endl;
|
stream << std::endl;
|
||||||
StreamingReporterBase::testRunEnded(_testRunStats);
|
StreamingReporterBase::testRunEnded(_testRunStats);
|
||||||
}
|
}
|
||||||
|
void ConsoleReporter::testRunStarting(TestRunInfo const& _testInfo) {
|
||||||
|
StreamingReporterBase::testRunStarting(_testInfo);
|
||||||
|
printTestFilters();
|
||||||
|
}
|
||||||
|
|
||||||
void ConsoleReporter::lazyPrint() {
|
void ConsoleReporter::lazyPrint() {
|
||||||
|
|
||||||
@ -622,6 +626,11 @@ void ConsoleReporter::printSummaryDivider() {
|
|||||||
stream << getLineOfChars<'-'>() << '\n';
|
stream << getLineOfChars<'-'>() << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConsoleReporter::printTestFilters() {
|
||||||
|
if (m_config->testSpec().hasFilters())
|
||||||
|
stream << Colour(Colour::BrightYellow) << "Filters: " << serializeFilters( m_config->getTestsOrTags() ) << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
CATCH_REGISTER_REPORTER("console", ConsoleReporter)
|
CATCH_REGISTER_REPORTER("console", ConsoleReporter)
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
@ -46,7 +46,7 @@ namespace Catch {
|
|||||||
void testCaseEnded(TestCaseStats const& _testCaseStats) override;
|
void testCaseEnded(TestCaseStats const& _testCaseStats) override;
|
||||||
void testGroupEnded(TestGroupStats const& _testGroupStats) override;
|
void testGroupEnded(TestGroupStats const& _testGroupStats) override;
|
||||||
void testRunEnded(TestRunStats const& _testRunStats) override;
|
void testRunEnded(TestRunStats const& _testRunStats) override;
|
||||||
|
void testRunStarting(TestRunInfo const& _testRunInfo) override;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void lazyPrint();
|
void lazyPrint();
|
||||||
@ -69,6 +69,7 @@ namespace Catch {
|
|||||||
|
|
||||||
void printTotalsDivider(Totals const& totals);
|
void printTotalsDivider(Totals const& totals);
|
||||||
void printSummaryDivider();
|
void printSummaryDivider();
|
||||||
|
void printTestFilters();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_headerPrinted = false;
|
bool m_headerPrinted = false;
|
||||||
|
@ -76,8 +76,17 @@ namespace Catch {
|
|||||||
void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) {
|
void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) {
|
||||||
CumulativeReporterBase::testRunStarting( runInfo );
|
CumulativeReporterBase::testRunStarting( runInfo );
|
||||||
xml.startElement( "testsuites" );
|
xml.startElement( "testsuites" );
|
||||||
|
|
||||||
|
if ( m_config->hasTestFilters() || m_config->rngSeed() != 0 )
|
||||||
|
xml.startElement("properties");
|
||||||
|
|
||||||
|
if ( m_config->hasTestFilters() ) {
|
||||||
|
xml.scopedElement( "property" )
|
||||||
|
.writeAttribute( "name" , "filters" )
|
||||||
|
.writeAttribute( "value" , serializeFilters( m_config->getTestsOrTags() ) );
|
||||||
|
}
|
||||||
|
|
||||||
if( m_config->rngSeed() != 0 ) {
|
if( m_config->rngSeed() != 0 ) {
|
||||||
xml.startElement( "properties" );
|
|
||||||
xml.scopedElement( "property" )
|
xml.scopedElement( "property" )
|
||||||
.writeAttribute( "name", "random-seed" )
|
.writeAttribute( "name", "random-seed" )
|
||||||
.writeAttribute( "value", m_config->rngSeed() );
|
.writeAttribute( "value", m_config->rngSeed() );
|
||||||
|
@ -55,6 +55,8 @@ namespace Catch {
|
|||||||
m_xml.startElement( "Catch" );
|
m_xml.startElement( "Catch" );
|
||||||
if( !m_config->name().empty() )
|
if( !m_config->name().empty() )
|
||||||
m_xml.writeAttribute( "name", m_config->name() );
|
m_xml.writeAttribute( "name", m_config->name() );
|
||||||
|
if (m_config->testSpec().hasFilters())
|
||||||
|
m_xml.writeAttribute( "filters", serializeFilters( m_config->getTestsOrTags() ) );
|
||||||
if( m_config->rngSeed() != 0 )
|
if( m_config->rngSeed() != 0 )
|
||||||
m_xml.scopedElement( "Randomness" )
|
m_xml.scopedElement( "Randomness" )
|
||||||
.writeAttribute( "seed", m_config->rngSeed() );
|
.writeAttribute( "seed", m_config->rngSeed() );
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
Filters: ~[!nonportable]~[!benchmark]~[approvals]
|
||||||
This would not be caught previously
|
This would not be caught previously
|
||||||
Nor would this
|
Nor would this
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
Filters: ~[!nonportable]~[!benchmark]~[approvals]
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
<exe-name> is a <version> host application.
|
<exe-name> is a <version> host application.
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
Filters: ~[!nonportable]~[!benchmark]~[approvals]
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
<exe-name> is a <version> host application.
|
<exe-name> is a <version> host application.
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<properties>
|
<properties>
|
||||||
|
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
|
||||||
<property name="random-seed" value="1"/>
|
<property name="random-seed" value="1"/>
|
||||||
</properties>
|
</properties>
|
||||||
loose text artifact
|
loose text artifact
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<Catch name="<exe-name>">
|
<Catch name="<exe-name>" filters="~[!nonportable]~[!benchmark]~[approvals]">
|
||||||
<Randomness seed="1"/>
|
<Randomness seed="1"/>
|
||||||
<Group name="<exe-name>">
|
<Group name="<exe-name>">
|
||||||
<TestCase name="# A test name that starts with a #" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
|
<TestCase name="# A test name that starts with a #" filename="projects/<exe-name>/UsageTests/Misc.tests.cpp" >
|
||||||
|
Loading…
Reference in New Issue
Block a user