]>
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 value doesn't have encoding, so swap in first
38 assert_match
"* encoding:$enc *" [r debug object
$key]
41 proc assert_type
{type key
} {
42 assert_equal
$type [r type
$key]
45 proc test
{name code
{okpattern notspecified
}} {
46 # abort if tagged with a tag to deny
47 foreach tag
$::denytags {
48 if {[lsearch $::tags $tag] >= 0} {
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} {
57 foreach tag
$::allowtags {
58 if {[lsearch $::tags $tag] >= 0} {
68 puts -nonewline [format "#%03d %-68s " $::testnum $name]
70 if {[catch {set retval
[uplevel 1 $code]} error]} {
71 if {$error eq
"assertion"} {
75 puts "\nCaught error: $error"
79 if {$okpattern eq
"notspecified" ||
$okpattern eq
$retval ||
[string match
$okpattern $retval]} {
83 puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
88 if {![string match
{*0 leaks
*} [exec leaks redis-server
]]} {
89 puts "--------- Test $::testnum LEAKED! --------"