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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed May 13 11:16:35 PDT 2015


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

Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com

--- Comment #9 from Steven Schveighoffer <schveiguy at yahoo.com> ---
(In reply to Walter Bright from comment #7)
> 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.

This is, inconvenient, if not downright horrid. Putting a unit test far away
from the code it tests makes for some very difficult reading. It would be much
more palatable if there was a way to say inside the tmeplate "here's a unit
test, but it's not part of the template". 

But I can't think of any good reason why unit tests should be compiled when
importing. If you want to build the unit tests, build the module that contains
them. The author wrote the unit tests to run when he built that module, not
when someone else imported them. They probably aren't meant for other
consumption.

All that being said, putting unit tests outside the template is a valid
workaround, even if it sucks.

--


More information about the Digitalmars-d-bugs mailing list