On 2012-03-12 15:08, Steven Schveighoffer wrote:
I contended that unit test asserts should result in a hook that by
default kills the program, but could be hooked into a unit testing
handler. But the consensus was just to switch back to the original
behavior (all asserts kill the program). If you look through the phobos
or druntime mailing list archives you might find the relevant
conversations. It may even be so old that the archives don't have it (it
was on a private mailing list on Andrei's server for a time).

My thoughts on assert/unit test:

1. AssertError (and any other Error) should not be caught by normal user
code. Ever. It should only be caught by the runtime. However, the
handler in the runtime could provide a hook specific to the
OS/application and whether it is running unit tests. Obviously the hook
would have to be set up before main runs, so that is an issue, but you
may just need to alter the runtime in that case.

I had a look through the source code of druntime and found "onAssertError". I don't know if it's used or not but sounds exactly like the function I need. But unfortunately the function to set the assert handler is deprecated.

http://dlang.org/phobos/core_exception.html#onAssertError
http://dlang.org/phobos/core_exception.html#setAssertHandler

--
/Jacob Carlborg

Reply via email to