From 0ab3ce1249292a7221058b9e370472bca8f04813 Mon Sep 17 00:00:00 2001 From: "Artem V. Navrotskiy" Date: Tue, 3 Jan 2023 13:57:11 +0300 Subject: [PATCH] Fix `CallerInfo()` source file paths (#1288) --- assert/assertions.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/assert/assertions.go b/assert/assertions.go index 361d0bdad..c540bb02d 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -8,7 +8,6 @@ import ( "fmt" "math" "os" - "path/filepath" "reflect" "regexp" "runtime" @@ -141,12 +140,11 @@ func CallerInfo() []string { } parts := strings.Split(file, "/") - file = parts[len(parts)-1] if len(parts) > 1 { + filename := parts[len(parts)-1] dir := parts[len(parts)-2] - if (dir != "assert" && dir != "mock" && dir != "require") || file == "mock_test.go" { - path, _ := filepath.Abs(file) - callers = append(callers, fmt.Sprintf("%s:%d", path, line)) + if (dir != "assert" && dir != "mock" && dir != "require") || filename == "mock_test.go" { + callers = append(callers, fmt.Sprintf("%s:%d", file, line)) } }