mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-11 18:32:12 +02:00
Show invocation line for failing test
This commit is contained in:
@@ -5,7 +5,9 @@ package utils
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
@@ -270,3 +272,25 @@ func IfElse[T any](condition bool, if_val T, else_val T) T {
|
||||
}
|
||||
return else_val
|
||||
}
|
||||
|
||||
func SourceLine(skip_frames ...int) int {
|
||||
s := 1
|
||||
if len(skip_frames) > 0 {
|
||||
s += skip_frames[0]
|
||||
}
|
||||
if _, _, ans, ok := runtime.Caller(s); ok {
|
||||
return ans
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func SourceLoc(skip_frames ...int) string {
|
||||
s := 1
|
||||
if len(skip_frames) > 0 {
|
||||
s += skip_frames[0]
|
||||
}
|
||||
if _, file, line, ok := runtime.Caller(s); ok {
|
||||
return filepath.Base(file) + ":" + strconv.Itoa(line)
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user