mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-03 05:45:39 +02:00
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.
This commit is contained in:
@@ -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; }
|
||||
|
@@ -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;
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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" );
|
||||
|
||||
|
Reference in New Issue
Block a user