Unit Threaded - a unit testing library for D
Andrej Mitrovic
andrej.mitrovich at gmail.com
Tue Aug 27 11:27:53 PDT 2013
On 8/27/13, Dicebot <public at dicebot.lv> wrote:
> By the way, can we currently in 2.064 attach UDA's to unittest
> blocks?
Yes. E.g.:
-----
alias Seq(T...) = T;
struct RunTest { }
struct SkipTest { }
@RunTest unittest { }
@SkipTest unittest { }
void main()
{
alias Tests = Seq!(__traits(getUnitTests, test));
// http://d.puremagic.com/issues/show_bug.cgi?id=7804 workaround
alias Attrib1 = Seq!(__traits(getAttributes, Tests[0]))[0];
// ditto
alias Attrib2 = Seq!(__traits(getAttributes, Tests[1]))[0];
static assert(is(Attrib1 == RunTest));
static assert(is(Attrib2 == SkipTest));
}
-----
The Seq() nonsense is to avoid running into Issue 7804. Working with
attributes is generally very quirky, I had to define a whole set of
__traits(compiles) versions of templates just in order to be able to
extract various attributes from symbols (an attribute can be a type,
an instance, a template declaration, a template instance, a literal,
etc...). Here's some of the work I've had to do to work with
attributes:
Helper functions:
https://github.com/AndrejMitrovic/minilib/blob/master/src/minilib/core/attributes.d
And I use the attributes to enable things like (nevermind the ironic
name "simple" :p):
https://github.com/AndrejMitrovic/minilib/blob/master/src/minilib/parser/simple_ini/tests.d
More information about the Digitalmars-d-announce
mailing list