Is it possible to compile unittest without running them and explicitly run unittest for a specific module?

前提是你 提交于 2019-12-05 17:41:17

You can program a custom test runner using the trait getUnittests.

getUnitTests

Takes one argument, a symbol of an aggregate (e.g. struct/class/module). The result is a tuple of all the unit test functions of that aggregate. The functions returned are like normal nested static functions, CTFE will work and UDA's will be accessible.

in your main() you should be able to write something that takes an arbitrary number of module:

void runModuleTests(Modules...)()
{
    static if (Modules.length > 1)
        runModuleTests!(Modules[1..$]);
    else static if (Modules.length == 1)
        foreach(test; __traits(getUnitTests, Modules[0])) test;
}

of course the switch -unittest must be passed to dmd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!