On Sat, Sep 8, 2012 at 9:46 PM, Lucas Sampaio <
magal...@gmail.com> wrote:
> Nothing special, actually. I'm just trying to learn how to extend testing
> package... something like this, but instead of assert.Equal(t, a, b), make
> something like t.assertEqual(a, b).
// untested code
type myT struct {
*testing.T
}
func (t myT) assertEqual(foo, bar baz) {
if foo != bar {
t.Error(foo, "!=", bar)
}
}
func TestQux(t *testing.T) {
u := myT{t}
err, got := what()
if err != nil {
t.Fatal(err)
}
!u.assertWhatever(got, expected)
}
... but note how rigid 'assert*' is - it cannot easily provide more
context nor decision logic than
func TestQux(t *testing.T) {
err, got := what()
if err != nil {
t.Fatal(err)
}
if foo != bar {
switch {
case foo - bar < 0.01:
t.Log("foo not exactly bar", foo, bar)
case foo < bar:
t.Error("foo < bar", foo, bar)
case foo > bar:
t.Fatal("foo > bar!", foo, bar)
}
}
}
IOW, you will not find too much assert* like functions in Go code out there ;-)
-j