Named unittests

Adam D. Ruppe destructionator at gmail.com
Sat May 18 13:20:13 UTC 2019


On Saturday, 18 May 2019 at 05:49:00 UTC, H. S. Teoh wrote:
> Dmd already has -run, so it's not too much of a stretch to 
> change the behaviour of -unittest into the equivalent of 
> today's:
>
> 	dmd -unittest -run blah.d

Actually, right after I went to bed, I realized the solution to 
everyone's problem.

We all want `-unittest=package,list` to control which tests are 
run. That doesn't exist yet which means it is our opportunity to 
change other things along with the new syntax.

dmd -unittest # existing behavior, no changes
dmd -unittest=package,list # implies -run, -main when needed, 
triggers new druntime behavior


The help text might be
   -unittest         compile in unit tests
   -unittest=<pattern> run automatic unittests for <pattern> 
modules as part of the build



I think this will keep unit-threaded from experiencing any 
breakage (though I wouldn't be surprised if Atila would be 
onboard for some changes too. I actually could go a little 
further and make the built in tests more customizable, but right 
now I wanna do the simplest thing that can possibly work.)



> Perhaps tentatively we can
> call it --DRT-run-unittests, which will start the unittest 
> runner and skip over calling _Dmain.

Yes, that's what I'm thinking.

So the dmd auto run uses the --DRT-run-unittests flag which runs 
them but NOT main.

But if you don't specify that, you run main like normal, without 
tests.

And this can be done only on the new switch syntax so no legacy / 
third party runner breakage.


> Of course, currently this involves running two instances of the 
> compiler, one with -unittest and one without; but if there was 
> some way to unify them, and perhaps make running the unittests 
> automatic, that would be *really* nice.

Yes, I thought about that too, I just figured it would be easier 
today to just keep the existing plumbing for the most part.

version(unittest) existing makes it kinda hard to imagine doing 
to builds with a lot of reuse of compiler time. Well, I'm sure we 
can do some but each semantic could be different with the 
presence of that version thus making me think the compiler is 
basically run twice regardless.

but maybe that can be solved, just again I wanna go for a MVP we 
can try out in the ~2ish hours I have available this weekend to 
hack on D.


More information about the Digitalmars-d mailing list