[Issue 13291] unittest should be allowed inside template functions
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Sep 15 18:20:31 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13291
Steven Schveighoffer <schveiguy at yahoo.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |schveiguy at yahoo.com
--- Comment #7 from Steven Schveighoffer <schveiguy at yahoo.com> ---
Using the template instantiation to cover all unit tests is both a boon and a
curse.
I use it in dcollections to great effect, and have found several D/phobos bugs
just with that use.
However, often you do NOT want to instantiate unit tests for ALL invocations.
Consider this:
T max(T)(T x, T y)
A test for max might look like:
unittest
{
T t1 = 0, t2 = 1, t3 = 2;
assert(max(t1, t2) == t2);
assert(max(t2, t1) == 1);
assert(max(t1, t3) == t3);
assert(max(t3, t2) == 2);
// etc...
}
But what if T is string?
Now, you have to create a different unit test because the literals are
different. Unit tests require both input and results, and the input isn't
always easy to determine for any generic type.
--
More information about the Digitalmars-d-bugs
mailing list