-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
48 lines (34 loc) · 900 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package example
import (
"fmt"
"github.com/jgroeneveld/trial/assert"
"github.com/jgroeneveld/trial/th"
"testing"
)
func TestExample(t *testing.T) {
if true {
// generic t.Error replacement that allows skipping
th.Error(t, 0, "This will happen")
}
// simple equals
assert.Equal(t, 1, 2, "numbers dont match")
assert.NotEqual(t, 1, 1, "numbers match")
// if the types dont match, it will be printed
assert.Equal(t, 1, "1")
assert.True(t, true == false)
assert.False(t, true == true)
// assert nil to have easy error handling in tests
err := someError()
assert.Nil(t, err)
err = noErr()
assert.Nil(t, err)
// Must* functions will call FailNow. (Fatal equivalent)
assert.MustBeEqual(t, "nicht", "gleich")
assert.Equal(t, "never", "thesame - but should not be called")
}
func someError() error {
return fmt.Errorf("Hallo Welt")
}
func noErr() error {
return nil
}