mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-17 18:35:40 +02:00
Added signal handling to the updated Catch (fetched from latest upstream)
This commit is contained in:
@@ -10,8 +10,82 @@
|
||||
|
||||
#ifndef __OBJC__
|
||||
|
||||
#if !defined(DO_NOT_USE_SIGNALS)
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
void add_test_info(std::stringstream& s) {
|
||||
// add info about current test
|
||||
Catch::IContext& context = Catch::getCurrentContext();
|
||||
Catch::IResultCapture& result = context.getResultCapture();
|
||||
const Catch::AssertionResult* ar = result.getLastResult();
|
||||
if(ar) {
|
||||
Catch::SourceLineInfo src = ar->getSourceInfo();
|
||||
s << "\n\nwhile executing test: \"" << result.getCurrentTestName() << "\"\n";
|
||||
s << "\n(last successful check was: \"" << ar->getExpression() << "\"\n";
|
||||
s << " in: " << src.file << ", ";
|
||||
s << "line: " << static_cast<int>(src.line) << ")\n\n";
|
||||
}
|
||||
Catch::cleanUp();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef DO_NOT_USE_SIGNALS
|
||||
static bool testing_finished = false;
|
||||
#include <signal.h>
|
||||
|
||||
// handler for signals
|
||||
void handle_signal(int sig) {
|
||||
std::stringstream s;
|
||||
s << "\n\n=================\n\n";
|
||||
if(testing_finished)
|
||||
{
|
||||
std::cerr << s.str() << "received signal " << std::dec << sig;
|
||||
std::cerr << " after testing was finished\n";
|
||||
exit(0);
|
||||
}
|
||||
|
||||
switch (sig) {
|
||||
case SIGINT:
|
||||
s << "Interactive attention";
|
||||
break;
|
||||
case SIGILL:
|
||||
s << "Illegal instruction";
|
||||
break;
|
||||
case SIGFPE:
|
||||
s << "Floating point error";
|
||||
break;
|
||||
case SIGSEGV:
|
||||
s << "Segmentation violation";
|
||||
break;
|
||||
case SIGTERM:
|
||||
s << "Termination request";
|
||||
break;
|
||||
case SIGABRT:
|
||||
s << "Abnormal termination (abort)";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
add_test_info(s);
|
||||
std::cout << s.str();
|
||||
|
||||
exit(-sig);
|
||||
}
|
||||
#endif /*!DO_NOT_USE_SIGNALS*/
|
||||
|
||||
// Standard C/C++ main entry point
|
||||
int main (int argc, char * const argv[]) {
|
||||
#ifndef DO_NOT_USE_SIGNALS
|
||||
testing_finished = false;
|
||||
signal(SIGSEGV, handle_signal);
|
||||
signal(SIGABRT, handle_signal);
|
||||
signal(SIGTERM, handle_signal);
|
||||
signal(SIGINT, handle_signal);
|
||||
signal(SIGILL, handle_signal);
|
||||
signal(SIGFPE, handle_signal);
|
||||
#endif /*!DO_NOT_USE_SIGNALS*/
|
||||
|
||||
return Catch::Session().run( argc, argv );
|
||||
}
|
||||
|
||||
|
@@ -13,7 +13,7 @@
|
||||
namespace Catch {
|
||||
|
||||
// These numbers are maintained by a script
|
||||
Version libraryVersion( 1, 0, 19, "master" );
|
||||
Version libraryVersion( 1, 0, 23, "master" );
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
|
||||
|
Reference in New Issue
Block a user