-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can catch support checking for abort? #553
Comments
Installing a
Which means, that there'd need to be a separate (static) environment for this kinda thing, which drops multithreading. |
It seems like it may not be legal to return from a signal handler. This is probably not do-able. |
You could always write a custom assert macro: #ifdef DEBUG
class AssertionFailure : public std::runtime_error {}
inline void assert_impl(bool cond, std::string expr, std::string file, std::string func, int line) {
if (!c) {
std::stringstream ss;
ss << "assertion " << expr << " in " << file << ':' << line << " (" << func << ") failed";
throw AssertionError(ss.str());
}
}
#define assert(x) assert_impl((x), #x, __FILE__, __func__, __LINE__)
#else
#define assert(x) (void)0
#endif |
That's a good idea, but the code I'm testing is in C. |
Returning from the handler is legal for <see your local compiler's documentation> signals. |
From SO, it seems like the approach |
Sounds expensive as fuck, though. |
Agreed. I wouldn't mind the performance cost if it let me specify individual use cases where aborts should occur. It's not a cost anyone would need to pay for unless they chose to check for aborts. It doesn't seem like returning from a signal handler, and still having all of the program state defined, is plausible. Currently, I'm making a ton of binaries, and having a bash script check their exit status. It's messy/hacky, but works fine. Implementing a similar thing into the framework(through forking) is just as bad, but at least I could specify all my use cases in the same file, and run them from the same binary. |
If I read the cppreference correctly, it's only UB for some cases, and On 11/12/2015 18:31, Trevor Hickey wrote:
|
I can't find any documentation that says handling |
I'm going to try and fork a process as part of my unit test case, and then compare the exit code using That won't require any changes to the Catch framework. |
From cppreference on |
our signal handler
As far as I can tell, |
And |
Ok cool. I was looking at the value of I guess that doesn't mean the same thing as not being standard though. |
A few observations:
HTH |
This is my current integration:
It's used like so:
This is sufficient for my use cases.
One of the new problems this gives me, is that assert prints to the terminal, and the signal handler by Catch prints that the unit test failed. This results in me having to use Here is a terminal dump to better illustrate the problem:
|
I've disabled output on the forked process, and I'm pretty satisfied with how this is working. full program example:
console output:
I don't expect any of this to be integrated, but I wanted to show the linux work-around that has been working well for me. Hopefully it will help anyone else who wants to check for aborts on linux. I'm not sure about any global state that may get changed from the forked process, or how it would affect other test cases. I have not run into any problems myself testing our C code this way. |
IIRC |
In that case, I'll add:
|
Or redirect it to a |
good point. |
Since this will not be added to Catch Classic, but might be added to Catch 2 at some point, I opened #853 instead. |
Our codebase is using assertions to check for preconditions and post conditions.
Example:
When we call
Do_Computation(0)
in debug mode, the program aborts.I see that Catch supports
CHECK_THROWS
, but does it supportCHECK_ABORT
?Would implementing that even be possible?
I guess you could write a signal handler, but I'm not sure if you could recover from it.
The text was updated successfully, but these errors were encountered: