X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/82e5dd35ea99692cc10077be95485242a9b352a3..0bd6d68e34bc41cd80cd7fc44aab9cf3884de8dc:/tests/support/test.tcl diff --git a/tests/support/test.tcl b/tests/support/test.tcl index 0fca6182..480c674e 100644 --- a/tests/support/test.tcl +++ b/tests/support/test.tcl @@ -3,9 +3,13 @@ set ::num_passed 0 set ::num_failed 0 set ::tests_failed {} +proc fail {msg} { + error "assertion:$msg" +} + proc assert {condition} { - if {![uplevel 1 expr $condition]} { - error "assertion:Expected '$value' to be true" + if {![uplevel 1 [list expr $condition]]} { + error "assertion:Expected condition '$condition' to be true ([uplevel 1 [list subst -nocommands $condition]])" } } @@ -44,6 +48,19 @@ proc assert_type {type key} { assert_equal $type [r type $key] } +# Wait for the specified condition to be true, with the specified number of +# max retries and delay between retries. Otherwise the 'elsescript' is +# executed. +proc wait_for_condition {maxtries delay e _else_ elsescript} { + while {[incr maxtries -1] >= 0} { + if {[uplevel 1 [list expr $e]]} break + after $delay + } + if {$maxtries == -1} { + uplevel 1 $elsescript + } +} + # Test if TERM looks like to support colors proc color_term {} { expr {[info exists ::env(TERM)] && [string match *xterm* $::env(TERM)]} @@ -98,9 +115,7 @@ proc test {name code {okpattern undefined}} { incr ::num_tests set details {} - lappend details $::curfile - lappend details $::tags - lappend details $name + lappend details "$name in $::curfile" send_data_packet $::test_server_fd testing $name @@ -111,7 +126,7 @@ proc test {name code {okpattern undefined}} { lappend ::tests_failed $details incr ::num_failed - send_data_packet $::test_server_fd err $name + send_data_packet $::test_server_fd err [join $details "\n"] } else { # Re-raise, let handler up the stack take care of this. error $error $::errorInfo @@ -126,7 +141,7 @@ proc test {name code {okpattern undefined}} { lappend ::tests_failed $details incr ::num_failed - send_data_packet $::test_server_fd err $name + send_data_packet $::test_server_fd err [join $details "\n"] } }