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

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Oct 24 04:28:57 UTC 2020


On Thursday, 22 October 2020 at 16:34:14 UTC, Adam D. Ruppe wrote:
> and encourages ugly, unusable examples because they are run as 
> automatic tests instead of you know, actually being written as 
> examples.

Sorry but that's not a problem with documented unittests. They 
should be written like so:

///
struct S { }

///
unittest
{
     // show example of *simple* usage that is generated in the 
documentation
}

// NOT generated in the documentation, and can be heavy-duty and 
have contexts
unittest
{
}

The responsibility of writing good documentation unittests lies 
solely on the person introducing the new functionality (and the 
reviewers!). If people write terrible examples in `///` unittests 
then they write terrible documentation regardless. You can add 
the requirement for  the need to import into the module if you 
want (and this is a good idea, maybe we could abuse static for 
this), but in the end those same people will still abuse the 
feature. They'll add the necessary import, and still write 
terrible documentation examples. Can't fix bad documentation 
unless there's someone willing to review and point it out.


More information about the Digitalmars-d mailing list