Skip to content

Commit

Permalink
Fix mock CallerInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerb committed Oct 19, 2012
1 parent 8014de2 commit c090beb
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// that failed.
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)
if !ok {
return ""
}
parts = strings.Split(file, "/")
parts := strings.Split(file, "/")
dir := parts[len(parts)-2]
file = parts[len(parts)-1]
if thisDir != dir || file == "assertions_test.go" {
if (dir != "assert" && dir != "mock") || file == "mock_test.go" {
break
}
}
Expand Down

0 comments on commit c090beb

Please sign in to comment.