www.digitalmars.com         C & C++   DMDScript  

digitalmars.dip.development - Statement Unittest [DRAFT]

reply monkyyy <crazymonkyyy gmail.com> writes:
A module-level unittest statement( uses `()` instead of `{}`) for 
single asserts
, with an optional string message

```d
unittest(1==1);
unittest(1==1,"math broke");
```


https://gist.github.com/crazymonkyyy/2afa7ae1402cd246fb98bdb86dd19605
Oct 15
next sibling parent Paul Backus <snarwin gmail.com> writes:
On Tuesday, 15 October 2024 at 14:37:24 UTC, monkyyy wrote:
 https://gist.github.com/crazymonkyyy/2afa7ae1402cd246fb98bdb86dd19605
For "Prior Work", I'd say the most obvious thing to cite is the shortened syntax for `in`, `out`, and `invariant` contracts: ```d // Short versions in (n > 0); out (ret; ret !is null); invariant (start <= end); // Long versions in { assert(n > 0); } out (ret) { assert(ret !is null); } invariant { assert( start <= end); } ``` Spec links: * [Function contracts][1] * [Struct invariants][2] * [Class invariants][3] [1]: https://dlang.org/spec/function.html#contracts [2]: https://dlang.org/spec/struct.html#Invariant [3]: https://dlang.org/spec/class.html#invariants
Oct 15
prev sibling parent Guillaume Piolat <guillaume.piolat gmail.com> writes:
On Tuesday, 15 October 2024 at 14:37:24 UTC, monkyyy wrote:
 A module-level unittest statement( uses `()` instead of `{}`) 
 for single asserts
 , with an optional string message

 ```d
 unittest(1==1);
 unittest(1==1,"math broke");
 ```


 https://gist.github.com/crazymonkyyy/2afa7ae1402cd246fb98bdb86dd19605
This is a pretty cool idea. unittest being one of the big win of D, why not have more of it.
Oct 17