summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2010-07-12 15:28:31 -0400
committerPieter Noordhuis <pcnoordhuis@gmail.com>2010-07-12 15:35:11 -0400
commit75d675d954f64d3a9c6a68821f5d42c76fb9ca9d (patch)
tree6dc03ba2fce895b8903545d2cc8241a632dd4346
parent243b914bd6949351b873059747ea17b2bced1107 (diff)
downloadredis-75d675d954f64d3a9c6a68821f5d42c76fb9ca9d.tar.gz
partial cherry-pick of d4507ec6 to import assertion functions
-rw-r--r--tests/support/test.tcl56
1 files changed, 46 insertions, 10 deletions
diff --git a/tests/support/test.tcl b/tests/support/test.tcl
index d2674da19..4caa6ca79 100644
--- a/tests/support/test.tcl
+++ b/tests/support/test.tcl
@@ -2,7 +2,38 @@ set ::passed 0
set ::failed 0
set ::testnum 0
-proc test {name code okpattern} {
+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 $code error]} {
+ assert_match $pattern $error
+ } else {
+ puts "!! ERROR\nExpected an error but nothing was catched"
+ error "assertion"
+ }
+}
+
+proc assert_encoding {enc 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} {
@@ -28,16 +59,21 @@ proc test {name code okpattern} {
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]]} {