How can one reliably run unittests

jfondren julian.fondren at gmail.com
Thu Sep 2 17:51:10 UTC 2021


On Thursday, 2 September 2021 at 17:26:46 UTC, deadalnix wrote:
> ```
> $ dmd -m64 -Isrc -w -debug -g -main -unittest -i -run 
> src/somemodule.d
> 3 modules passed unittests
> ```
>
> It is clear that this is running random unitests I don't care 
> about. Module that are brought in via the -i flag are also 
> compiled with their unittests, which is nonsense.

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.

> On the other hand, I made an interesting discovery:
>
> ```
> $ dmd -m64 -Isrc -w -debug -g -main -unittest -i -run 
> src/module1.d src/module2.d
> ```
>
> Will run exclusively the tests for module1.d and ignore 
> module2.d , which is considered an argument to be passed to the 
> main that don't exist and is never run.

Yep. That's what -run does. It passes the remaining commandline 
to the program to be run.

> This is complete nonsense

The only *conceivable* alternative to this "complete nonsense" is 
to always require a -- separator, which dub does, which is more 
an artifact of getopt-style commandline processing than the 
outcome of a thoughtfully designed CLI.

dub requiring -- just means I never use it directly. Here's my 
two-line ~/.local/bin/dfmt:

```
#! /bin/bash
dub run -q --skip-registry=all dfmt -- -i --brace_style=otbs "$@"
```

> (and means that I simply run a fraction of my unitests and have 
> no idea how to fix my build to runt hem all).

```
$ grep . *.d
alsotest.d:unittest {
alsotest.d:    assert(!0);
alsotest.d:}
donttest.d:unittest {
donttest.d:    assert(0);
donttest.d:}
pleasetest.d:unittest {
pleasetest.d:    assert(true);
pleasetest.d:}
$ dmd -c donttest.d; dmd -c -unittest pleasetest.d alsotest.d
$ dmd -main -of=main *.o
$ ./main
2 modules passed unittests
```


More information about the Digitalmars-d mailing list