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;

The unittest documentation is nicely generated. The unittest code itself is only generated for one instantiation.


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.digitalmar...@puremagic.com#post-psrgjdlvsiukkuhrekoo:40forum.dlang.org

Reply via email to