www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - (compiler+dub) flags to print file:line of the running unnitest

reply Dejan Lekic <dejan.lekic gmail.com> writes:
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!
Mar 12
next sibling parent Dejan Lekic <dejan.lekic gmail.com> writes:
On Thursday, 12 March 2026 at 19:47:00 UTC, Dejan Lekic wrote:

Apologies I was writing in rush. Here is how the `tt` template is 
called:

```d
unittest {
   tt!"hunt";
```

Anyway, I should not need this at all...
Mar 12
prev sibling parent reply Julian Fondren <julian.fondren gmail.com> writes:
On Thursday, 12 March 2026 at 19:47:00 UTC, Dejan Lekic wrote:
 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.
If you're using dub, then the testing library need only be a testing dependency, like ``` configuration "release" { targetType "executable" } configuration "unittest" { targetType "library" dependency "silly" version="~>1.1.1" } ```
Mar 16
parent Dejan Lekic <dejan.lekic gmail.com> writes:
On Monday, 16 March 2026 at 23:24:29 UTC, Julian Fondren wrote:

 If you're using dub, then the testing library need only be a 
 testing dependency, like

 ```
 configuration "release" {
     targetType "executable"
 }
 configuration "unittest" {
     targetType "library"
     dependency "silly" version="~>1.1.1"
 }
 ```
Yes. I am aware of this. My point is - this should be available to us by default, with the default tooling, without the need for third-party packages.
Mar 17