]>
Commit | Line | Data |
---|---|---|
98578b57 PN |
1 | set ::passed 0 |
2 | set ::failed 0 | |
3 | set ::testnum 0 | |
4 | ||
c2ff0e90 PN |
5 | proc assert {condition} { |
6 | if {![uplevel 1 expr $condition]} { | |
7 | puts "!! ERROR\nExpected '$value' to evaluate to true" | |
8 | error "assertion" | |
9 | } | |
10 | } | |
11 | ||
d4507ec6 PN |
12 | proc assert_match {pattern value} { |
13 | if {![string match $pattern $value]} { | |
14 | puts "!! ERROR\nExpected '$value' to match '$pattern'" | |
15 | error "assertion" | |
16 | } | |
17 | } | |
18 | ||
19 | proc assert_equal {expected value} { | |
20 | if {$expected ne $value} { | |
21 | puts "!! ERROR\nExpected '$value' to be equal to '$expected'" | |
22 | error "assertion" | |
23 | } | |
24 | } | |
25 | ||
26 | proc assert_error {pattern code} { | |
5eedc9c6 | 27 | if {[catch {uplevel 1 $code} error]} { |
d4507ec6 PN |
28 | assert_match $pattern $error |
29 | } else { | |
30 | puts "!! ERROR\nExpected an error but nothing was catched" | |
31 | error "assertion" | |
32 | } | |
33 | } | |
34 | ||
35 | proc assert_encoding {enc key} { | |
86d39249 PN |
36 | # Swapped out values don't have an encoding, so make sure that |
37 | # the value is swapped in before checking the encoding. | |
38 | set dbg [r debug object $key] | |
68254919 PN |
39 | while {[string match "* swapped at:*" $dbg]} { |
40 | r debug swapin $key | |
86d39249 PN |
41 | set dbg [r debug object $key] |
42 | } | |
43 | assert_match "* encoding:$enc *" $dbg | |
d4507ec6 PN |
44 | } |
45 | ||
46 | proc assert_type {type key} { | |
47 | assert_equal $type [r type $key] | |
48 | } | |
49 | ||
50 | proc test {name code {okpattern notspecified}} { | |
6e0e5bed PN |
51 | # abort if tagged with a tag to deny |
52 | foreach tag $::denytags { | |
53 | if {[lsearch $::tags $tag] >= 0} { | |
54 | return | |
55 | } | |
56 | } | |
57 | ||
58 | # check if tagged with at least 1 tag to allow when there *is* a list | |
59 | # of tags to allow, because default policy is to run everything | |
60 | if {[llength $::allowtags] > 0} { | |
61 | set matched 0 | |
62 | foreach tag $::allowtags { | |
73bd6c58 | 63 | if {[lsearch $::tags $tag] >= 0} { |
6e0e5bed PN |
64 | incr matched |
65 | } | |
66 | } | |
67 | if {$matched < 1} { | |
68 | return | |
69 | } | |
70 | } | |
71 | ||
98578b57 | 72 | incr ::testnum |
ab72b483 | 73 | puts -nonewline [format "#%03d %-68s " $::testnum $name] |
98578b57 | 74 | flush stdout |
fdfb02e7 | 75 | if {[catch {set retval [uplevel 1 $code]} error]} { |
d4507ec6 PN |
76 | if {$error eq "assertion"} { |
77 | incr ::failed | |
78 | } else { | |
79 | puts "EXCEPTION" | |
80 | puts "\nCaught error: $error" | |
81 | error "exception" | |
82 | } | |
98578b57 | 83 | } else { |
d4507ec6 PN |
84 | if {$okpattern eq "notspecified" || $okpattern eq $retval || [string match $okpattern $retval]} { |
85 | puts "PASSED" | |
86 | incr ::passed | |
87 | } else { | |
88 | puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'" | |
89 | incr ::failed | |
90 | } | |
98578b57 PN |
91 | } |
92 | if {$::traceleaks} { | |
5b12b47d PN |
93 | set output [exec leaks redis-server] |
94 | if {![string match {*0 leaks*} $output]} { | |
98578b57 | 95 | puts "--------- Test $::testnum LEAKED! --------" |
5b12b47d | 96 | puts $output |
98578b57 PN |
97 | exit 1 |
98 | } | |
99 | } | |
100 | } |