]>
Commit | Line | Data |
---|---|---|
6f8a32d5 PN |
1 | set ::num_tests 0 |
2 | set ::num_passed 0 | |
3 | set ::num_failed 0 | |
4 | set ::tests_failed {} | |
98578b57 | 5 | |
c2ff0e90 PN |
6 | proc assert {condition} { |
7 | if {![uplevel 1 expr $condition]} { | |
6f8a32d5 | 8 | error "assertion:Expected '$value' to be true" |
c2ff0e90 PN |
9 | } |
10 | } | |
11 | ||
d4507ec6 PN |
12 | proc assert_match {pattern value} { |
13 | if {![string match $pattern $value]} { | |
6f8a32d5 | 14 | error "assertion:Expected '$value' to match '$pattern'" |
d4507ec6 PN |
15 | } |
16 | } | |
17 | ||
18 | proc assert_equal {expected value} { | |
19 | if {$expected ne $value} { | |
6f8a32d5 | 20 | error "assertion:Expected '$value' to be equal to '$expected'" |
d4507ec6 PN |
21 | } |
22 | } | |
23 | ||
24 | proc assert_error {pattern code} { | |
5eedc9c6 | 25 | if {[catch {uplevel 1 $code} error]} { |
d4507ec6 PN |
26 | assert_match $pattern $error |
27 | } else { | |
6f8a32d5 | 28 | error "assertion:Expected an error but nothing was catched" |
d4507ec6 PN |
29 | } |
30 | } | |
31 | ||
32 | proc assert_encoding {enc key} { | |
86d39249 PN |
33 | # Swapped out values don't have an encoding, so make sure that |
34 | # the value is swapped in before checking the encoding. | |
35 | set dbg [r debug object $key] | |
68254919 PN |
36 | while {[string match "* swapped at:*" $dbg]} { |
37 | r debug swapin $key | |
86d39249 PN |
38 | set dbg [r debug object $key] |
39 | } | |
40 | assert_match "* encoding:$enc *" $dbg | |
d4507ec6 PN |
41 | } |
42 | ||
43 | proc assert_type {type key} { | |
44 | assert_equal $type [r type $key] | |
45 | } | |
46 | ||
6f8a32d5 | 47 | proc test {name code {okpattern undefined}} { |
6e0e5bed PN |
48 | # abort if tagged with a tag to deny |
49 | foreach tag $::denytags { | |
50 | if {[lsearch $::tags $tag] >= 0} { | |
51 | return | |
52 | } | |
53 | } | |
54 | ||
55 | # check if tagged with at least 1 tag to allow when there *is* a list | |
56 | # of tags to allow, because default policy is to run everything | |
57 | if {[llength $::allowtags] > 0} { | |
58 | set matched 0 | |
59 | foreach tag $::allowtags { | |
73bd6c58 | 60 | if {[lsearch $::tags $tag] >= 0} { |
6e0e5bed PN |
61 | incr matched |
62 | } | |
63 | } | |
64 | if {$matched < 1} { | |
65 | return | |
66 | } | |
67 | } | |
68 | ||
6f8a32d5 PN |
69 | incr ::num_tests |
70 | set details {} | |
71 | lappend details $::curfile | |
72 | lappend details $::tags | |
73 | lappend details $name | |
74 | ||
75 | if {$::verbose} { | |
76 | puts -nonewline [format "#%03d %-68s " $::num_tests $name] | |
77 | flush stdout | |
78 | } | |
79 | ||
fdfb02e7 | 80 | if {[catch {set retval [uplevel 1 $code]} error]} { |
6f8a32d5 PN |
81 | if {[string match "assertion:*" $error]} { |
82 | set msg [string range $error 10 end] | |
83 | lappend details $msg | |
84 | lappend ::tests_failed $details | |
85 | ||
86 | incr ::num_failed | |
87 | if {$::verbose} { | |
88 | puts "FAILED" | |
89 | puts "$msg\n" | |
90 | } else { | |
91 | puts -nonewline "F" | |
92 | } | |
d4507ec6 | 93 | } else { |
6f8a32d5 PN |
94 | # Re-raise, let handler up the stack take care of this. |
95 | error $error $::errorInfo | |
d4507ec6 | 96 | } |
98578b57 | 97 | } else { |
6f8a32d5 PN |
98 | if {$okpattern eq "undefined" || $okpattern eq $retval || [string match $okpattern $retval]} { |
99 | incr ::num_passed | |
100 | if {$::verbose} { | |
101 | puts "PASSED" | |
102 | } else { | |
103 | puts -nonewline "." | |
104 | } | |
d4507ec6 | 105 | } else { |
6f8a32d5 PN |
106 | set msg "Expected '$okpattern' to equal or match '$retval'" |
107 | lappend details $msg | |
108 | lappend ::tests_failed $details | |
109 | ||
110 | incr ::num_failed | |
111 | if {$::verbose} { | |
112 | puts "FAILED" | |
113 | puts "$msg\n" | |
114 | } else { | |
115 | puts -nonewline "F" | |
116 | } | |
d4507ec6 | 117 | } |
98578b57 | 118 | } |
6f8a32d5 PN |
119 | flush stdout |
120 | ||
98578b57 | 121 | if {$::traceleaks} { |
5b12b47d PN |
122 | set output [exec leaks redis-server] |
123 | if {![string match {*0 leaks*} $output]} { | |
6f8a32d5 | 124 | puts "--- Test \"$name\" leaked! ---" |
5b12b47d | 125 | puts $output |
98578b57 PN |
126 | exit 1 |
127 | } | |
128 | } | |
129 | } |