Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorMartin Hořeňovský2021-12-18 19:59:23 +0100
committerMartin Hořeňovský2021-12-18 20:50:03 +0100
commit840acedf62b2dabb98bf4ab372a7582131d6b530 (patch)
tree2246182676b827884962a1a62ed216a14de0d992 /src
parent9f2dca5384a6a8f9f37a7dc2d998cac616545592 (diff)
downloadcatch3-840acedf62b2dabb98bf4ab372a7582131d6b530.tar.gz
Implement warning for unmatched test specs
Diffstat (limited to 'src')
-rw-r--r--src/catch2/catch_config.cpp3
-rw-r--r--src/catch2/catch_config.hpp1
-rw-r--r--src/catch2/catch_session.cpp15
-rw-r--r--src/catch2/interfaces/catch_interfaces_config.hpp4
-rw-r--r--src/catch2/internal/catch_commandline.cpp3
5 files changed, 24 insertions, 2 deletions
diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp
index 33951dbd..da9457da 100644
--- a/src/catch2/catch_config.cpp
+++ b/src/catch2/catch_config.cpp
@@ -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; }
diff --git a/src/catch2/catch_config.hpp b/src/catch2/catch_config.hpp
index 8f249c09..2b881f6b 100644
--- a/src/catch2/catch_config.hpp
+++ b/src/catch2/catch_config.hpp
@@ -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;
diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp
index 647dcfa3..38111fe8 100644
--- a/src/catch2/catch_session.cpp
+++ b/src/catch2/catch_session.cpp
@@ -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;
diff --git a/src/catch2/interfaces/catch_interfaces_config.hpp b/src/catch2/interfaces/catch_interfaces_config.hpp
index 8d93c964..b8da0df0 100644
--- a/src/catch2/interfaces/catch_interfaces_config.hpp
+++ b/src/catch2/interfaces/catch_interfaces_config.hpp
@@ -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;
diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp
index 8576e808..71550945 100644
--- a/src/catch2/internal/catch_commandline.cpp
+++ b/src/catch2/internal/catch_commandline.cpp
@@ -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(