27 lines
439 B
Go
Raw Normal View History

2023-07-05 11:14:37 +00:00
package assert
import (
"runtime/debug"
"strings"
)
// file returns the first line containing "_test.go" in the debug stack.
2023-07-10 09:36:17 +00:00
func file() string {
2023-07-05 11:14:37 +00:00
stack := string(debug.Stack())
lines := strings.Split(stack, "\n")
for _, line := range lines {
if strings.Contains(line, "_test.go") {
2023-07-10 09:36:17 +00:00
space := strings.LastIndex(line, " ")
if space != -1 {
line = line[:space]
}
2023-07-05 11:14:37 +00:00
return strings.TrimSpace(line)
}
}
return ""
}