]>
git.saurik.com Git - redis.git/blob - tests/support/test.tcl
6 proc assert
{condition
} {
7 if {![uplevel 1 expr $condition]} {
8 error "assertion:Expected '$value' to be true"
12 proc assert_match
{pattern value
} {
13 if {![string match
$pattern $value]} {
14 error "assertion:Expected '$value' to match '$pattern'"
18 proc assert_equal
{expected value
} {
19 if {$expected ne
$value} {
20 error "assertion:Expected '$value' to be equal to '$expected'"
24 proc assert_error
{pattern code
} {
25 if {[catch {uplevel 1 $code} error]} {
26 assert_match
$pattern $error
28 error "assertion:Expected an error but nothing was catched"
32 proc assert_encoding
{enc key
} {
33 # Swapped out values don't have an encoding, so make sure that
34 # the value is swapped in before checking the encoding.
35 set dbg
[r debug object
$key]
36 while {[string match
"* swapped at:*" $dbg]} {
38 set dbg
[r debug object
$key]
40 assert_match
"* encoding:$enc *" $dbg
43 proc assert_type
{type key
} {
44 assert_equal
$type [r type
$key]
47 # This is called before starting the test
48 proc announce_test
{s
} {
49 if {[info exists
::env(TERM
)] && [string match
$::env(TERM
) xterm
]} {
50 puts -nonewline "$s\033\[0K"
52 set ::backward_count [string length
$s]
56 # This is called after the test finished
57 proc colored_dot
{tags passed
} {
58 if {[info exists
::env(TERM
)] && [string match
$::env(TERM
) xterm
]} {
59 # Go backward and delete what announc_test function printed.
60 puts -nonewline "\033\[${::backward_count}D\033\[0K\033\[J"
62 # Print a coloured char, accordingly to test outcome and tags.
63 if {[lsearch $tags list] != -1} {
66 } elseif
{[lsearch $tags hash
] != -1} {
69 } elseif
{[lsearch $tags set] != -1} {
72 } elseif
{[lsearch $tags zset
] != -1} {
75 } elseif
{[lsearch $tags basic
] != -1} {
82 if {$colorcode ne
{}} {
84 puts -nonewline "\033\[0;${colorcode};40m"
86 puts -nonewline "\033\[7;${colorcode};40m"
89 puts -nonewline "\033\[0m"
101 proc test
{name code
{okpattern undefined
}} {
102 # abort if tagged with a tag to deny
103 foreach tag
$::denytags {
104 if {[lsearch $::tags $tag] >= 0} {
109 # check if tagged with at least 1 tag to allow when there *is* a list
110 # of tags to allow, because default policy is to run everything
111 if {[llength $::allowtags] > 0} {
113 foreach tag
$::allowtags {
114 if {[lsearch $::tags $tag] >= 0} {
125 lappend details
$::curfile
126 lappend details
$::tags
127 lappend details
$name
130 puts -nonewline [format "#%03d %-68s " $::num_tests $name]
136 if {[catch {set retval
[uplevel 1 $code]} error]} {
137 if {[string match
"assertion:*" $error]} {
138 set msg
[string range
$error 10 end
]
140 lappend ::tests_failed $details
147 colored_dot
$::tags 0
150 # Re-raise, let handler up the stack take care of this.
151 error $error $::errorInfo
154 if {$okpattern eq
"undefined" ||
$okpattern eq
$retval ||
[string match
$okpattern $retval]} {
159 colored_dot
$::tags 1
162 set msg
"Expected '$okpattern' to equal or match '$retval'"
164 lappend ::tests_failed $details
171 colored_dot
$::tags 0
178 set output
[exec leaks redis-server
]
179 if {![string match
{*0 leaks
*} $output]} {
180 puts "--- Test \"$name\" leaked! ---"