selectively running unittest functions

Dicebot public at dicebot.lv
Fri Oct 25 07:14:38 PDT 2013


This will work starting with 2.064:

module a;

import std.stdio;

struct ID
{
     string data;
}

@ID("one")
unittest
{
     writeln("1");
}

@ID("two")
unittest
{
     writeln("2");
}

void main()
{
     import std.typetuple;
     alias tests = TypeTuple!( __traits(getUnitTests, a) );

     foreach (test; tests)
     {
         foreach (uda; __traits(getAttributes, test))
         {
             static if (is(typeof(uda) == ID))
             {
                 if (uda == ID("two"))
                     test();
             }
         }
     }
}

It will print stuff twice though because I didn't suppress native 
unittest runner. Didn't actually dwell deep into runtime hooks so 
don't know what is best way to do it (maybe we need one more 
enhancement for it)


More information about the Digitalmars-d-learn mailing list