mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-17 03:02:24 +01:00
Added signal handling to the updated Catch (fetched from latest upstream)
This commit is contained in:
parent
66d641af64
commit
0b394ba318
@ -1,6 +1,6 @@
|
|||||||
![catch logo](catch-logo-small.png)
|
![catch logo](catch-logo-small.png)
|
||||||
|
|
||||||
*v1.0 build 19 (master branch)*
|
*v1.0 build 23 (master branch)*
|
||||||
|
|
||||||
Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch)
|
Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.png)](https://travis-ci.org/philsquared/Catch)
|
||||||
|
|
||||||
|
@ -10,8 +10,82 @@
|
|||||||
|
|
||||||
#ifndef __OBJC__
|
#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
|
// Standard C/C++ main entry point
|
||||||
int main (int argc, char * const argv[]) {
|
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 );
|
return Catch::Session().run( argc, argv );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
// These numbers are maintained by a script
|
// 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
|
#endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* CATCH v1.0 build 19 (master branch)
|
* CATCH v1.0 build 23 (master branch)
|
||||||
* Generated: 2013-12-14 23:16:21.805565
|
* Generated: 2013-12-17 13:44:13.801508
|
||||||
* ----------------------------------------------------------
|
* ----------------------------------------------------------
|
||||||
* This file has been merged from multiple headers. Please don't edit it directly
|
* This file has been merged from multiple headers. Please don't edit it directly
|
||||||
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||||
@ -6166,7 +6166,7 @@ namespace Catch {
|
|||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
// These numbers are maintained by a script
|
// These numbers are maintained by a script
|
||||||
Version libraryVersion( 1, 0, 19, "master" );
|
Version libraryVersion( 1, 0, 23, "master" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// #included from: catch_text.hpp
|
// #included from: catch_text.hpp
|
||||||
@ -7904,8 +7904,82 @@ namespace Catch {
|
|||||||
|
|
||||||
#ifndef __OBJC__
|
#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
|
// Standard C/C++ main entry point
|
||||||
int main (int argc, char * const argv[]) {
|
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 );
|
return Catch::Session().run( argc, argv );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user