You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
831 B

  1. // Package gotest contains internal functionality. Although this package
  2. // contains one or more exported names it is not intended for public
  3. // consumption. See the examples package for how to use this project.
  4. package gotest
  5. import (
  6. "runtime"
  7. "strings"
  8. )
  9. func ResolveExternalCaller() (file string, line int, name string) {
  10. var caller_id uintptr
  11. callers := runtime.Callers(0, callStack)
  12. for x := 0; x < callers; x++ {
  13. caller_id, file, line, _ = runtime.Caller(x)
  14. if strings.HasSuffix(file, "_test.go") || strings.HasSuffix(file, "_tests.go") {
  15. name = runtime.FuncForPC(caller_id).Name()
  16. return
  17. }
  18. }
  19. file, line, name = "<unkown file>", -1, "<unknown name>"
  20. return // panic?
  21. }
  22. const maxStackDepth = 100 // This had better be enough...
  23. var callStack []uintptr = make([]uintptr, maxStackDepth, maxStackDepth)