Ah, simple solution to unittests inside templates
ZombineDev via Digitalmars-d
digitalmars-d at puremagic.com
Sun Sep 18 04:10:22 PDT 2016
On Saturday, 17 September 2016 at 17:22:52 UTC, Andrei
Alexandrescu wrote:
> Recall the discussion a few days ago about unittests inside
> templates being instantiated with the template. Often that's
> desirable, but sometimes not - for example when you want to
> generate nice ddoc unittests and avoid bloating. For those
> cases, here's a simple solution that I don't think has been
> mentioned:
>
> /** Awesome struct */
> struct Awesome(T)
> {
> /** Awesome function. */
> void awesome() {}
>
> ///
> static if (is(T == int)) unittest
> {
> Awesome awesome;
> awesome.awesome;
> }
> }
>
> The unittest documentation is nicely generated. The unittest
> code itself is only generated for one instantiation.
>
>
> Andrei
This solution is used extensively by ndslice [1] and I agree that
it's quite flexible.
[1]
http://forum.dlang.org/post/mailman.166.1472923003.2965.digitalmars-d@puremagic.com#post-psrgjdlvsiukkuhrekoo:40forum.dlang.org
More information about the Digitalmars-d
mailing list