How can one reliably run unittests

deadalnix deadalnix at gmail.com
Thu Aug 26 09:38:54 UTC 2021


On Wednesday, 25 August 2021 at 20:49:32 UTC, Walter Bright wrote:
> On 8/24/2021 5:21 AM, deadalnix wrote:
>> Adding a main for libraries is required, or it won't link, but 
>> adding one to executable is going to cause a link error.
>
> This is indeed a real problem. It was solved with the -main 
> switch to dmd, which will just stick one in for you. I use it 
> all the time for unit testing modules.

No it wasn't, because it add a main no matter what, which means 
that when there is a main in the module being tested, you get a 
link error.

The root of the problem, really, is that I don't cares about main 
when running unit tests. I don't want to know if it is there or 
not, I don't want it to run, nothing. If the compiler needs one 
to link under the hood, then good for it, but this is an 
implementation detail.

When running the unit tests, one wants to know if the unit tests 
pass. Nothing more, nothing less.

The compiler has 100% of the information it needs to make this 
happen, yet, for some reason, it is requesting them from me. 
Which i can provide too, but this is fragile, and it doesn't 
scale, as I can't get my build system to automate it for me. 
Which in turn lead to most projects rolling out their own 
solution.

I can work with having to pass the -main flag. This is not ideal, 
because what else could I possibly want? A link error? I'm not 
trying to link and run main. I care about unittests in that case. 
But having main declared twice is some special level of nonsense. 
In what case could I possibly want two main?


More information about the Digitalmars-d mailing list