Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module opmix.ut;
- struct UT { string tag; }
- mixin template UTInit(string modname) {
- version(UT) {
- import std.traits;
- template unitTestTag(alias f) {
- auto helper() {
- foreach(attr; __traits(getAttributes, f))
- static if(is(attr == UT))
- return attr.tag;
- return "";
- }
- enum string unitTestTag = helper;
- }
- static this() {
- import std.typecons;
- import std.typetuple;
- import std.string;
- import std.algorithm;
- import std.traits;
- import std.stdio;
- mixin("alias mod = " ~ modname ~ ";");
- alias members = TypeTuple!(__traits(allMembers, mod));
- foreach( member ; members ) {
- writeln("Member: ", member);
- }
- alias tests = TypeTuple!(__traits(getUnitTests, mod));
- /*
- foreach( test; tests ) {
- writeln("examining ", name);
- mixin ("alias symbol = " ~ name ~ ";");
- testFunctions[fullyQualifiedName!mod ~ "GOO"] = &symbol;
- }
- */
- }
- }
- }
- version(UT) {
- import std.stdio;
- import std.algorithm;
- import std.regex;
- import std.getopt;
- import core.runtime;
- static void function()[string] testFunctions;
- bool unitTester() {
- string[] modules;
- string[] tests;
- string[] args = Runtime.args;
- bool help;
- getopt(args,
- "help|h", &help,
- "module_re|m", &modules,
- "test_re|t", &tests);
- if(help) {
- writeln("
- Test Function based unit tests.
- Supported arguments:
- [module_re|m] one or more regexes to match on module names
- [test_re|m] one or more regexes to match on test function names
- ");
- return false;
- }
- auto delim = regex(r"\.");
- foreach( funcName, func ; testFunctions ) {
- auto parts = split(funcName, delim);
- if(modules.length == 0 || any!(re => match(parts[0], re))(modules)) {
- if(tests.length == 0 || any!(re => match(parts[1], re))(tests)) {
- writeln("Running ", funcName);
- func();
- }
- }
- }
- return true;
- }
- static this() {
- Runtime.moduleUnitTester(&unitTester);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement