Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
397a8b57
Unverified
Commit
397a8b57
authored
Nov 19, 2019
by
Salvatore Sanfilippo
Committed by
GitHub
Nov 19, 2019
Browse files
Merge pull request #6513 from oranagra/test_assertions
test infra: improve prints on failed assertions
parents
ce03d683
a0cfd519
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/support/test.tcl
View file @
397a8b57
...
@@ -11,28 +11,55 @@ proc fail {msg} {
...
@@ -11,28 +11,55 @@ proc fail {msg} {
proc assert
{
condition
}
{
proc assert
{
condition
}
{
if
{
!
[
uplevel 1
[
list expr $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
}
{
proc assert_no_match
{
pattern value
}
{
if
{[
string 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
}
{
proc assert_match
{
pattern value
}
{
if
{
!
[
string 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
{
$expected
ne $value
}
{
if
{
$detail
ne
""
}
{
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
"
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment