On 8/27/13, Dicebot <pub...@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

Helper functions:

And I use the attributes to enable things like (nevermind the ironic
name "simple" :p):

Reply via email to