-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactually_util_test.go
69 lines (57 loc) · 1.47 KB
/
actually_util_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package actually
import (
"testing"
w "github.com/bayashi/actually/witness"
)
func TestFail(t *testing.T) {
a := Got(nil)
if a.failNow != nil && *a.failNow != false {
t.Errorf("Default failNow is false, but Actual:%#v", a.failNow)
}
a.FailNow()
if *a.failNow != true {
t.Errorf("`FailNow()` was broken. Expected:%#v, but Actual:%#v", true, a.failNow)
}
a.FailNotNow()
if *a.failNow != false {
t.Errorf("`FailNotNow()` was broken. Expected:%#v, but Actual:%#v", false, a.failNow)
}
a.t = t
stub()
a.fail(w.New(), "reason")
if stubRes != "reason" {
t.Error("a.fail method is wrong")
}
stub()
a.failf(w.New(), "reason %s", "foo")
if stubRes != "reason foo" {
t.Error("a.failf method is wrong")
}
}
func TestNaming(t *testing.T) {
expect := "FooTest"
if n := Got(12).naming(expect); n != expect {
t.Errorf("Expect `%s`, but got `%s`", expect, n)
}
expect2 := "Name.FooTest"
if n := Got(12).Name("Name").naming(expect); n != expect2 {
t.Errorf("Expect `%s`, but got `%s`", expect2, n)
}
if n := Got(12).Name("Name").naming(expect, expect); n != expect2+"."+expect {
t.Errorf("Expect `%s`, but got `%s`", expect2+", "+expect, n)
}
}
func TestInvalidCall(t *testing.T) {
f := false
defer func() {
err := recover()
if err != panicReason_NotCalledGot {
t.Errorf("expect error %s, but got %+v", panicReason_NotCalledGot, err)
}
f = true
}()
Expect(nil).Nil(t) // Without calling Got should be panic
if !f {
t.Error("panic wouldn't happen")
}
}