Skip to content

Commit b2985f5

Browse files
author
Stavros Ntentos
committed
impr: CallerInfo should print full paths to the terminal
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>
1 parent 41453c0 commit b2985f5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

assert/assertions.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"math"
1010
"os"
11+
"path/filepath"
1112
"reflect"
1213
"regexp"
1314
"runtime"
@@ -144,7 +145,8 @@ func CallerInfo() []string {
144145
if len(parts) > 1 {
145146
dir := parts[len(parts)-2]
146147
if (dir != "assert" && dir != "mock" && dir != "require") || file == "mock_test.go" {
147-
callers = append(callers, fmt.Sprintf("%s:%d", file, line))
148+
path, _ := filepath.Abs(file)
149+
callers = append(callers, fmt.Sprintf("%s:%d", path, line))
148150
}
149151
}
150152

0 commit comments

Comments
 (0)