10 proc assert 
{condition
} { 
  11     if {![uplevel 1 [list expr $condition]]} { 
  12         error "assertion:Expected condition '$condition' to be true ([uplevel 1 [list subst -nocommands $condition]])" 
  16 proc assert_match 
{pattern value
} { 
  17     if {![string match 
$pattern $value]} { 
  18         error "assertion:Expected '$value' to match '$pattern'" 
  22 proc assert_equal 
{expected value
} { 
  23     if {$expected ne 
$value} { 
  24         error "assertion:Expected '$value' to be equal to '$expected'" 
  28 proc assert_error 
{pattern code
} { 
  29     if {[catch {uplevel 1 $code} error]} { 
  30         assert_match 
$pattern $error 
  32         error "assertion:Expected an error but nothing was catched" 
  36 proc assert_encoding 
{enc key
} { 
  37     # Swapped out values don't have an encoding, so make sure that 
  38     # the value is swapped in before checking the encoding. 
  39     set dbg 
[r debug object 
$key] 
  40     while {[string match 
"* swapped at:*" $dbg]} { 
  42         set dbg 
[r debug object 
$key] 
  44     assert_match 
"* encoding:$enc *" $dbg 
  47 proc assert_type 
{type key
} { 
  48     assert_equal 
$type [r type 
$key] 
  51 # Wait for the specified condition to be true, with the specified number of 
  52 # max retries and delay between retries. Otherwise the 'elsescript' is 
  54 proc wait_for_condition 
{maxtries delay e _else_ elsescript
} { 
  55     while {[incr maxtries 
-1] >= 0} { 
  56         if {[uplevel 1 [list expr $e]]} break 
  59     if {$maxtries == -1} { 
  64 # Test if TERM looks like to support colors 
  66     expr {[info exists 
::env(TERM
)] && [string match 
*xterm
* $::env(TERM
)]} 
  69 proc colorstr 
{color str
} { 
  72         if {[string range 
$color 0 4] eq 
{bold-
}} { 
  74             set color 
[string range 
$color 5 end
] 
  77             red 
{set colorcode 
{31}} 
  78             green 
{set colorcode 
{32}} 
  79             yellow 
{set colorcode 
{33}} 
  80             blue 
{set colorcode 
{34}} 
  81             magenta 
{set colorcode 
{35}} 
  82             cyan 
{set colorcode 
{36}} 
  83             white 
{set colorcode 
{37}} 
  84             default {set colorcode 
{37}} 
  86         if {$colorcode ne 
{}} { 
  87             return "\033\[$b;${colorcode};40m$str\033\[0m" 
  94 proc test 
{name code 
{okpattern undefined
}} { 
  95     # abort if tagged with a tag to deny 
  96     foreach tag 
$::denytags { 
  97         if {[lsearch $::tags $tag] >= 0} { 
 102     # check if tagged with at least 1 tag to allow when there *is* a list 
 103     # of tags to allow, because default policy is to run everything 
 104     if {[llength $::allowtags] > 0} { 
 106         foreach tag 
$::allowtags { 
 107             if {[lsearch $::tags $tag] >= 0} { 
 118     lappend details 
"$name in $::curfile" 
 120     send_data_packet 
$::test_server_fd testing 
$name 
 122     if {[catch {set retval 
[uplevel 1 $code]} error]} { 
 123         if {[string match 
"assertion:*" $error]} { 
 124             set msg 
[string range 
$error 10 end
] 
 126             lappend ::tests_failed $details 
 129             send_data_packet 
$::test_server_fd err 
[join $details "\n"] 
 131             # Re-raise, let handler up the stack take care of this. 
 132             error $error $::errorInfo 
 135         if {$okpattern eq 
"undefined" || 
$okpattern eq 
$retval || 
[string match 
$okpattern $retval]} { 
 137             send_data_packet 
$::test_server_fd ok 
$name 
 139             set msg 
"Expected '$okpattern' to equal or match '$retval'" 
 141             lappend ::tests_failed $details 
 144             send_data_packet 
$::test_server_fd err 
[join $details "\n"] 
 149         set output 
[exec leaks redis-server
] 
 150         if {![string match 
{*0 leaks
*} $output]} { 
 151             send_data_packet 
$::test_server_fd err 
"Detected a memory leak in test '$name': $output"