Thread overview
dub: standard project: how to build the unittest (the thing `dub test` runs)
Dec 12, 2020
Tobias Pankrath
Dec 12, 2020
Andre Pany
Dec 12, 2020
Andre Pany
Dec 12, 2020
Tobias Pankrath
Dec 12, 2020
Andre Pany
December 12, 2020
Whenever I come back to some D, I seem to be stumbling over dub. Somehow dub and I don't align:

$ dub init dubtest && cd dubtest
$ dub test
-> creates executable `dubtest` (saying Falling back to "dub -b unittest".)

$ touch source/lib.d
dub test
-> creates executable dubtest-test-library

Question is: How do I build the `dubtest-test-library` without running the tests?

> If no explicit configuration is given, an existing "unittest" configuration will be preferred for testing. If none exists, the first library type configuration will be used, and if that doesn't exist either, the first executable configuration is chosen.

I've tried

$ dub test -b unittest -c library

but that re-creates ./dubtest not ./dubtest-test-library.

December 12, 2020
On Saturday, 12 December 2020 at 11:13:45 UTC, Tobias Pankrath wrote:
> Whenever I come back to some D, I seem to be stumbling over dub. Somehow dub and I don't align:
>
> $ dub init dubtest && cd dubtest
> $ dub test
> -> creates executable `dubtest` (saying Falling back to "dub -b unittest".)
>
> $ touch source/lib.d
> dub test
> -> creates executable dubtest-test-library
>
> Question is: How do I build the `dubtest-test-library` without running the tests?
>
>> If no explicit configuration is given, an existing "unittest" configuration will be preferred for testing. If none exists, the first library type configuration will be used, and if that doesn't exist either, the first executable configuration is chosen.
>
> I've tried
>
> $ dub test -b unittest -c library
>
> but that re-creates ./dubtest not ./dubtest-test-library.

In any case you should have configurations in your dub json. For the first configuration, the name does not matter, it is used by default for command "dub" or "dub build", here you set targetType library. The second configuration you name unittest, you set targetType executable and you also have to set attribute mainSourceFile. This configuration is used automatically by command "dub test".

Kind regards
Andre
December 12, 2020
On Saturday, 12 December 2020 at 12:18:47 UTC, Andre Pany wrote:
> On Saturday, 12 December 2020 at 11:13:45 UTC, Tobias Pankrath wrote:
>> [...]
>
> In any case you should have configurations in your dub json. For the first configuration, the name does not matter, it is used by default for command "dub" or "dub build", here you set targetType library. The second configuration you name unittest, you set targetType executable and you also have to set attribute mainSourceFile. This configuration is used automatically by command "dub test".
>
> Kind regards
> Andre

Here is a more detailed example
https://github.com/andre2007/coding-puzzles/blob/master/dub.json

Kind regards
Andre
December 12, 2020
On Saturday, 12 December 2020 at 12:18:47 UTC, Andre Pany wrote:
>
> In any case you should have configurations in your dub json.

Thank you for your detailed reply and I am sure I can make it work in the way you described.

But I don't think my use case is invalid and dub should improve its usability here.

Either it is indeed necessary to provide configuration even for very simple projects. Than dub should generate them on `dub init`. Or dub allows one to just build the test without running them. I'd propose `dub build test` or `dub build --test` for it.

What do you think?

December 12, 2020
On Saturday, 12 December 2020 at 12:47:59 UTC, Tobias Pankrath wrote:
> On Saturday, 12 December 2020 at 12:18:47 UTC, Andre Pany wrote:
>>
>> In any case you should have configurations in your dub json.
>
> Thank you for your detailed reply and I am sure I can make it work in the way you described.
>
> But I don't think my use case is invalid and dub should improve its usability here.
>
> Either it is indeed necessary to provide configuration even for very simple projects. Than dub should generate them on `dub init`. Or dub allows one to just build the test without running them. I'd propose `dub build test` or `dub build --test` for it.
>
> What do you think?

As far as I remember someone else also requested the feature: building a test build without executing it.
About the actual command I am not sure, maybe also `dub test --build` could be an option.

Actually I add the configurations section to all dub projects, therefore I would like if dub init already add it by default. But I do not know whether this would be for other (new) users too confusing.

Kind regards
Andre