Statement Unittest [DRAFT]

Quirin Schroll qs.il.paperinik at gmail.com
Sat Jan 18 05:26:11 UTC 2025


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

"Shortened function syntax." isn’t really an example of prior 
work.

"Shortened contract syntax." is.

"On-going debate if it effects future unittest syntax" Does not 
apply in the *Breaking Changes and Deprecations* section.

Here’s the description and grammar changes for your DIP:

````
## Description

The following grammar changes are needed:

```diff
     UnitTest:
         unittest BlockStatement
+       unittest ( AssertArguments ) ;
```

Statement unittests are equivalent to a unittest with a 
*`BlockStatement`* that contains a single statement that is an 
*`AssertExpression`* with the *`AssertArguments`* as given.
In fact, implementations are encouraged to implement statement 
unittests as a lowering,
essentially making <code>unittest(*AssertArguments*);</code> a 
shorthand for <code>unittest{ assert(*AssertArguments*); }</code>.
````

I’m not sure this even requires a DIP.

Maybe I’ll implement this next week.


More information about the dip.development mailing list