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

I often wrote my test code in the main function when developing the API, but since D integrated unittest, I want to start using them.

My current workflow is as follows: I have a script that monitors file changes in any .d files, if scripts detect a modified file, it will run dub build

The problem is that dub buildunittest doesn't seem to create

module foo

struct Bar{..}

unittest{
...
// some syntax error here
...
}

It only compiles unittests if I explicitly run it dub test. But I do not want to run and compile them at the same time.

The second problem is that I want to be able to run unittests for one module, for example

dub test module foo

Is it possible?

+4
1

, getUnittests.

getUnitTests

, (, struct/class/module). unit test . , CTFE , UDA .

main() -, :

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

, -unittest dmd

+1

Source: https://habr.com/ru/post/1626463/


All Articles