(compiler+dub) flags to print file:line of the running unnitest
Dejan Lekic
dejan.lekic at gmail.com
Thu Mar 12 19:47:00 UTC 2026
This is not really a candidate for DIP so I write it here.
Many, many times in the past I needed to actually find unittest
that is misbehaving and a simple feature would solve my problems
- to be able to tell compiler to generate for each unittest
output in form of `__FILE__ ~ ":" ~ __LINE__` so that I can
figure out which unittest is taking too much time to execute.
Yes, I could use some third-party package but I do not want to
add a new dependency to the project for something as trivial as
this.
Currently when I need this I replace all my `unittest {` with
```d
unittest {
tt("hunt");
```
Where tt is
```d
void tt(string header, string fileName = __FILE__, int
lineNumber = __LINE__)() {
version (UT_HEADER) {
import std.stdio: writeln;
writeln("(", fileName, ":", lineNumber, ") ", header);
}
}
```
Once I find the culprit and fix or remove it, I then change back
everything to unittests without calls to the `tt` template.
Can we _please_ have something like `dub test
--print-ut-line-numbers` ?! Use whatever name you like instead of
`--print-ut-line-numbers`.
Maybe there already is a way to do this, if there is please
enlighten me!
More information about the Digitalmars-d
mailing list