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-13 15:15:23 +0100
committerMartin Hořeňovský2021-12-18 20:50:00 +0100
commit9f2dca5384a6a8f9f37a7dc2d998cac616545592 (patch)
tree181d46f4eb905903e08af58a8a35108f87a24505 /src
parent602e484f027ccdfb59cfde852e20283ad1635f81 (diff)
downloadcatch3-9f2dca5384a6a8f9f37a7dc2d998cac616545592.tar.gz
Exit with non-0 return code if no tests were run
A new flag, `--allow-running-no-tests` was added to override this behaviour if exit code of 0 was desired. This change also made `-w NoTests` obsolete, and so it has been removed.
Diffstat (limited to 'src')
-rw-r--r--src/catch2/catch_config.cpp6
-rw-r--r--src/catch2/catch_config.hpp3
-rw-r--r--src/catch2/catch_session.cpp8
-rw-r--r--src/catch2/interfaces/catch_interfaces_config.hpp3
-rw-r--r--src/catch2/internal/catch_commandline.cpp26
5 files changed, 22 insertions, 24 deletions
diff --git a/src/catch2/catch_config.cpp b/src/catch2/catch_config.cpp
index e2569de9..33951dbd 100644
--- a/src/catch2/catch_config.cpp
+++ b/src/catch2/catch_config.cpp
@@ -67,8 +67,10 @@ namespace Catch {
std::ostream& Config::stream() const { return m_stream->stream(); }
StringRef Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
- bool Config::warnAboutMissingAssertions() const { return !!(m_data.warnings & WarnAbout::NoAssertions); }
- bool Config::warnAboutNoTests() const { return !!(m_data.warnings & WarnAbout::NoTests); }
+ bool Config::warnAboutMissingAssertions() const {
+ return !!( m_data.warnings & WarnAbout::NoAssertions );
+ }
+ bool Config::zeroTestsCountAsSuccess() const { return m_data.allowZeroTests; }
ShowDurations Config::showDurations() const { return m_data.showDurations; }
double Config::minDuration() const { return m_data.minDuration; }
TestRunOrder Config::runOrder() const { return m_data.runOrder; }
diff --git a/src/catch2/catch_config.hpp b/src/catch2/catch_config.hpp
index dbb9bf0e..8f249c09 100644
--- a/src/catch2/catch_config.hpp
+++ b/src/catch2/catch_config.hpp
@@ -33,6 +33,7 @@ namespace Catch {
bool showInvisibles = false;
bool filenamesAsTags = false;
bool libIdentify = false;
+ bool allowZeroTests = false;
int abortAfter = -1;
uint32_t rngSeed = generateRandomSeed(GenerateFrom::Default);
@@ -97,7 +98,7 @@ namespace Catch {
StringRef name() const override;
bool includeSuccessfulResults() const override;
bool warnAboutMissingAssertions() const override;
- bool warnAboutNoTests() const override;
+ bool zeroTestsCountAsSuccess() const override;
ShowDurations showDurations() const override;
double minDuration() const override;
TestRunOrder runOrder() const override;
diff --git a/src/catch2/catch_session.cpp b/src/catch2/catch_session.cpp
index ff5e4cd8..647dcfa3 100644
--- a/src/catch2/catch_session.cpp
+++ b/src/catch2/catch_session.cpp
@@ -105,12 +105,10 @@ namespace Catch {
}
private:
- using Tests = std::set<TestCaseHandle const*>;
-
IStreamingReporter* m_reporter;
Config const* m_config;
RunContext m_context;
- Tests m_tests;
+ std::set<TestCaseHandle const*> m_tests;
TestSpec::Matches m_matches;
};
@@ -303,8 +301,10 @@ namespace Catch {
TestGroup tests { CATCH_MOVE(reporter), m_config.get() };
auto const totals = tests.execute();
- if( m_config->warnAboutNoTests() && totals.error == -1 )
+ if ( totals.testCases.total() == 0
+ && !m_config->zeroTestsCountAsSuccess() ) {
return 2;
+ }
// Note that on unices only the lower 8 bits are usually used, clamping
// the return value to 255 prevents false negative when some multiple
diff --git a/src/catch2/interfaces/catch_interfaces_config.hpp b/src/catch2/interfaces/catch_interfaces_config.hpp
index 4f466b22..8d93c964 100644
--- a/src/catch2/interfaces/catch_interfaces_config.hpp
+++ b/src/catch2/interfaces/catch_interfaces_config.hpp
@@ -27,7 +27,6 @@ namespace Catch {
struct WarnAbout { enum What {
Nothing = 0x00,
NoAssertions = 0x01,
- NoTests = 0x02
}; };
enum class ShowDurations {
@@ -64,7 +63,7 @@ namespace Catch {
virtual bool includeSuccessfulResults() const = 0;
virtual bool shouldDebugBreak() const = 0;
virtual bool warnAboutMissingAssertions() const = 0;
- virtual bool warnAboutNoTests() const = 0;
+ virtual bool zeroTestsCountAsSuccess() const = 0;
virtual int abortAfter() const = 0;
virtual bool showInvisibles() const = 0;
virtual ShowDurations showDurations() const = 0;
diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp
index 02056da5..8576e808 100644
--- a/src/catch2/internal/catch_commandline.cpp
+++ b/src/catch2/internal/catch_commandline.cpp
@@ -24,21 +24,14 @@ namespace Catch {
using namespace Clara;
auto const setWarning = [&]( std::string const& warning ) {
- auto warningSet = [&]() {
- if( warning == "NoAssertions" )
- return WarnAbout::NoAssertions;
-
- if ( warning == "NoTests" )
- return WarnAbout::NoTests;
-
- return WarnAbout::Nothing;
- }();
-
- if (warningSet == WarnAbout::Nothing)
- return ParserResult::runtimeError( "Unrecognised warning: '" + warning + '\'' );
- config.warnings = static_cast<WarnAbout::What>( config.warnings | warningSet );
+ if ( warning == "NoAssertions" ) {
+ config.warnings = WarnAbout::NoAssertions;
return ParserResult::ok( ParseResultType::Matched );
- };
+ }
+
+ return ParserResult ::runtimeError(
+ "Unrecognised warning option: '" + warning + '\'' );
+ };
auto const loadTestNamesFromFile = [&]( std::string const& filename ) {
std::ifstream f( filename.c_str() );
if( !f.is_open() )
@@ -280,7 +273,10 @@ namespace Catch {
( "split the tests to execute into this many groups" )
| Opt( setShardIndex, "shard index" )
["--shard-index"]
- ( "index of the group of tests to execute (see --shard-count)" )
+ ( "index of the group of tests to execute (see --shard-count)" ) |
+ Opt( config.allowZeroTests )
+ ["--allow-running-no-tests"]
+ ( "Treat 'No tests run' as a success" )
| Arg( config.testsOrTags, "test name|pattern|tags" )
( "which test or tests to use" );