-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfaket_test.go
56 lines (48 loc) · 1.36 KB
/
faket_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
package faket
import (
"testing"
"github.com/prashantv/faket/internal/syncutil"
"github.com/prashantv/faket/internal/want"
)
func TestFakeT_Success(t *testing.T) {
res := RunTest(func(t testing.TB) {
t.Log("this", "is", "log", 1)
})
want.Equal(t, "Failed", res.Failed(), false)
want.Equal(t, "Skipped", res.Skipped(), false)
want.DeepEqual(t, "Logs", res.Logs().Messages(), []string{"this is log 1"})
}
func TestFakeT_FailSkip(t *testing.T) {
tr := RunTest(func(t testing.TB) {
t.Error("about to skip")
t.Skipf("skip %s", t.Name())
})
want.Equal(t, "Skipped", tr.Skipped(), false)
want.Equal(t, "Failed", tr.Failed(), true)
want.Equal(t, "FailedAndSkipped", tr.FailedAndSkipped(), true)
}
func TestFakeT_Helpers(t *testing.T) {
tr := RunTest(func(t testing.TB) {
testHelper1(t)
testHelper2(t)
testHelper3(t)
})
want.DeepEqual(t, "Helpers", tr.Helpers(), []string{
"github.com/prashantv/faket.testHelper1",
"github.com/prashantv/faket.testHelper3",
})
}
func testHelper1(t testing.TB) { t.Helper() }
func testHelper2(t testing.TB) {}
func testHelper3(t testing.TB) { t.Helper() }
func TestFakeT_PanicRace(t *testing.T) {
syncutil.RunN(100, func(int) {
for i := 0; i < 100; i++ {
res := RunTest(func(t testing.TB) {
panic("panicked")
})
want.Equal(t, "Failed", res.Failed(), true)
want.Equal(t, "Panicked", res.Panicked(), true)
}
})
}