Example unittests?

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Oct 17 05:23:19 UTC 2022


On Monday, 17 October 2022 at 03:07:04 UTC, WebFreak001 wrote:
> 3. Add explicit example blocks (e.g. `@example unittest { ... 
> }`) - this would require a `example` symbol to be defined 
> somewhere though, or a special case in the compiler, like with 
> `nogc` and `live` (also some kind of standard UDA library might 
> make in general, for things like D-Scanner as well)

It's funny you should mention this. I just had the thought 
yesterday that we don't really need the `///` documented unittest 
feature anymore (except for backwards compatibility).

IIRC, when I implemented this feature in the compiler it predated 
UDAs.

Nowadays we could instead define some UDAs in Druntime that the 
compiler could pick up. For example `@ddoc`. I'd probably define 
two versions:
- `@ddoc` that associates the unittest with the previous symbol 
declaration
- `@ddoc!symbol`, allowing users to put the documented unittest 
anywhere in the code, rather than being forced to make it the 
very first unittest following a symbol name.


More information about the Digitalmars-d mailing list