]>
git.saurik.com Git - redis.git/blob - tests/support/test.tcl
5 proc assert
{condition
} {
6 if {![uplevel 1 expr $condition]} {
7 puts "!! ERROR\nExpected '$value' to evaluate to true"
12 proc assert_match
{pattern value
} {
13 if {![string match
$pattern $value]} {
14 puts "!! ERROR\nExpected '$value' to match '$pattern'"
19 proc assert_equal
{expected value
} {
20 if {$expected ne
$value} {
21 puts "!! ERROR\nExpected '$value' to be equal to '$expected'"
26 proc assert_error
{pattern code
} {
27 if {[catch {uplevel 1 $code} error]} {
28 assert_match
$pattern $error
30 puts "!! ERROR\nExpected an error but nothing was catched"
35 proc assert_encoding
{enc key
} {
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]
39 while {[string match
"* swapped at:*" $dbg]} {
41 set dbg
[r debug object
$key]
43 assert_match
"* encoding:$enc *" $dbg
46 proc assert_type
{type key
} {
47 assert_equal
$type [r type
$key]
50 proc test
{name code
{okpattern notspecified
}} {
51 # abort if tagged with a tag to deny
52 foreach tag
$::denytags {
53 if {[lsearch $::tags $tag] >= 0} {
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} {
62 foreach tag
$::allowtags {
63 if {[lsearch $::tags $tag] >= 0} {
73 puts -nonewline [format "#%03d %-68s " $::testnum $name]
75 if {[catch {set retval
[uplevel 1 $code]} error]} {
76 if {$error eq
"assertion"} {
80 puts "\nCaught error: $error"
84 if {$okpattern eq
"notspecified" ||
$okpattern eq
$retval ||
[string match
$okpattern $retval]} {
88 puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
93 if {![string match
{*0 leaks
*} [exec leaks redis-server
]]} {
94 puts "--------- Test $::testnum LEAKED! --------"