On Thursday, 10 March 2016 at 08:09:40 UTC, Jacob Carlborg wrote:
On 2016-03-09 19:01, Atila Neves wrote:
The forum must be sick of hearing from me... :P For those not
in the
know, unit-threaded is an advanced unit testing library for D:
http://code.dlang.org/packages/unit-threaded
The v0.6.3 release had tests parametrized by value; this
v0.6.5 release
brings with it the possibility of parametrizing tests by type,
like so:
@Types!(int, byte)
void testInit(T)() {
assert(T.init == 0);
}
This will run the testInit code twice, once for each type, and
report
them as separate tests:
tests.pass.attributes.testInit.int:
tests.pass.attributes.testInit.byte:
I've literally only written that silly testInit example yet.
But imagine
how easy it'd be to test, say, different input ranges.
I'm thinking of ways of getting the parametrized tests to work
with the
built-in unittest blocks. I assume it'll be hacky. Right now
it's the
only thing that requires non-standard test functions and I'm
trying to
augment the existing unit testing features of D instead of
replacing them.
Do you have a slightly more extended example that shows how
this is used?
No, sorry. I haven't needed it yet. Something like this?
@Types!(int, string)
void testArray(T)() {
import std.container;
auto arr = Array!T();
arr.empty.shouldBeTrue;
arr.insertBack(T.init);
arr.empty.shouldBeFalse;
auto l = arr.length;
l.shouldEqual(1);
}
Atila