34
34
namespace Catch {
35
35
36
36
namespace {
37
- const int MaxExitCode = 255 ;
37
+ static constexpr int TestFailureExitCode = 42 ;
38
+ static constexpr int UnspecifiedErrorExitCode = 1 ;
39
+ static constexpr int AllTestsSkippedExitCode = 4 ;
40
+ static constexpr int NoTestsRunExitCode = 2 ;
41
+ static constexpr int UnmatchedTestSpecExitCode = 3 ;
42
+ static constexpr int InvalidTestSpecExitCode = 5 ;
43
+
38
44
39
45
IEventListenerPtr createReporter (std::string const & reporterName, ReporterConfig&& config) {
40
46
auto reporter = Catch::getRegistryHub ().getReporterRegistry ().create (reporterName, CATCH_MOVE (config));
@@ -198,8 +204,7 @@ namespace Catch {
198
204
}
199
205
200
206
int Session::applyCommandLine ( int argc, char const * const * argv ) {
201
- if ( m_startupExceptions )
202
- return 1 ;
207
+ if ( m_startupExceptions ) { return UnspecifiedErrorExitCode; }
203
208
204
209
auto result = m_cli.parse ( Clara::Args ( argc, argv ) );
205
210
@@ -215,7 +220,7 @@ namespace Catch {
215
220
<< TextFlow::Column ( result.errorMessage () ).indent ( 2 )
216
221
<< " \n\n " ;
217
222
errStream->stream () << " Run with -? for usage\n\n " << std::flush;
218
- return MaxExitCode ;
223
+ return UnspecifiedErrorExitCode ;
219
224
}
220
225
221
226
if ( m_configData.showHelp )
@@ -285,8 +290,7 @@ namespace Catch {
285
290
}
286
291
287
292
int Session::runInternal () {
288
- if ( m_startupExceptions )
289
- return 1 ;
293
+ if ( m_startupExceptions ) { return UnspecifiedErrorExitCode; }
290
294
291
295
if (m_configData.showHelp || m_configData.libIdentify ) {
292
296
return 0 ;
@@ -297,7 +301,7 @@ namespace Catch {
297
301
<< " ) must be greater than the shard index ("
298
302
<< m_configData.shardIndex << " )\n "
299
303
<< std::flush;
300
- return 1 ;
304
+ return UnspecifiedErrorExitCode ;
301
305
}
302
306
303
307
CATCH_TRY {
@@ -320,7 +324,7 @@ namespace Catch {
320
324
for ( auto const & spec : invalidSpecs ) {
321
325
reporter->reportInvalidTestSpec ( spec );
322
326
}
323
- return 1 ;
327
+ return InvalidTestSpecExitCode ;
324
328
}
325
329
326
330
@@ -334,29 +338,29 @@ namespace Catch {
334
338
335
339
if ( tests.hadUnmatchedTestSpecs ()
336
340
&& m_config->warnAboutUnmatchedTestSpecs () ) {
337
- return 3 ;
341
+ // UnmatchedTestSpecExitCode
342
+ return UnmatchedTestSpecExitCode;
338
343
}
339
344
340
345
if ( totals.testCases .total () == 0
341
346
&& !m_config->zeroTestsCountAsSuccess () ) {
342
- return 2 ;
347
+ return NoTestsRunExitCode ;
343
348
}
344
349
345
350
if ( totals.testCases .total () > 0 &&
346
351
totals.testCases .total () == totals.testCases .skipped
347
352
&& !m_config->zeroTestsCountAsSuccess () ) {
348
- return 4 ;
353
+ return AllTestsSkippedExitCode ;
349
354
}
350
355
351
- // Note that on unices only the lower 8 bits are usually used, clamping
352
- // the return value to 255 prevents false negative when some multiple
353
- // of 256 tests has failed
354
- return (std::min) (MaxExitCode, static_cast <int >(totals.assertions .failed ));
356
+ if ( totals.assertions .failed ) { return TestFailureExitCode; }
357
+ return 0 ;
358
+
355
359
}
356
360
#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
357
361
catch ( std::exception & ex ) {
358
362
Catch::cerr () << ex.what () << ' \n ' << std::flush;
359
- return MaxExitCode ;
363
+ return UnspecifiedErrorExitCode ;
360
364
}
361
365
#endif
362
366
}
0 commit comments