snitch-org / snitch

Lightweight C++20 testing framework.
Boost Software License 1.0
267 stars 10 forks source link

Query whether snitch is expecting a throw #153

Open vid512 opened 10 months ago

vid512 commented 10 months ago

Is it possible to query Snitch whether it currectly expects an exception being thrown? If yes, how?

I would like to make my exception class break into debugger on each throw, when running unit tests in debugger, and exception is not expected by Snitch (eg. I am not inside any _THROWS macro).

I mean something like this (on Windows/MSVC):

MyException::MyException() 
{
#ifdef UNITTESTS
  if (!snitch::expecting_throw() && DebuggerPresent())
    __debugbreak();
#endif
}

I realize this is not really a robust solution (exception can be caused and then consumed by different component), but still it would be a nice quality-of-life improvement in my current situation.

cschreib commented 10 months ago

Hi there! It is not currently possible, no. Supporting this would not require a lot of code changes, but changes nonetheless. It seems to me more of a niche use case, and perhaps not worth the extra complexity. But others may think otherwise?