Merge pull request #6513 from oranagra/test_assertions
test infra: improve prints on failed assertions
This commit is contained in:
commit
397a8b57cc
@ -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"
|
||||
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 between to '$min' and '$max' $detail"
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user