mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-03 05:45:39 +02:00
Implement warning for unmatched test specs
This commit is contained in:
@@ -70,6 +70,9 @@ namespace Catch {
|
||||
bool Config::warnAboutMissingAssertions() const {
|
||||
return !!( m_data.warnings & WarnAbout::NoAssertions );
|
||||
}
|
||||
bool Config::warnAboutUnmatchedTestSpecs() const {
|
||||
return !!( m_data.warnings & WarnAbout::UnmatchedTestSpec );
|
||||
}
|
||||
bool Config::zeroTestsCountAsSuccess() const { return m_data.allowZeroTests; }
|
||||
ShowDurations Config::showDurations() const { return m_data.showDurations; }
|
||||
double Config::minDuration() const { return m_data.minDuration; }
|
||||
|
@@ -98,6 +98,7 @@ namespace Catch {
|
||||
StringRef name() const override;
|
||||
bool includeSuccessfulResults() const override;
|
||||
bool warnAboutMissingAssertions() const override;
|
||||
bool warnAboutUnmatchedTestSpecs() const override;
|
||||
bool zeroTestsCountAsSuccess() const override;
|
||||
ShowDurations showDurations() const override;
|
||||
double minDuration() const override;
|
||||
|
@@ -96,20 +96,26 @@ namespace Catch {
|
||||
|
||||
for (auto const& match : m_matches) {
|
||||
if (match.tests.empty()) {
|
||||
m_reporter->noMatchingTestCases(match.name);
|
||||
totals.error = -1;
|
||||
m_unmatchedTestSpecs = true;
|
||||
m_reporter->noMatchingTestCases( match.name );
|
||||
}
|
||||
}
|
||||
|
||||
return totals;
|
||||
}
|
||||
|
||||
bool hadUnmatchedTestSpecs() const {
|
||||
return m_unmatchedTestSpecs;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
IStreamingReporter* m_reporter;
|
||||
Config const* m_config;
|
||||
RunContext m_context;
|
||||
std::set<TestCaseHandle const*> m_tests;
|
||||
TestSpec::Matches m_matches;
|
||||
bool m_unmatchedTestSpecs = false;
|
||||
};
|
||||
|
||||
void applyFilenamesAsTags() {
|
||||
@@ -301,6 +307,11 @@ namespace Catch {
|
||||
TestGroup tests { CATCH_MOVE(reporter), m_config.get() };
|
||||
auto const totals = tests.execute();
|
||||
|
||||
if ( tests.hadUnmatchedTestSpecs()
|
||||
&& m_config->warnAboutUnmatchedTestSpecs() ) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if ( totals.testCases.total() == 0
|
||||
&& !m_config->zeroTestsCountAsSuccess() ) {
|
||||
return 2;
|
||||
|
@@ -26,7 +26,10 @@ namespace Catch {
|
||||
|
||||
struct WarnAbout { enum What {
|
||||
Nothing = 0x00,
|
||||
//! A test case or leaf section did not run any assertions
|
||||
NoAssertions = 0x01,
|
||||
//! A command line test spec matched no test cases
|
||||
UnmatchedTestSpec = 0x02,
|
||||
}; };
|
||||
|
||||
enum class ShowDurations {
|
||||
@@ -63,6 +66,7 @@ namespace Catch {
|
||||
virtual bool includeSuccessfulResults() const = 0;
|
||||
virtual bool shouldDebugBreak() const = 0;
|
||||
virtual bool warnAboutMissingAssertions() const = 0;
|
||||
virtual bool warnAboutUnmatchedTestSpecs() const = 0;
|
||||
virtual bool zeroTestsCountAsSuccess() const = 0;
|
||||
virtual int abortAfter() const = 0;
|
||||
virtual bool showInvisibles() const = 0;
|
||||
|
@@ -27,6 +27,9 @@ namespace Catch {
|
||||
if ( warning == "NoAssertions" ) {
|
||||
config.warnings = WarnAbout::NoAssertions;
|
||||
return ParserResult::ok( ParseResultType::Matched );
|
||||
} else if ( warning == "UnmatchedTestSpec" ) {
|
||||
config.warnings = WarnAbout::UnmatchedTestSpec;
|
||||
return ParserResult::ok( ParseResultType::Matched );
|
||||
}
|
||||
|
||||
return ParserResult ::runtimeError(
|
||||
|
Reference in New Issue
Block a user