Shared static this() not executed for unittest

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Dec 17 10:09:32 UTC 2018


On Sunday, December 16, 2018 12:53:43 PM MST Steven Schveighoffer via 
Digitalmars-d-learn wrote:
> On 12/15/18 5:14 PM, Jonathan M Davis wrote:
> > On Saturday, December 15, 2018 10:27:36 AM MST Neia Neutuladh via
> >
> > Digitalmars-d-learn wrote:
> >> On Sat, 15 Dec 2018 17:19:05 +0000, Timoses wrote:
> >>> Running `dub test` will output:
> >>> Running ./unit-test-library writeln: unittest All unit tests have been
> >>> run successfully.
> >>>
> >>> Why is the `shared static this()` not executed?
> >>
> >> Run `dub clean; dub test -v` and you'll see that main.d isn't compiled
> >> into the test library.
> >>
> >> dub test substitutes its own main() function over yours. In order to do
> >> this, it needs to not compile in your main() and to compile in its own.
> >> dmd doesn't have an option to replace main(), so dub drops that entire
> >> source file.
> >
> > Yeah. I hate how dub does this. I've been bitten by it on multiple
> > occasions, and it's really easy to miss that this is happening. It
> > probably would have been better if it required you to deal with main
> > when the target type is an executable, resulting in a linker error when
> > you didn't provide one. Instead, a number of us do stuff like
>
> This should be fixed, as DMD now supports just running the program with
> --DRT-testmode=test-only and it will only run unit tests.

That would be fantastic.

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list