How can one reliably run unittests

jfondren julian.fondren at gmail.com
Thu Sep 2 18:15:17 UTC 2021


On Thursday, 2 September 2021 at 18:01:34 UTC, deadalnix wrote:
> On Thursday, 2 September 2021 at 17:51:10 UTC, jfondren wrote:
>> This is the only reasonable outcome from this combination of 
>> flags. Not everything that ever surprises you is nonsense. If 
>> you're not familiar with how dmd works, then being surprised 
>> is just part of learning how it works.
>>
>
> No, it clearly isn't. In fact, there are exactly 0 use case for 
> what this combination of flag is doing and 0 combination of 
> flags for use cases that exist in the wild.

1 use case: run all the tests in all the imported modules. The 
thing it does.

> This is *OBVIOUSLY* nonsense because there is *NO PROGRAM TO BE 
> RUN*. The compiler know this because I had to pass the -main 
> flag to begin with.

You want -run to treat the commandline completely differently 
depending on whether -main has been passed? That would help you 
to have not been surprised in this one case, but by making the 
CLI more complex it's just going to be more confusing to more 
people in the long run.

Bug report: I removed -main and suddenly was only testing a 
single module instead of the several I'd been testing before.

> Think of it this way. There is a unitest feature in the 
> language. There are literally no way to tell the compiler 
> "please run the unitests for this set of module".

This is fair. There's a lot of machinery set up *around* testing 
but there isn't a one-shot command. 'dub test' also isn't such a 
command, as it's package-oriented rather than module-oriented.

> Or if there is one, it is so bizantine that nobody seems to be 
> able to figure it out. This is a 7 pages long thread about it, 
> full of D experts, and yet, nobody knows how to do this simple 
> task.

I just demonstrated compiling three modules to only test two of 
them. This 7 pages long thread has all kinds of talk in it; it is 
not full of people asking "I have these files; how do I run only 
these tests in them?" or it'd be full of as many answers. The 
machinery built up *around* testing is very good and can be 
persuaded to work any way you want.


More information about the Digitalmars-d mailing list