mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-19 11:56:11 +01:00
Clamp exit code internally, so it doesn’t have to be done in every main() implies
This commit is contained in:
parent
fae0fa4ec1
commit
4c1880b35f
@ -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;
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -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<int>::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<std::size_t> listed = list( config() ) )
|
||||
return static_cast<int>( *listed );
|
||||
|
||||
return static_cast<int>( runTests( m_config ).assertions.failed );
|
||||
return (std::min)( MaxExitCode, static_cast<int>( runTests( m_config ).assertions.failed ) );
|
||||
}
|
||||
catch( std::exception& ex ) {
|
||||
Catch::cerr() << ex.what() << std::endl;
|
||||
return (std::numeric_limits<int>::max)();
|
||||
return MaxExitCode;
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,6 +231,8 @@ namespace Catch {
|
||||
std::shared_ptr<Config> m_config;
|
||||
};
|
||||
|
||||
const int Session::MaxExitCode = 255;
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
|
||||
|
@ -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__
|
||||
|
Loading…
Reference in New Issue
Block a user