Low level unit test library in druntime

ZombineDev via Digitalmars-d digitalmars-d at puremagic.com
Thu Sep 1 09:17:42 PDT 2016


On Thursday, 1 September 2016 at 12:06:21 UTC, Dicebot wrote:
> On 08/31/2016 01:01 PM, Atila Neves wrote:
>> And never mind that any such low level library would suffer 
>> from the same problem unit-threaded did until dub fixed it: D 
>> can't reflect on packages so a program must be written that 
>> explicitly lists all modules that need to be looked at.
>
> I don't even think fixing package reflection would truly help 
> here because there exist legit D projects that don't 
> transitively import all modules from `main` and recursive 
> compile-time visiting of all symbols would miss them.
>
>> [snip]

Not a problem, since you can do things like this:

// Prints:
// tuple("CSVException", "IncompleteCellException",
// "HeaderMismatchException", "Malformed", "JSONFloatLiteral",
// "JSONOptions", "JSON_TYPE", "JSONValue", "JSONException")
pragma (msg, ModuleTypes!("std.csv", "std.json"));


/**
  * Params:
  *    Takes a sequence of module name strings and returns a 
sequence of all types names
  *    defined in those modules
  */
template ModuleTypes(ModuleNames...)
{
     import std.meta : staticMap, aliasSeqOf;

     alias ModuleTypes = aliasSeqOf!(getTypes());

     string[] getTypes()
     {
         import std.meta : AliasSeq;

         string[] result;

         foreach (fqModuleName; ModuleNames)
         {
             mixin ("import " ~ fqModuleName ~ ";");

             foreach (member; __traits(allMembers, 
mixin(fqModuleName)))
             {
                 static if (mixin("is(" ~ member ~ ")"))
                 {
                     result ~= member;
                 }
             }
         }

         return result;
     }
}




More information about the Digitalmars-d mailing list