You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure what machinery is in Catch2 dedicated to handle this, but here's how I've handled it in my own project which uses Catch2 (where the code calling exit is actually a C library).
Often exit is a weak symbol, so can be redefined by the calling code (the tester). You could redefine it to throw a specific C++ exception which you can then recognise as the result of an attempted exit. I think the result is nice and idiomatic.
Let's say there's some function f(void) which invokes exit. Your test code can be
E.g.
Note that the code providing f, when intending to call exit, will not expect the process to stay alive (even though control flow will be 'yanked' back to Catch) and so may be in an internally invalid state. Hence subsequent use of f or other functions may have unexpected behaviour.
Hello everyone,
as far as I know, there's no built in assertion macro to check for an
exit
call using Catch2.What's an approachable way to test for an
exit()
?Thanks in advance!
The text was updated successfully, but these errors were encountered: