Thread overview
Re: Does "dub test" run tests?
Mar 20, 2017
Jonathan M Davis
Mar 20, 2017
Russel Winder
Mar 20, 2017
Russel Winder
Mar 20, 2017
Jacob Carlborg
March 20, 2017
On Monday, March 20, 2017 07:51:09 Russel Winder via Digitalmars-d-learn wrote:
> I have a Meson build for a D program project with a single main.d file that has some unit tests. Both executable and test executable are created and work as expected.
>
> I created a minimal Dub file for this project. Using Dub the program runs as expected. However when I run "dub test" it claims to be running "dub -b unittest" and then proceeds to run the program not the tests.
>
> In main.d I have:
>
>     ... some most excellent D code …
>
>     version(unittest) {
>       ... the unit tests ...
>     }
>     else {
>       ... the application main ...
>     }
>
> so whilst the Meson/Ninja "ldc2 -unittest --main" thing works fine, Dub doesn't do the right thing. Or more likely I am just missing something obvious.

I haven't spent the time to dig in and report it properly, but based on some of what I saw recently on a project I have, the module with main in it didn't have its tests run, as if dub's didn't compile it when compiling the unit tests. The tests in the other modules were definitely run though. So, I think that dub probably does have a bug with regards to how it handles the module with main in it.

- Jonathan M Davis


March 20, 2017
On Mon, 2017-03-20 at 00:58 -0700, Jonathan M Davis via Digitalmars-d- learn wrote:
> 
[…]
> I haven't spent the time to dig in and report it properly, but based
> on some
> of what I saw recently on a project I have, the module with main in
> it
> didn't have its tests run, as if dub's didn't compile it when
> compiling the
> unit tests. The tests in the other modules were definitely run
> though. So, I
> think that dub probably does have a bug with regards to how it
> handles the
> module with main in it.

Actually it seems worse than that. Even with "dub -b unittest" it appears that Dub  compiles main.d without the -unittest flag to ldc2 and so the normal application runs.

-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

March 20, 2017
On Mon, 2017-03-20 at 08:39 +0000, Russel Winder wrote:
> […]
> Actually it seems worse than that. Even with "dub -b unittest" it
> appears that Dub  compiles main.d without the -unittest flag to ldc2
> and so the normal application runs.

And different behaviour with different build options, at least when using dmd, but I think the same is true for ldc2:


|> dub test
No source files found in configuration 'library'. Falling back to "dub -b unittest".
Performing "unittest" build using dmd for x86_64.
approxgc ~master: building configuration "application"...
Linking...
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
dmd failed with exit code 1.
600 anglides:~/Repositories/Git/Masters/ApproxGC_D

|> dub test --build=release
No source files found in configuration 'library'. Falling back to "dub -b unittest".
Performing "release" build using dmd for x86_64.
approxgc ~master: building configuration "application"...
Linking...
Running ./approxgc
["b":["b_1.2.1.txt", "b_1.0.0.txt", "b_1.0.2.txt"], "a":["a_1.1.0.txt", "a_1.0.1.txt", "a_1.0.0.txt"]]
["b_1.0.0.txt", "b_1.0.2.txt", "a_1.0.0.txt", "a_1.0.1.txt"]



-- 
Russel. ============================================================================= Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net 41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@winder.org.uk London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

March 20, 2017
On 2017-03-20 10:07, Russel Winder via Digitalmars-d-learn wrote:

> And different behaviour with different build options, at least when
> using dmd, but I think the same is true for ldc2:
>
>
> |> dub test
> No source files found in configuration 'library'. Falling back to "dub -b unittest".
> Performing "unittest" build using dmd for x86_64.
> approxgc ~master: building configuration "application"...
> Linking...
> /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
> (.text+0x20): undefined reference to `main'
> collect2: error: ld returned 1 exit status
> Error: linker exited with status 1
> dmd failed with exit code 1.
> 600 anglides:~/Repositories/Git/Masters/ApproxGC_D

For me it works with "dub test" using DMD. But Dub does not seem to include its own "main" for running the tests.

These are the interesting flags that Dub uses when invoking DMD when "dub test --verbose" is run:

-debug -g -unittest -w

-- 
/Jacob Carlborg