Refactor noMatchingTestCases and skipTests reporter methods

They now take `StringRef` as the argument, and are virtual only
in the basic interface.

Also cleaned out the various reporters and their overrides
of these members which were often empty or delegating up.
This commit is contained in:
Martin Hořeňovský 2021-09-15 16:03:35 +02:00
parent 10fb93cce8
commit 013edc208b
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
20 changed files with 34 additions and 51 deletions

View File

@ -171,9 +171,8 @@ namespace Catch {
return m_preferences; return m_preferences;
} }
virtual void noMatchingTestCases( std::string const& spec ) = 0; virtual void noMatchingTestCases( StringRef unmatchedSpec ) = 0;
virtual void reportInvalidArguments( StringRef invalidArgument ) = 0;
virtual void reportInvalidArguments(std::string const&) {}
virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;

View File

@ -229,7 +229,8 @@ namespace Catch {
std::vector<ReporterDescription> const& ) {} std::vector<ReporterDescription> const& ) {}
void EventListenerBase::listTests( std::vector<TestCaseHandle> const& ) {} void EventListenerBase::listTests( std::vector<TestCaseHandle> const& ) {}
void EventListenerBase::listTags( std::vector<TagInfo> const& ) {} void EventListenerBase::listTags( std::vector<TagInfo> const& ) {}
void EventListenerBase::noMatchingTestCases( std::string const& ) {} void EventListenerBase::noMatchingTestCases( StringRef ) {}
void EventListenerBase::reportInvalidArguments( StringRef ) {}
void EventListenerBase::testRunStarting( TestRunInfo const& ) {} void EventListenerBase::testRunStarting( TestRunInfo const& ) {}
void EventListenerBase::testCaseStarting( TestCaseInfo const& ) {} void EventListenerBase::testCaseStarting( TestCaseInfo const& ) {}
void EventListenerBase::testCasePartialStarting(TestCaseInfo const&, uint64_t) {} void EventListenerBase::testCasePartialStarting(TestCaseInfo const&, uint64_t) {}

View File

@ -258,8 +258,8 @@ private:
return "Reports test results on a single line, suitable for IDEs"; return "Reports test results on a single line, suitable for IDEs";
} }
void CompactReporter::noMatchingTestCases( std::string const& spec ) { void CompactReporter::noMatchingTestCases( StringRef unmatchedSpec ) {
stream << "No test cases matched '" << spec << "'\n"; stream << "No test cases matched '" << unmatchedSpec << "'\n";
} }
void CompactReporter::assertionStarting( AssertionInfo const& ) {} void CompactReporter::assertionStarting( AssertionInfo const& ) {}

View File

@ -22,7 +22,7 @@ namespace Catch {
static std::string getDescription(); static std::string getDescription();
void noMatchingTestCases(std::string const& spec) override; void noMatchingTestCases( StringRef unmatchedSpec ) override;
void assertionStarting(AssertionInfo const&) override; void assertionStarting(AssertionInfo const&) override;

View File

@ -381,11 +381,11 @@ std::string ConsoleReporter::getDescription() {
return "Reports test results as plain lines of text"; return "Reports test results as plain lines of text";
} }
void ConsoleReporter::noMatchingTestCases(std::string const& spec) { void ConsoleReporter::noMatchingTestCases( StringRef unmatchedSpec ) {
stream << "No test cases matched '" << spec << "'\n"; stream << "No test cases matched '" << unmatchedSpec << "'\n";
} }
void ConsoleReporter::reportInvalidArguments(std::string const& arg) { void ConsoleReporter::reportInvalidArguments( StringRef arg ) {
stream << "Invalid Filter: " << arg << '\n'; stream << "Invalid Filter: " << arg << '\n';
} }

View File

@ -23,9 +23,8 @@ namespace Catch {
~ConsoleReporter() override; ~ConsoleReporter() override;
static std::string getDescription(); static std::string getDescription();
void noMatchingTestCases(std::string const& spec) override; void noMatchingTestCases( StringRef unmatchedSpec ) override;
void reportInvalidArguments( StringRef arg ) override;
void reportInvalidArguments(std::string const&arg) override;
void assertionStarting(AssertionInfo const&) override; void assertionStarting(AssertionInfo const&) override;

View File

@ -49,6 +49,11 @@ namespace Catch {
stream( _config.stream() ) {} stream( _config.stream() ) {}
~CumulativeReporterBase() override; ~CumulativeReporterBase() override;
void noMatchingTestCases( StringRef ) override {}
void reportInvalidArguments( StringRef ) override {}
void testRunStarting( TestRunInfo const& ) override {} void testRunStarting( TestRunInfo const& ) override {}
void testCaseStarting( TestCaseInfo const& ) override {} void testCaseStarting( TestCaseInfo const& ) override {}

View File

@ -24,6 +24,8 @@ namespace Catch {
EventListenerBase( ReporterConfig const& config ): EventListenerBase( ReporterConfig const& config ):
IStreamingReporter( config.fullConfig() ) {} IStreamingReporter( config.fullConfig() ) {}
void reportInvalidArguments( StringRef unmatchedSpec ) override;
void assertionStarting( AssertionInfo const& assertionInfo ) override; void assertionStarting( AssertionInfo const& assertionInfo ) override;
bool assertionEnded( AssertionStats const& assertionStats ) override; bool assertionEnded( AssertionStats const& assertionStats ) override;
@ -32,7 +34,7 @@ namespace Catch {
void listTests( std::vector<TestCaseHandle> const& tests ) override; void listTests( std::vector<TestCaseHandle> const& tests ) override;
void listTags( std::vector<TagInfo> const& tagInfos ) override; void listTags( std::vector<TagInfo> const& tagInfos ) override;
void noMatchingTestCases( std::string const& spec ) override; void noMatchingTestCases( StringRef unmatchedSpec ) override;
void testRunStarting( TestRunInfo const& testRunInfo ) override; void testRunStarting( TestRunInfo const& testRunInfo ) override;
void testCaseStarting( TestCaseInfo const& testInfo ) override; void testCaseStarting( TestCaseInfo const& testInfo ) override;
void testCasePartialStarting( TestCaseInfo const& testInfo, void testCasePartialStarting( TestCaseInfo const& testInfo,

View File

@ -64,14 +64,10 @@ namespace Catch {
m_preferences.shouldReportAllAssertions = true; m_preferences.shouldReportAllAssertions = true;
} }
JunitReporter::~JunitReporter() {}
std::string JunitReporter::getDescription() { std::string JunitReporter::getDescription() {
return "Reports test results in an XML format that looks like Ant's junitreport target"; return "Reports test results in an XML format that looks like Ant's junitreport target";
} }
void JunitReporter::noMatchingTestCases( std::string const& /*spec*/ ) {}
void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) { void JunitReporter::testRunStarting( TestRunInfo const& runInfo ) {
CumulativeReporterBase::testRunStarting( runInfo ); CumulativeReporterBase::testRunStarting( runInfo );
xml.startElement( "testsuites" ); xml.startElement( "testsuites" );

View File

@ -19,12 +19,10 @@ namespace Catch {
public: public:
JunitReporter(ReporterConfig const& _config); JunitReporter(ReporterConfig const& _config);
~JunitReporter() override; ~JunitReporter() override = default;
static std::string getDescription(); static std::string getDescription();
void noMatchingTestCases(std::string const& /*spec*/) override;
void testRunStarting(TestRunInfo const& runInfo) override; void testRunStarting(TestRunInfo const& runInfo) override;
void testCaseStarting(TestCaseInfo const& testCaseInfo) override; void testCaseStarting(TestCaseInfo const& testCaseInfo) override;

View File

@ -22,14 +22,14 @@ namespace Catch {
m_preferences.shouldRedirectStdOut = m_reporter->getPreferences().shouldRedirectStdOut; m_preferences.shouldRedirectStdOut = m_reporter->getPreferences().shouldRedirectStdOut;
} }
void ListeningReporter::noMatchingTestCases( std::string const& spec ) { void ListeningReporter::noMatchingTestCases( StringRef unmatchedSpec ) {
for ( auto& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->noMatchingTestCases( spec ); listener->noMatchingTestCases( unmatchedSpec );
} }
m_reporter->noMatchingTestCases( spec ); m_reporter->noMatchingTestCases( unmatchedSpec );
} }
void ListeningReporter::reportInvalidArguments(std::string const&arg){ void ListeningReporter::reportInvalidArguments( StringRef arg ) {
for ( auto& listener : m_listeners ) { for ( auto& listener : m_listeners ) {
listener->reportInvalidArguments( arg ); listener->reportInvalidArguments( arg );
} }

View File

@ -30,9 +30,9 @@ namespace Catch {
public: // IStreamingReporter public: // IStreamingReporter
void noMatchingTestCases( std::string const& spec ) override; void noMatchingTestCases( StringRef unmatchedSpec ) override;
void reportInvalidArguments(std::string const&arg) override; void reportInvalidArguments( StringRef arg ) override;
void benchmarkPreparing( StringRef name ) override; void benchmarkPreparing( StringRef name ) override;
void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override; void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;

View File

@ -14,8 +14,6 @@
namespace Catch { namespace Catch {
SonarQubeReporter::~SonarQubeReporter() {}
void SonarQubeReporter::testRunStarting(TestRunInfo const& testRunInfo) { void SonarQubeReporter::testRunStarting(TestRunInfo const& testRunInfo) {
CumulativeReporterBase::testRunStarting(testRunInfo); CumulativeReporterBase::testRunStarting(testRunInfo);
xml.startElement("testExecutions"); xml.startElement("testExecutions");

View File

@ -23,15 +23,13 @@ namespace Catch {
m_preferences.shouldReportAllAssertions = true; m_preferences.shouldReportAllAssertions = true;
} }
~SonarQubeReporter() override; ~SonarQubeReporter() override = default;
static std::string getDescription() { static std::string getDescription() {
using namespace std::string_literals; using namespace std::string_literals;
return "Reports test results in the Generic Test Data SonarQube XML format"s; return "Reports test results in the Generic Test Data SonarQube XML format"s;
} }
void noMatchingTestCases(std::string const& /*spec*/) override {}
void testRunStarting( TestRunInfo const& testRunInfo ) override; void testRunStarting( TestRunInfo const& testRunInfo ) override;
void testRunEndedCumulative() override { void testRunEndedCumulative() override {

View File

@ -42,9 +42,8 @@ namespace Catch {
~StreamingReporterBase() override; ~StreamingReporterBase() override;
void noMatchingTestCases(std::string const&) override {} void noMatchingTestCases( StringRef /*unmatchedSpec*/ ) override {}
void reportInvalidArguments( StringRef /*invalidArgument*/ ) override {}
void reportInvalidArguments(std::string const&) override {}
void testRunStarting( TestRunInfo const& _testRunInfo ) override; void testRunStarting( TestRunInfo const& _testRunInfo ) override;

View File

@ -194,10 +194,8 @@ namespace Catch {
} // End anonymous namespace } // End anonymous namespace
TAPReporter::~TAPReporter() {} void TAPReporter::noMatchingTestCases( StringRef unmatchedSpec ) {
stream << "# No test cases matched '" << unmatchedSpec << "'\n";
void TAPReporter::noMatchingTestCases(std::string const& spec) {
stream << "# No test cases matched '" << spec << "'\n";
} }
bool TAPReporter::assertionEnded(AssertionStats const& _assertionStats) { bool TAPReporter::assertionEnded(AssertionStats const& _assertionStats) {

View File

@ -18,14 +18,14 @@ namespace Catch {
StreamingReporterBase( config ) { StreamingReporterBase( config ) {
m_preferences.shouldReportAllAssertions = true; m_preferences.shouldReportAllAssertions = true;
} }
~TAPReporter() override; ~TAPReporter() override = default;
static std::string getDescription() { static std::string getDescription() {
using namespace std::string_literals; using namespace std::string_literals;
return "Reports test results in TAP format, suitable for test harnesses"s; return "Reports test results in TAP format, suitable for test harnesses"s;
} }
void noMatchingTestCases(std::string const& spec) override; void noMatchingTestCases( StringRef unmatchedSpec ) override;
void assertionStarting( AssertionInfo const& ) override {} void assertionStarting( AssertionInfo const& ) override {}

View File

@ -34,10 +34,6 @@ namespace Catch {
return "Reports test results as TeamCity service messages"s; return "Reports test results as TeamCity service messages"s;
} }
void skipTest( TestCaseInfo const& /* testInfo */ ) override {}
void noMatchingTestCases( std::string const& /* spec */ ) override {}
void testRunStarting( TestRunInfo const& groupInfo ) override; void testRunStarting( TestRunInfo const& groupInfo ) override;
void testRunEnded( TestRunStats const& testGroupStats ) override; void testRunEnded( TestRunStats const& testGroupStats ) override;

View File

@ -46,10 +46,6 @@ namespace Catch {
.writeAttribute( "line"_sr, sourceInfo.line ); .writeAttribute( "line"_sr, sourceInfo.line );
} }
void XmlReporter::noMatchingTestCases( std::string const& s ) {
StreamingReporterBase::noMatchingTestCases( s );
}
void XmlReporter::testRunStarting( TestRunInfo const& testInfo ) { void XmlReporter::testRunStarting( TestRunInfo const& testInfo ) {
StreamingReporterBase::testRunStarting( testInfo ); StreamingReporterBase::testRunStarting( testInfo );
std::string stylesheetRef = getStylesheetRef(); std::string stylesheetRef = getStylesheetRef();

View File

@ -29,8 +29,6 @@ namespace Catch {
public: // StreamingReporterBase public: // StreamingReporterBase
void noMatchingTestCases(std::string const& s) override;
void testRunStarting(TestRunInfo const& testInfo) override; void testRunStarting(TestRunInfo const& testInfo) override;
void testCaseStarting(TestCaseInfo const& testInfo) override; void testCaseStarting(TestCaseInfo const& testInfo) override;