Improved error messages

This commit is contained in:
Eduard Urbach 2023-07-10 11:36:17 +02:00
parent 2b28627e58
commit 7ab2ff6627
Signed by: eduard
GPG key ID: 49226B848C78F6C8
7 changed files with 46 additions and 43 deletions

View file

@ -3,16 +3,21 @@ package assert
import (
"runtime/debug"
"strings"
"testing"
)
// file returns the first line containing "_test.go" in the debug stack.
func file(t testing.TB) string {
func file() string {
stack := string(debug.Stack())
lines := strings.Split(stack, "\n")
for _, line := range lines {
if strings.Contains(line, "_test.go") {
space := strings.LastIndex(line, " ")
if space != -1 {
line = line[:space]
}
return strings.TrimSpace(line)
}
}