]>
git.saurik.com Git - redis.git/blob - tests/support/test.tcl
c70cc049a9750cc0649a8af97b450d1cf76a84d6
6 proc assert
{condition
} {
7 if {![uplevel 1 expr $condition]} {
8 error "assertion:Expected '$value' to be true"
12 proc assert_match
{pattern value
} {
13 if {![string match
$pattern $value]} {
14 error "assertion:Expected '$value' to match '$pattern'"
18 proc assert_equal
{expected value
} {
19 if {$expected ne
$value} {
20 error "assertion:Expected '$value' to be equal to '$expected'"
24 proc assert_error
{pattern code
} {
25 if {[catch {uplevel 1 $code} error]} {
26 assert_match
$pattern $error
28 error "assertion:Expected an error but nothing was catched"
32 proc assert_encoding
{enc key
} {
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]
36 while {[string match
"* swapped at:*" $dbg]} {
38 set dbg
[r debug object
$key]
40 assert_match
"* encoding:$enc *" $dbg
43 proc assert_type
{type key
} {
44 assert_equal
$type [r type
$key]
47 proc colored_dot
{tags passed
} {
48 if {[info exists
::env(TERM
)] && [string match
$::env(TERM
) xterm
]} {
49 if {[lsearch $tags list] != -1} {
52 } elseif
{[lsearch $tags hash
] != -1} {
55 } elseif
{[lsearch $tags set] != -1} {
58 } elseif
{[lsearch $tags zset
] != -1} {
61 } elseif
{[lsearch $tags basic
] != -1} {
68 if {$colorcode ne
{}} {
70 puts -nonewline "\033\[0;${colorcode};40m"
72 puts -nonewline "\033\[0;40;${colorcode}m"
75 puts -nonewline "\033\[0m"
87 proc test
{name code
{okpattern undefined
}} {
88 # abort if tagged with a tag to deny
89 foreach tag
$::denytags {
90 if {[lsearch $::tags $tag] >= 0} {
95 # check if tagged with at least 1 tag to allow when there *is* a list
96 # of tags to allow, because default policy is to run everything
97 if {[llength $::allowtags] > 0} {
99 foreach tag
$::allowtags {
100 if {[lsearch $::tags $tag] >= 0} {
111 lappend details
$::curfile
112 lappend details
$::tags
113 lappend details
$name
116 puts -nonewline [format "#%03d %-68s " $::num_tests $name]
120 if {[catch {set retval
[uplevel 1 $code]} error]} {
121 if {[string match
"assertion:*" $error]} {
122 set msg
[string range
$error 10 end
]
124 lappend ::tests_failed $details
131 colored_dot
$::tags 0
134 # Re-raise, let handler up the stack take care of this.
135 error $error $::errorInfo
138 if {$okpattern eq
"undefined" ||
$okpattern eq
$retval ||
[string match
$okpattern $retval]} {
143 colored_dot
$::tags 1
146 set msg
"Expected '$okpattern' to equal or match '$retval'"
148 lappend ::tests_failed $details
155 colored_dot
$::tags 0
162 set output
[exec leaks redis-server
]
163 if {![string match
{*0 leaks
*} $output]} {
164 puts "--- Test \"$name\" leaked! ---"