Thread overview
unittests and imported modules
Jan 28, 2021
kdevel
Jan 28, 2021
H. S. Teoh
Jan 28, 2021
kdevel
Jan 29, 2021
H. S. Teoh
January 28, 2021
Today I moved some functions to a new module within the same package
and ran

   dmd -g -i -unittest -checkaction=context -main -run <filename>.

dmd reported

   5 unittests passed

I would have expected that only the one unittest in <filename> would
have been compiled. After inserting print statements into the
other modules I found that the additional four unittests originate
from the imported files. Is there a trick to get only the unittest
from <filename> run other than dropping the "-i" and specifiying
the other object files on the command line?

And why are the unittests from the imported phobos functions not run?
January 28, 2021
On Thu, Jan 28, 2021 at 07:44:59PM +0000, kdevel via Digitalmars-d-learn wrote:
> Today I moved some functions to a new module within the same package and ran
> 
>    dmd -g -i -unittest -checkaction=context -main -run <filename>.
> 
> dmd reported
> 
>    5 unittests passed

Which version of dmd is this?  In the latest releases, this inaccurate message has been replaced with:

    5 modules passed unittests

The count displayed is not the number of unittests, but the number of *modules* that passed unittests.  I've no idea why the original message was worded in such a misleading way, but it should have been fixed by now.


T

-- 
Why did the mathematician reinvent the square wheel?  Because he wanted to drive smoothly over an inverted catenary road.
January 28, 2021
On Thursday, 28 January 2021 at 20:03:34 UTC, H. S. Teoh wrote:
[...]
>>    5 unittests passed
>
> Which version of dmd is this?

$ dmd --version
DMD64 D Compiler v2.093.1
Copyright (C) 1999-2020 by The D Language Foundation, All Rights Reserved written by Walter Bright

> In the latest releases, this inaccurate message has been replaced with:
>
>     5 modules passed unittests
>
> The count displayed is not the number of unittests, but the number of *modules* that passed unittests.  I've no idea why the original message was worded in such a misleading way, but it should have been fixed by now.

DMD Versions > v2.094.1 expose a library issue here on my machine such that
I can only run the 32-Bit version of the compiler (which nonetheless
produces working 64-Bit-Code).

January 28, 2021
To answer your other question:

On Thu, Jan 28, 2021 at 07:44:59PM +0000, kdevel via Digitalmars-d-learn wrote: [...]
> After inserting print statements into the other modules I found that the additional four unittests originate from the imported files. Is there a trick to get only the unittest from <filename> run other than dropping the "-i" and specifiying the other object files on the command line?

AFAIK it's currently not possible with the built-in test runner. But there are dub packages for replacement test runners that may offer this functionality.


> And why are the unittests from the imported phobos functions not run?

Phobos was hacked to only run unittests when StdUnittest is defined. It's a workaround for the lameness that unittests from *all* imported modules are run with a -unittest build, including from external modules and libraries you may not be concerned with.


T

-- 
The easy way is the wrong way, and the hard way is the stupid way. Pick one.