http://code.dlang.org/packages/unit-threaded

Through the magic of dub, unit-threaded is now easier to include in your project, with no need for a hand-written test main file anymore. And all because the library can be run as an executable by dub. It's an idea that's so obvious in retrospect I don't know how it took me this long.

Say you've already got a dub project with unittest blocks and you just want them to have names and be run in threads. Easy, just have a "unittest" configuration in your dub.json/sdl like so:



    "configurations": [
        ...,
        {
            "name": "unittest",
"preBuildCommands": ["dub run unit-threaded -c gen_ut_main -- -f bin/ut.d"],
            "mainSourceFile": "bin/ut.d",
            "excludedSourceFiles": "src/main.d",
            "dependencies": {
                "unit-threaded": "~>0.6.3"
            }
        }


Now run "dub test" and enjoy the results. If you want "real" names then add a string UDA to your unittest blocks. And.... that's it. You might not even need to exclude the module with the main function if said function is versioned out for unit test builds.

If you want to use the library's other features you'll have to import it but that's easily versioned as well:

version(unittest) {
    import unit_threaded;
}

Enjoy!

Atila

Reply via email to