How can one reliably run unittests

Dennis dkorpel at gmail.com
Fri Aug 27 13:35:11 UTC 2021


On Friday, 27 August 2021 at 10:30:58 UTC, deadalnix wrote:
> This is the wrong question. When one runs the unittests, they 
> don't care about main. The existance of the main flag is 
> dubious to begin with.

Saying "-unittest should have been designed differently" doesn't 
help us forward. Currently it's possible to have a -betterC test 
runner in main, or set `UnitTestResult.runmain = true` from 
`core.runtime`, or to create a unittest build with incremental 
separate compilation, so changing the semantics of the -unittest 
flag is a very disruptive change.

However, like you said, there is no use case for having two 
`main` functions in one build, so I was looking into improving 
that (see https://github.com/dlang/dmd/pull/13026), which is how 
I got to that very real implementation question.

jfondren pointed out that the default test runner doesn't run 
main, so I think it's best to make -main only insert main when 
there isn't already one being compiled in. Then you should be 
able to do `dmd -unittest -main -run somemodule.d` on any 
(self-contained) d file with consistent results.


More information about the Digitalmars-d mailing list