]> git.saurik.com Git - redis.git/blame - tests/support/test.tcl
fix aof and digest code to work with dual set encoding
[redis.git] / tests / support / test.tcl
CommitLineData
98578b57
PN
1set ::passed 0
2set ::failed 0
3set ::testnum 0
4
c2ff0e90
PN
5proc 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
12proc assert_match {pattern value} {
13 if {![string match $pattern $value]} {
14 puts "!! ERROR\nExpected '$value' to match '$pattern'"
15 error "assertion"
16 }
17}
18
19proc 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
26proc 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
35proc assert_encoding {enc key} {
08b59207
PN
36 # swapped out value doesn't have encoding, so swap in first
37 r debug swapin $key
d4507ec6
PN
38 assert_match "* encoding:$enc *" [r debug object $key]
39}
40
41proc assert_type {type key} {
42 assert_equal $type [r type $key]
43}
44
45proc test {name code {okpattern notspecified}} {
6e0e5bed
PN
46 # abort if tagged with a tag to deny
47 foreach tag $::denytags {
48 if {[lsearch $::tags $tag] >= 0} {
49 return
50 }
51 }
52
53 # check if tagged with at least 1 tag to allow when there *is* a list
54 # of tags to allow, because default policy is to run everything
55 if {[llength $::allowtags] > 0} {
56 set matched 0
57 foreach tag $::allowtags {
73bd6c58 58 if {[lsearch $::tags $tag] >= 0} {
6e0e5bed
PN
59 incr matched
60 }
61 }
62 if {$matched < 1} {
63 return
64 }
65 }
66
98578b57 67 incr ::testnum
ab72b483 68 puts -nonewline [format "#%03d %-68s " $::testnum $name]
98578b57 69 flush stdout
fdfb02e7 70 if {[catch {set retval [uplevel 1 $code]} error]} {
d4507ec6
PN
71 if {$error eq "assertion"} {
72 incr ::failed
73 } else {
74 puts "EXCEPTION"
75 puts "\nCaught error: $error"
76 error "exception"
77 }
98578b57 78 } else {
d4507ec6
PN
79 if {$okpattern eq "notspecified" || $okpattern eq $retval || [string match $okpattern $retval]} {
80 puts "PASSED"
81 incr ::passed
82 } else {
83 puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
84 incr ::failed
85 }
98578b57
PN
86 }
87 if {$::traceleaks} {
88 if {![string match {*0 leaks*} [exec leaks redis-server]]} {
89 puts "--------- Test $::testnum LEAKED! --------"
90 exit 1
91 }
92 }
93}