There must be module with test assertions in Phobos

Nick Treleaven nick at geany.org
Tue Apr 4 18:49:50 UTC 2023


On Tuesday, 4 April 2023 at 12:11:28 UTC, Quirin Schroll wrote:`
>
> Instead of
> ```d
> assertThrows!Exception(expression);
> ```
> one could write
> ```d
> try { expression(); assert(0); } catch (Exception) {}
> ```
> but I see that it is a non-trivial pattern and `assertThrows` 
> just documents clearly what is expected. Even this isn’t that 
> much.

It's actually already in Phobos:
https://dlang.org/phobos/std_exception.html#.assertThrown

> Those functions can provide better error messages, but to be 
> honest, the D compiler’s unittest failure messages should be 
> improved instead.

They have been, with the -checkaction=context switch mentioned in 
this thread.



More information about the Digitalmars-d mailing list