Fix mock CallerInfo

pull/14/merge
Tyler Bunnell 2012-10-19 09:50:23 -06:00
parent 8014de2adc
commit c090beb5e4
1 changed files with 7 additions and 9 deletions

View File

@ -36,22 +36,20 @@ the problem actually occured in calling code.*/
// CallerInfo returns a string containing the file and line number of the assert call // CallerInfo returns a string containing the file and line number of the assert call
// that failed. // that failed.
func CallerInfo() string { func CallerInfo() string {
_, file, line, ok := runtime.Caller(0)
if !ok {
return ""
}
parts := strings.Split(file, "/")
thisDir := parts[len(parts)-2]
for i := 1; ; i++ { file := ""
line := 0
ok := false
for i := 0; ; i++ {
_, file, line, ok = runtime.Caller(i) _, file, line, ok = runtime.Caller(i)
if !ok { if !ok {
return "" return ""
} }
parts = strings.Split(file, "/") parts := strings.Split(file, "/")
dir := parts[len(parts)-2] dir := parts[len(parts)-2]
file = parts[len(parts)-1] file = parts[len(parts)-1]
if thisDir != dir || file == "assertions_test.go" { if (dir != "assert" && dir != "mock") || file == "mock_test.go" {
break break
} }
} }