-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
55 lines (40 loc) · 971 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
49
50
51
52
53
54
55
package should_test
import (
"strconv"
"testing"
//You should check errors and test!
"qlova.org/should"
"qlova.org/should/check"
"qlova.org/should/check/errors"
"qlova.org/should/test"
)
type Example struct {
test.Suite
Value string
}
func (e *Example) SetupSuite() {
e.Value = "Hello World"
}
func (e Example) TestValue() {
should.Be("Hello World")(e.Value).Test(e.T())
}
func (e Example) TestPanic() {
should.Panic(func() {
panic("Hello World")
}).Test(e.T())
}
func (e Example) TestErrors() {
AddStringIntegers := func(a, b string) (sum int, err error) {
defer check.Returnf("tostring failed: %w", &err)
i1, err := strconv.Atoi(a)
check.Error(errors.Trace(err))
i2, err := strconv.Atoi(b)
check.Error(errors.Trace(err))
return i1 + i2, nil
}
should.Be(5)(AddStringIntegers("3", "2")).Test(e.T())
should.Error(AddStringIntegers("asdsadsad", "2")).Test(e.T())
}
func TestExample(t *testing.T) {
test.New(new(Example))(t)
}