Postmortem: Template unittests are bad & you shouldn't catch Error

Jacob Carlborg doob at me.com
Fri Oct 23 09:10:02 UTC 2020


On Thursday, 22 October 2020 at 16:30:57 UTC, H. S. Teoh wrote:

> It's a different story altogether if druntime uses catching of 
> Errors as a low-level mechanism to implement certain language 
> semantics.  I know contracts in a class hierarchy are 
> implemented that way for certain reasons, for example.  But 
> that's stuff under the hood, that should not be done in user 
> code, ever.

And who would you then implement a new unit test runner without 
catching `AssertError`? Make it even worse than the built-in one 
and abort the whole program after a single failed test?

The program is still in a defined state when an assertion inside 
a `unittest` block fails because the assertion is not assumed to 
hold [1].

[1] https://dlang.org/spec/unittest.html

--
/Jacob Carlborg


More information about the Digitalmars-d mailing list