2010-05-14 15:31:11 +00:00
|
|
|
set ::passed 0
|
|
|
|
set ::failed 0
|
|
|
|
set ::testnum 0
|
|
|
|
|
2010-06-16 09:03:23 +00:00
|
|
|
proc assert {condition} {
|
|
|
|
if {![uplevel 1 expr $condition]} {
|
|
|
|
puts "!! ERROR\nExpected '$value' to evaluate to true"
|
|
|
|
error "assertion"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-04 14:30:54 +00:00
|
|
|
proc assert_match {pattern value} {
|
|
|
|
if {![string match $pattern $value]} {
|
|
|
|
puts "!! ERROR\nExpected '$value' to match '$pattern'"
|
|
|
|
error "assertion"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc assert_equal {expected value} {
|
|
|
|
if {$expected ne $value} {
|
|
|
|
puts "!! ERROR\nExpected '$value' to be equal to '$expected'"
|
|
|
|
error "assertion"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc assert_error {pattern code} {
|
2010-06-15 19:16:27 +00:00
|
|
|
if {[catch {uplevel 1 $code} error]} {
|
2010-06-04 14:30:54 +00:00
|
|
|
assert_match $pattern $error
|
|
|
|
} else {
|
|
|
|
puts "!! ERROR\nExpected an error but nothing was catched"
|
|
|
|
error "assertion"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
proc assert_encoding {enc key} {
|
2010-06-14 07:45:34 +00:00
|
|
|
# swapped out value doesn't have encoding, so swap in first
|
|
|
|
r debug swapin $key
|
2010-06-04 14:30:54 +00:00
|
|
|
assert_match "* encoding:$enc *" [r debug object $key]
|
|
|
|
}
|
|
|
|
|
|
|
|
proc assert_type {type key} {
|
|
|
|
assert_equal $type [r type $key]
|
|
|
|
}
|
|
|
|
|
|
|
|
proc test {name code {okpattern notspecified}} {
|
2010-06-02 20:53:22 +00:00
|
|
|
# abort if tagged with a tag to deny
|
|
|
|
foreach tag $::denytags {
|
|
|
|
if {[lsearch $::tags $tag] >= 0} {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# check if tagged with at least 1 tag to allow when there *is* a list
|
|
|
|
# of tags to allow, because default policy is to run everything
|
|
|
|
if {[llength $::allowtags] > 0} {
|
|
|
|
set matched 0
|
|
|
|
foreach tag $::allowtags {
|
2010-06-02 21:04:22 +00:00
|
|
|
if {[lsearch $::tags $tag] >= 0} {
|
2010-06-02 20:53:22 +00:00
|
|
|
incr matched
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if {$matched < 1} {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-14 15:31:11 +00:00
|
|
|
incr ::testnum
|
2010-05-14 16:48:33 +00:00
|
|
|
puts -nonewline [format "#%03d %-68s " $::testnum $name]
|
2010-05-14 15:31:11 +00:00
|
|
|
flush stdout
|
2010-05-15 21:48:08 +00:00
|
|
|
if {[catch {set retval [uplevel 1 $code]} error]} {
|
2010-06-04 14:30:54 +00:00
|
|
|
if {$error eq "assertion"} {
|
|
|
|
incr ::failed
|
|
|
|
} else {
|
|
|
|
puts "EXCEPTION"
|
|
|
|
puts "\nCaught error: $error"
|
|
|
|
error "exception"
|
|
|
|
}
|
2010-05-14 15:31:11 +00:00
|
|
|
} else {
|
2010-06-04 14:30:54 +00:00
|
|
|
if {$okpattern eq "notspecified" || $okpattern eq $retval || [string match $okpattern $retval]} {
|
|
|
|
puts "PASSED"
|
|
|
|
incr ::passed
|
|
|
|
} else {
|
|
|
|
puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
|
|
|
|
incr ::failed
|
|
|
|
}
|
2010-05-14 15:31:11 +00:00
|
|
|
}
|
|
|
|
if {$::traceleaks} {
|
|
|
|
if {![string match {*0 leaks*} [exec leaks redis-server]]} {
|
|
|
|
puts "--------- Test $::testnum LEAKED! --------"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|