On Saturday, 3 September 2016 at 15:54:31 UTC, Jonathan M Davis
wrote:
On Saturday, September 03, 2016 15:06:33 Andrei Alexandrescu
via Digitalmars-d wrote:
On 9/3/16 5:36 AM, Manu via Digitalmars-d wrote:
> This document: https://wiki.dlang.org/Contributing_to_Phobos
>
> States: "Avoid unittest in templates (it will generate a new
> unittest for each instance) - put your tests outside"
Actually that's a good thing, sometimes you do want to run a
unittest for each instantiation.
Sometimes, sure. But usually not.
> Sounds reasonable, but then I realised that most of my unit
> tests are documenting unittests... this recommendation is in
> conflict with the documentation standards... who wins?
Just version it only for the documentation.
Then the tests won't be run unless your documentation build is
also your unittest build, and they frequently can't be the same
- e.g. when something differs between operating systems, and
you have a separate D_Ddoc or StdDdoc block so that you can
have proper documentation without requiring that the
documentation be built on all systems and potentially being
able to document what exists on each system. For instance, the
supported clock types vary quite a bit across operating
systems, so the core.time.ClockType enum has different values
on different systems and version(CoreDdoc) is used so that the
documentation can list them all and list the consistently
across systems.
You could add some sort of version identifier that's specific
to your build that you use for your unittest builds (similar to
how Phobos has StdDdoc separate from D_Ddoc), but even if you
do that, you still have the problem of the non-generic unit
tests within a template being compiled into every instantiation
of the template that's part of your unittest build, and all of
those tests will get run, increasing both the build times and
the time it takes to run the unit tests.
- Jonathan M Davis
You can just enable the unittests for a single instance that you
know for sure that it will be used. For example:
1)
https://github.com/dlang/phobos/blob/v2.071.2-b3/std/experimental/ndslice/slice.d#L808
2)
https://github.com/dlang/phobos/blob/v2.071.2-b3/std/experimental/ndslice/slice.d#L947