Commit d4507ec6 authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

refactor list tests to test both encodings; implemented assert functions

parent d1578a33
...@@ -2,7 +2,38 @@ set ::passed 0 ...@@ -2,7 +2,38 @@ set ::passed 0
set ::failed 0 set ::failed 0
set ::testnum 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 # abort if tagged with a tag to deny
foreach tag $::denytags { foreach tag $::denytags {
if {[lsearch $::tags $tag] >= 0} { if {[lsearch $::tags $tag] >= 0} {
...@@ -28,16 +59,21 @@ proc test {name code okpattern} { ...@@ -28,16 +59,21 @@ proc test {name code okpattern} {
puts -nonewline [format "#%03d %-68s " $::testnum $name] puts -nonewline [format "#%03d %-68s " $::testnum $name]
flush stdout flush stdout
if {[catch {set retval [uplevel 1 $code]} error]} { if {[catch {set retval [uplevel 1 $code]} error]} {
puts "EXCEPTION" if {$error eq "assertion"} {
puts "\nCaught error: $error" incr ::failed
error "exception" } else {
} puts "EXCEPTION"
if {$okpattern eq $retval || [string match $okpattern $retval]} { puts "\nCaught error: $error"
puts "PASSED" error "exception"
incr ::passed }
} else { } else {
puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'" if {$okpattern eq "notspecified" || $okpattern eq $retval || [string match $okpattern $retval]} {
incr ::failed puts "PASSED"
incr ::passed
} else {
puts "!! ERROR expected\n'$okpattern'\nbut got\n'$retval'"
incr ::failed
}
} }
if {$::traceleaks} { if {$::traceleaks} {
if {![string match {*0 leaks*} [exec leaks redis-server]]} { if {![string match {*0 leaks*} [exec leaks redis-server]]} {
......
...@@ -73,7 +73,7 @@ proc main {} { ...@@ -73,7 +73,7 @@ proc main {} {
execute_tests "integration/aof" execute_tests "integration/aof"
# run tests with VM enabled # 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/protocol"
execute_tests "unit/basic" execute_tests "unit/basic"
execute_tests "unit/type/list" execute_tests "unit/type/list"
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment