-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_util.go
42 lines (34 loc) · 841 Bytes
/
test_util.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
package xmpp
import (
"testing"
"regexp"
)
func should(t *testing.T, message string, checker func() bool) {
if !checker() {
t.Fatalf("Should " + message)
}
}
func assertEqual(t *testing.T, expected, actual interface{}, message string) {
if expected != actual {
t.Fatalf("Expected <%s> but got <%s>", expected, actual)
}
}
func assertMatch(t *testing.T, regex_str, str, message string) {
regex := regexp.MustCompile(regex_str)
if !regex.MatchString(str) {
t.Fatalf("%s: Expected <%s> to match <%s>", message, str, regex)
} else {
// all good
}
}
func assertPanic(t *testing.T, message string, f func()) {
defer func() {
if err := recover(); err == nil {
t.Fatalf(message)
}
}()
f()
}
func fail(t *testing.T, message string, args ...interface{}) {
t.Fatalf(message, args...)
}