[Issue 13454] Unit tests should be compiled in a module, where they are declared

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat May 9 19:32:30 PDT 2015


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com

--- Comment #7 from Walter Bright <bugzilla at 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");
    }

--


More information about the Digitalmars-d-bugs mailing list