Skip to content

Commit 79140fd

Browse files
authored
Merge pull request #19 from Merovius/test_location
Add location to test-failure output
2 parents ba95eba + 1af8bf2 commit 79140fd

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/helpers_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
package gin_test
22

33
import (
4+
"fmt"
45
"reflect"
6+
"runtime"
57
"testing"
68
)
79

10+
func getCaller() string {
11+
_, file, line, ok := runtime.Caller(2)
12+
if !ok {
13+
return "Unrecoverable location"
14+
}
15+
return fmt.Sprintf("%s:%d", file, line)
16+
}
17+
818
/* Test Helpers */
919
func expect(t *testing.T, a interface{}, b interface{}) {
1020
if a != b {
11-
t.Errorf("Expected %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a))
21+
t.Errorf("Expected %v (type %v) - Got %v (type %v) at %s", b, reflect.TypeOf(b), a, reflect.TypeOf(a), getCaller())
1222
}
1323
}
1424

1525
func refute(t *testing.T, a interface{}, b interface{}) {
1626
if a == b {
17-
t.Errorf("Did not expect %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a))
27+
t.Errorf("Did not expect %v (type %v) - Got %v (type %v) at %s", b, reflect.TypeOf(b), a, reflect.TypeOf(a), getCaller())
1828
}
1929
}

0 commit comments

Comments
 (0)