Skip to content

Commit 46bd2c0

Browse files
committed
README
1 parent 753adc1 commit 46bd2c0

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,27 @@ No, seriously. They're tiny functions. Just copy them.
77

88

99
```go
10+
import (
11+
"fmt"
12+
"path/filepath"
13+
"runtime"
14+
"testing"
15+
)
16+
1017
func assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
1118
if !condition {
12-
tb.Fatalf(msg, v...)
19+
_, file, line, _ := runtime.Caller(1)
20+
v = append([]interface{}{filepath.Base(file), line}, v...)
21+
fmt.Printf("%s:%d: "+msg+"\n", v...)
22+
tb.FailNow()
1323
}
1424
}
1525

1626
func equals(tb testing.TB, exp, act interface{}) {
17-
assert(tb, exp == act, "exp: %#v, got: %#v", exp, act)
27+
if exp != act {
28+
_, file, line, _ := runtime.Caller(1)
29+
fmt.Printf("%s:%d: exp: %#v, got: %#v\n", filepath.Base(file), line, exp, act)
30+
tb.FailNow()
31+
}
1832
}
1933
```

doc.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,28 @@ It's literally two functions.
66
77
Why are you reading the documentation?
88
9+
import (
10+
"fmt"
11+
"path/filepath"
12+
"runtime"
13+
"testing"
14+
)
15+
916
func assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
1017
if !condition {
11-
tb.Fatalf(msg, v...)
18+
_, file, line, _ := runtime.Caller(1)
19+
v = append([]interface{}{filepath.Base(file), line}, v...)
20+
fmt.Printf("%s:%d: "+msg+"\n", v...)
21+
tb.FailNow()
1222
}
1323
}
1424
1525
func equals(tb testing.TB, exp, act interface{}) {
16-
assert(tb, exp == act, "exp: %#v, got: %#v", exp, act)
26+
if exp != act {
27+
_, file, line, _ := runtime.Caller(1)
28+
fmt.Printf("%s:%d: exp: %#v, got: %#v\n", filepath.Base(file), line, exp, act)
29+
tb.FailNow()
30+
}
1731
}
1832
1933
*/

0 commit comments

Comments
 (0)