1 Star 0 Fork 0

api-go / smartystreets-goconvey

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
utils.go 771 Bytes
一键复制 编辑 原始数据 按行查看 历史
package gotest
import (
"fmt"
"runtime"
"strings"
)
func FormatExternalFileAndLine() string {
file, line, _ := ResolveExternalCaller()
if line == -1 {
return "<unknown caller!>" // panic?
}
return fmt.Sprintf("%s:%d", file, line)
}
func ResolveExternalCaller() (file string, line int, name string) {
var caller_id uintptr
callers := runtime.Callers(0, callStack)
for x := 0; x < callers; x++ {
caller_id, file, line, _ = runtime.Caller(x)
if strings.HasSuffix(file, "test.go") {
name = runtime.FuncForPC(caller_id).Name()
return
}
}
file, line, name = "<unkown file>", -1, "<unknown name"
return // panic?
}
const maxStackDepth = 100 // This had better be enough...
var callStack []uintptr = make([]uintptr, maxStackDepth, maxStackDepth)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/netscript/smartystreets-goconvey.git
git@gitee.com:netscript/smartystreets-goconvey.git
netscript
smartystreets-goconvey
smartystreets-goconvey
v1.4.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891