diff --git a/docs/own-main.md b/docs/own-main.md index 91a79b26..8ab0077e 100644 --- a/docs/own-main.md +++ b/docs/own-main.md @@ -23,7 +23,7 @@ int main( int argc, char* argv[] ) { // global clean-up... - return ( result < 0xff ? result : 0xff ); + return result; } ``` @@ -66,10 +66,10 @@ int main( int argc, char* argv[] ) // only do this if you know you need to int numFailed = session.run(); - // Note that on unices only the lower 8 bits are usually used, clamping - // the return value to 255 prevents false negative when some multiple - // of 256 tests has failed - return ( numFailed < 0xff ? numFailed : 0xff ); + // numFailed is clamped to 255 as some unices only use the lower 8 bits. + // This clamping has already been applied, so just return it here + // You can also do any post run clean-up here + return numFailed; } ``` diff --git a/include/catch_session.hpp b/include/catch_session.hpp index 09ca85f1..ffd87c9d 100644 --- a/include/catch_session.hpp +++ b/include/catch_session.hpp @@ -96,6 +96,7 @@ namespace Catch { } class Session : NonCopyable { + static const int MaxExitCode; public: Session() { @@ -113,7 +114,7 @@ namespace Catch { Catch::cout() << "\nCatch v" << libraryVersion() << "\n"; Catch::cout() << m_cli << std::endl; - Catch::cout() << "For more detail usage please see the project docs\n" << std::endl; + Catch::cout() << "For more detailed usage please see the project docs\n" << std::endl; } int applyCommandLine( int argc, char* argv[] ) { @@ -127,7 +128,7 @@ namespace Catch { << "\n\n"; } Catch::cerr() << m_cli << std::endl; - return (std::numeric_limits::max)(); + return MaxExitCode; } if( m_configData.showHelp ) @@ -174,9 +175,7 @@ namespace Catch { WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL ); } - int returnCode = applyCommandLine( argc, utf8Argv ); - if( returnCode == 0 ) - returnCode = run(); + int returnCode = run( argc, utf8Argv ); for ( int i = 0; i < argc; ++i ) delete [] utf8Argv[ i ]; @@ -204,11 +203,11 @@ namespace Catch { if( Option listed = list( config() ) ) return static_cast( *listed ); - return static_cast( runTests( m_config ).assertions.failed ); + return (std::min)( MaxExitCode, static_cast( runTests( m_config ).assertions.failed ) ); } catch( std::exception& ex ) { Catch::cerr() << ex.what() << std::endl; - return (std::numeric_limits::max)(); + return MaxExitCode; } } @@ -232,6 +231,8 @@ namespace Catch { std::shared_ptr m_config; }; + const int Session::MaxExitCode = 255; + } // end namespace Catch #endif // TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED diff --git a/include/internal/catch_default_main.hpp b/include/internal/catch_default_main.hpp index e9f466c0..9b7c2890 100644 --- a/include/internal/catch_default_main.hpp +++ b/include/internal/catch_default_main.hpp @@ -18,8 +18,7 @@ extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) { int main (int argc, char * argv[]) { #endif - int result = Catch::Session().run( argc, argv ); - return ( result < 0xff ? result : 0xff ); + return Catch::Session().run( argc, argv ); } #else // __OBJC__ @@ -37,7 +36,7 @@ int main (int argc, char * const argv[]) { [pool drain]; #endif - return ( result < 0xff ? result : 0xff ); + return result; } #endif // __OBJC__