How can one reliably run unittests

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Tue Aug 24 15:54:25 UTC 2021


On Tuesday, 24 August 2021 at 12:21:41 UTC, deadalnix wrote:
> Some of these component are libraries, some are executable. 
> 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 
> in itself is a major main in the ass, because that means there 
> is no one consistent way to unittest a module without knowing 
> if that module has a main. In addition, everything needs to be 
> built twice now, which is really undesirable.

That particular problem has a well known workaround -- prepend 
the `main` function with `version` statements to exclude it from 
`unittest` builds:

```D
version (unittest) {} else
void main ()
{
     ...
}
```

Obviously that assumes you control all the codebases that define 
a `main`, and it doesn't solve the problem of building everything 
twice, but it should cover a lot of use-cases.


More information about the Digitalmars-d mailing list