]> git.saurik.com Git - redis.git/blame_incremental - tests/support/test.tcl
fixed a bug in rdbLoadObject abount specially encoded objects
[redis.git] / tests / support / test.tcl
... / ...
CommitLineData
1set ::passed 0
2set ::failed 0
3set ::testnum 0
4
5proc assert_match {pattern value} {
6 if {![string match $pattern $value]} {
7 puts "!! ERROR\nExpected '$value' to match '$pattern'"
8 error "assertion"
9 }
10}
11
12proc assert_equal {expected value} {
13 if {$expected ne $value} {
14 puts "!! ERROR\nExpected '$value' to be equal to '$expected'"
15 error "assertion"
16 }
17}
18
19proc assert_error {pattern code} {
20 if {[catch $code error]} {
21 assert_match $pattern $error
22 } else {
23 puts "!! ERROR\nExpected an error but nothing was catched"
24 error "assertion"
25 }
26}
27
28proc assert_encoding {enc key} {
29 assert_match "* encoding:$enc *" [r debug object $key]
30}
31
32proc assert_type {type key} {
33 assert_equal $type [r type $key]
34}
35
36proc test {name code {okpattern notspecified}} {
37 # abort if tagged with a tag to deny
38 foreach tag $::denytags {
39 if {[lsearch $::tags $tag] >= 0} {
40 return
41 }
42 }
43
44 # check if tagged with at least 1 tag to allow when there *is* a list
45 # of tags to allow, because default policy is to run everything
46 if {[llength $::allowtags] > 0} {
47 set matched 0
48 foreach tag $::allowtags {
49 if {[lsearch $::tags $tag] >= 0} {
50 incr matched
51 }
52 }
53 if {$matched < 1} {
54 return
55 }
56 }
57
58 incr ::testnum
59 puts -nonewline [format "#%03d %-68s " $::testnum $name]
60 flush stdout
61 if {[catch {set retval [uplevel 1 $code]} error]} {
62 if {$error eq "assertion"} {
63 incr ::failed
64 } else {
65 puts "EXCEPTION"
66 puts "\nCaught error: $error"
67 error "exception"
68 }
69 } else {
70 if {$okpattern eq "notspecified" || $okpattern eq $retval || [string match $okpattern $retval]} {
71 puts "PASSED"
72 incr ::passed
73 } else {
74 puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
75 incr ::failed
76 }
77 }
78 if {$::traceleaks} {
79 if {![string match {*0 leaks*} [exec leaks redis-server]]} {
80 puts "--------- Test $::testnum LEAKED! --------"
81 exit 1
82 }
83 }
84}