dub
dub copied to clipboard
Adding a configuration changes the behavior of `dub test`
DUB v1.23.0 (latest ATM)
Adding an empty configuration to dub.json changes the behavior of dub test in a way that is IMO unexpected.
Do a simple dub init, then dub test and things work. Add the following:
"configurations": [
{ "name": "with-lib" }
]
And you get a failure:
% dub test :(
Generating test runner configuration 'foo-test-with-lib' for 'with-lib' (library).
Performing "unittest" build using dmd for x86_64.
foo ~master: building configuration "foo-test-with-lib"...
source/app.d(3,6): Error: only one main allowed. Previously found main at /var/folders/1_/wzk0c3d17t37j8r1q8_3zl840000gn/T/dub_test_root_fd84c86f_46f7_4721_9886_a30205f60d95.d(9,12)
dmd failed with exit code 1.
Now looking deeper into the issue, it's obvious why: dub picks up the configuration.
However, this is slightly counter-intuitive when compared to what's written in the documentation:
The configuration name "unittest" has a special meaning - if a configuration with this name is present, it will be used by default when executing dub test. It can be assumed to have the
-unittestflag present (through the "unittest" build type). Possible use cases for custom unittest configurations overriding the default behavior of excluding the main source file or adding additional modules containing additional external tests, which don't need to be compiled in the application/library mode.
What I expected was that dub would behave as if there was a "default" unittest configuration defined, and only if I override it it would pick it up.
This is a reduction of a bug. The actual issue was much more serious: The d2sqlite3 dub.sdl file does not define unittest, and the default configuration excludes the file that contains all the test, effectively meaning the the tests haven't been run for a while.
Related forum post https://forum.dlang.org/thread/[email protected]
I think I know why: https://github.com/dlang/dub/blob/807b6e378403a270e14daa56da513fe6877c654e/source/dub/recipe/json.d#L60-L62