X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/436f18b618d3820ee3c99b2ae78cf29bf36b2994..6171250871e408928a172c09d5fdf41961720fbc:/tests/support/test.tcl diff --git a/tests/support/test.tcl b/tests/support/test.tcl index 1fdeb1e9..2c1fc164 100644 --- a/tests/support/test.tcl +++ b/tests/support/test.tcl @@ -2,22 +2,87 @@ set ::passed 0 set ::failed 0 set ::testnum 0 -proc test {name code okpattern} { +proc assert {condition} { + if {![uplevel 1 expr $condition]} { + puts "!! ERROR\nExpected '$value' to evaluate to true" + error "assertion" + } +} + +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} { + if {[catch {uplevel 1 $code} error]} { + assert_match $pattern $error + } else { + puts "!! ERROR\nExpected an error but nothing was catched" + error "assertion" + } +} + +proc assert_encoding {enc key} { + # swapped out value doesn't have encoding, so swap in first + r debug swapin $key + 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}} { + # 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 { + if {[lsearch $::tags $tag] >= 0} { + incr matched + } + } + if {$matched < 1} { + return + } + } + incr ::testnum - # if {$::testnum < $::first || $::testnum > $::last} return puts -nonewline [format "#%03d %-68s " $::testnum $name] flush stdout if {[catch {set retval [uplevel 1 $code]} error]} { - puts "EXCEPTION" - puts "\nCaught error: $error" - error "exception" - } - if {$okpattern eq $retval || [string match $okpattern $retval]} { - puts "PASSED" - incr ::passed + if {$error eq "assertion"} { + incr ::failed + } else { + puts "EXCEPTION" + puts "\nCaught error: $error" + error "exception" + } } else { - puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'" - incr ::failed + 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 + } } if {$::traceleaks} { if {![string match {*0 leaks*} [exec leaks redis-server]]} {