summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2019-10-29 17:29:06 +0200
committerOran Agra <oran@redislabs.com>2019-10-29 17:38:12 +0200
commita0cfd519e3cbbb4c432d25094e4cb202631f131f (patch)
tree095b061186923ffda0e571b4b58ba8e083160783 /tests
parent764b420f5fddfe177638828a43c921eb949b140c (diff)
downloadredis-a0cfd519e3cbbb4c432d25094e4cb202631f131f.tar.gz
test infra: improve prints on failed assertions
sometimes we have several assertions with the same condition in the same test at different stages, and when these fail (the ones that print the condition text) you don't know which one it was. other assertions didn't print the condition text (variable names), just the expected and unexpected values. So now, all assertions print context line, and conditin text. besides, one of the major differences between 'assert' and 'assert_equal', is that the later is able to print the value that doesn't match the expected. if there is a rare non-reproducible failure, it is helpful to know what was the value the test encountered and how far it was from the threshold. So now, adding assert_lessthan and assert_range that can be used in some places. were we used just 'assert { a > b }' so far.
Diffstat (limited to 'tests')
-rw-r--r--tests/support/test.tcl39
1 files changed, 33 insertions, 6 deletions
diff --git a/tests/support/test.tcl b/tests/support/test.tcl
index 2646acecd..5e8916236 100644
--- a/tests/support/test.tcl
+++ b/tests/support/test.tcl
@@ -11,28 +11,55 @@ proc fail {msg} {
proc assert {condition} {
if {![uplevel 1 [list expr $condition]]} {
- error "assertion:Expected condition '$condition' to be true ([uplevel 1 [list subst -nocommands $condition]])"
+ set context "(context: [info frame -1])"
+ error "assertion:Expected [uplevel 1 [list subst -nocommands $condition]] $context"
}
}
proc assert_no_match {pattern value} {
if {[string match $pattern $value]} {
- error "assertion:Expected '$value' to not match '$pattern'"
+ set context "(context: [info frame -1])"
+ error "assertion:Expected '$value' to not match '$pattern' $context"
}
}
proc assert_match {pattern value} {
if {![string match $pattern $value]} {
- error "assertion:Expected '$value' to match '$pattern'"
+ set context "(context: [info frame -1])"
+ error "assertion:Expected '$value' to match '$pattern' $context"
}
}
-proc assert_equal {expected value {detail ""}} {
+proc assert_equal {value expected {detail ""}} {
if {$expected ne $value} {
if {$detail ne ""} {
- set detail " (detail: $detail)"
+ set detail "(detail: $detail)"
+ } else {
+ set detail "(context: [info frame -1])"
+ }
+ error "assertion:Expected '$value' to be equal to '$expected' $detail"
+ }
+}
+
+proc assert_lessthan {value expected {detail ""}} {
+ if {!($value < $expected)} {
+ if {$detail ne ""} {
+ set detail "(detail: $detail)"
+ } else {
+ set detail "(context: [info frame -1])"
+ }
+ error "assertion:Expected '$value' to be lessthan to '$expected' $detail"
+ }
+}
+
+proc assert_range {value min max {detail ""}} {
+ if {!($value <= $max && $value >= $min)} {
+ if {$detail ne ""} {
+ set detail "(detail: $detail)"
+ } else {
+ set detail "(context: [info frame -1])"
}
- error "assertion:Expected '$value' to be equal to '$expected'$detail"
+ error "assertion:Expected '$value' to be between to '$min' and '$max' $detail"
}
}