mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
support for printing test filters (PR #1585)
This commit is contained in:

committed by
Martin Hořeňovský

parent
3816e99d0c
commit
8af8704089
@@ -41,6 +41,20 @@ namespace Catch {
|
||||
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)
|
||||
:StreamingReporterBase(_config) {}
|
||||
|
@@ -25,6 +25,8 @@ namespace Catch {
|
||||
// Returns double formatted as %.3f (format expected on output)
|
||||
std::string getFormattedDuration( double duration );
|
||||
|
||||
std::string serializeFilters( std::vector<std::string> const& container );
|
||||
|
||||
template<typename DerivedT>
|
||||
struct StreamingReporterBase : IStreamingReporter {
|
||||
|
||||
@@ -52,6 +54,7 @@ namespace Catch {
|
||||
void testRunStarting(TestRunInfo const& _testRunInfo) override {
|
||||
currentTestRunInfo = _testRunInfo;
|
||||
}
|
||||
|
||||
void testGroupStarting(GroupInfo const& _groupInfo) override {
|
||||
currentGroupInfo = _groupInfo;
|
||||
}
|
||||
|
@@ -441,6 +441,10 @@ void ConsoleReporter::testRunEnded(TestRunStats const& _testRunStats) {
|
||||
stream << std::endl;
|
||||
StreamingReporterBase::testRunEnded(_testRunStats);
|
||||
}
|
||||
void ConsoleReporter::testRunStarting(TestRunInfo const& _testInfo) {
|
||||
StreamingReporterBase::testRunStarting(_testInfo);
|
||||
printTestFilters();
|
||||
}
|
||||
|
||||
void ConsoleReporter::lazyPrint() {
|
||||
|
||||
@@ -622,6 +626,11 @@ void ConsoleReporter::printSummaryDivider() {
|
||||
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)
|
||||
|
||||
} // end namespace Catch
|
||||
|
@@ -46,7 +46,7 @@ namespace Catch {
|
||||
void testCaseEnded(TestCaseStats const& _testCaseStats) override;
|
||||
void testGroupEnded(TestGroupStats const& _testGroupStats) override;
|
||||
void testRunEnded(TestRunStats const& _testRunStats) override;
|
||||
|
||||
void testRunStarting(TestRunInfo const& _testRunInfo) override;
|
||||
private:
|
||||
|
||||
void lazyPrint();
|
||||
@@ -69,6 +69,7 @@ namespace Catch {
|
||||
|
||||
void printTotalsDivider(Totals const& totals);
|
||||
void printSummaryDivider();
|
||||
void printTestFilters();
|
||||
|
||||
private:
|
||||
bool m_headerPrinted = false;
|
||||
|
@@ -76,8 +76,17 @@ namespace Catch {
|
||||
void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) {
|
||||
CumulativeReporterBase::testRunStarting( runInfo );
|
||||
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 ) {
|
||||
xml.startElement( "properties" );
|
||||
xml.scopedElement( "property" )
|
||||
.writeAttribute( "name", "random-seed" )
|
||||
.writeAttribute( "value", m_config->rngSeed() );
|
||||
|
@@ -55,6 +55,8 @@ namespace Catch {
|
||||
m_xml.startElement( "Catch" );
|
||||
if( !m_config->name().empty() )
|
||||
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 )
|
||||
m_xml.scopedElement( "Randomness" )
|
||||
.writeAttribute( "seed", m_config->rngSeed() );
|
||||
|
Reference in New Issue
Block a user