Thread overview
unit-threaded v0.6.3 - now even easier to use / opt-in
Feb 29, 2016
Atila Neves
Feb 29, 2016
Sebastiaan Koppe
Feb 29, 2016
Dicebot
Feb 29, 2016
Sebastiaan Koppe
Mar 02, 2016
Sebastiaan Koppe
Mar 02, 2016
Atila Neves
February 29, 2016
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
February 29, 2016
On Monday, 29 February 2016 at 09:37:51 UTC, Atila Neves wrote:
> http://code.dlang.org/packages/unit-threaded
>
> Enjoy!
>
> Atila

Really nice.

Wow, didn't know dub could build and run a dependency.
February 29, 2016
On 02/29/2016 02:00 PM, Sebastiaan Koppe wrote:
> On Monday, 29 February 2016 at 09:37:51 UTC, Atila Neves wrote:
>> http://code.dlang.org/packages/unit-threaded
>>
>> Enjoy!
>>
>> Atila
> 
> Really nice.
> 
> Wow, didn't know dub could build and run a dependency.

Note: only if it has a configuration with an `application` target defined.

It is effectively a way to make tools from dub registry usable from other dub projects without messing with system-wide state.
February 29, 2016
On Monday, 29 February 2016 at 12:11:44 UTC, Dicebot wrote:
> On 02/29/2016 02:00 PM, Sebastiaan Koppe wrote:
>> On Monday, 29 February 2016 at 09:37:51 UTC, Atila Neves wrote:
>>> http://code.dlang.org/packages/unit-threaded
>>>
>>> Enjoy!
>>>
>>> Atila
>> 
>> Really nice.
>> 
>> Wow, didn't know dub could build and run a dependency.
>
> Note: only if it has a configuration with an `application` target defined.
>
> It is effectively a way to make tools from dub registry usable from other dub projects without messing with system-wide state.

That is pretty darn cool. It means one can write some nice dev tools. E.g. a file-watcher that runs unittests on each save command.
March 02, 2016
On Monday, 29 February 2016 at 09:37:51 UTC, Atila Neves wrote:
>     "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"
>             }
>         }

Worked nicely, but I had to change some configs.

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

probably due to dub's default of the code being in `source/` instead of root folder. Do not know why I had to add `targetType:executable`, perhapse because my project is a library ?
March 02, 2016
On Wednesday, 2 March 2016 at 12:52:34 UTC, Sebastiaan Koppe wrote:
> On Monday, 29 February 2016 at 09:37:51 UTC, Atila Neves wrote:
>>         [...]
>
> Worked nicely, but I had to change some configs.
>
>         {
>             "name": "unittest",
>             "preBuildCommands": ["dub run unit-threaded -c gen_ut_main -- -f bin/ut.d"],
>             "importPaths": ["bin"],
>             "mainSourceFile": "bin/ut.d",
>             "excludedSourceFiles": ["app.d"],
>             "targetType":"executable",
>             "dependencies": {
>                 "unit-threaded": "~>0.6.3"
>             }
>         }
>
> probably due to dub's default of the code being in `source/` instead of root folder. Do not know why I had to add `targetType:executable`, perhapse because my project is a library ?

Yeah, I think that's why. Glad it worked out for you!

Atila