Skip to content

Commit

Permalink
refactor list tests to test both encodings; implemented assert functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Jun 4, 2010
1 parent d1578a3 commit d4507ec
Show file tree
Hide file tree
Showing 3 changed files with 436 additions and 268 deletions.
56 changes: 46 additions & 10 deletions tests/support/test.tcl
Expand Up @@ -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} {
Expand All @@ -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]]} {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_helper.tcl
Expand Up @@ -73,7 +73,7 @@ proc main {} {
execute_tests "integration/aof"

# run tests with VM enabled
set ::global_overrides [list [list vm-enabled yes]]
set ::global_overrides {vm-enabled yes}
execute_tests "unit/protocol"
execute_tests "unit/basic"
execute_tests "unit/type/list"
Expand Down

0 comments on commit d4507ec

Please sign in to comment.