Skip to content

Commit

Permalink
impr: CallerInfo should print full paths to the terminal
Browse files Browse the repository at this point in the history
I am proposing this simple change, which changes this output
```
--- FAIL: TestABC (0.00s)
    --- FAIL: TestABC/C (0.00s)
        /0/1/2/3/4/5/6_test.go:258:
            	Error Trace:	6_test.go:258
            	            				6_test.go:748
            	Error:      	Not equal:
...
```
to this:
```
--- FAIL: TestABC (0.00s)
    --- FAIL: TestABC/C (0.00s)
        /0/1/2/3/4/5/6_test.go:258:
            	Error Trace:	/0/1/2/3/4/5/6_test.go:258
            	            				/0/1/2/3/4/5/6_test.go:748
            	Error:      	Not equal:
...
```

With the latter output, it is much more straightforward to find the file
you are looking for, even though in the displayed case, the file is the same.

However, for VSCodium, the case is a little more helpful, since VSCodium's
terminal is smart enough to recognize the output, and make links out of that input.

Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com>
  • Loading branch information
Stavros Ntentos committed Jun 9, 2022
1 parent 41453c0 commit b2985f5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion assert/assertions.go
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"math"
"os"
"path/filepath"
"reflect"
"regexp"
"runtime"
Expand Down Expand Up @@ -144,7 +145,8 @@ func CallerInfo() []string {
if len(parts) > 1 {
dir := parts[len(parts)-2]
if (dir != "assert" && dir != "mock" && dir != "require") || file == "mock_test.go" {
callers = append(callers, fmt.Sprintf("%s:%d", file, line))
path, _ := filepath.Abs(file)
callers = append(callers, fmt.Sprintf("%s:%d", path, line))
}
}

Expand Down

0 comments on commit b2985f5

Please sign in to comment.