https://issues.dlang.org/show_bug.cgi?id=13454

Walter Bright <bugzi...@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzi...@digitalmars.com

--- Comment #7 from Walter Bright <bugzi...@digitalmars.com> ---
When designing unit tests for templates, a decision must be made:

1. are the unit tests to be run for specified instantiations only?
2. are the unit tests to be run for all instantiations?

For (1), put them outside the template body. For (2), put the unit tests inside
the template body. In the example code, the unit test code is in both places
and both are expected to exist, and as you discovered, such does not work.

The solution is either put all the unit test code outside the template for
option (1), or all inside for option (2). I almost always go with (1) for my
template code, and it works fine.

> It's questionable that duplicating tests for each instantiation of a template 
> is intended.

Right, that's the (1) or (2) decision above, and only the programmer can make
that decision.

> too many issues with random imports

-------- bad practice ----------
    version (unittest) import std.stdio;
    unittest { writeln("hello"); }

-------- better practice ---------
    unittest {
        import std.stdio;
        writeln("hello");
    }

--

Reply via email to