]>
git.saurik.com Git - redis.git/blob - tests/support/test.tcl
0fca618222f0c943560292da0cd9acafed123205
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 # Test if TERM looks like to support colors
49 expr {[info exists
::env(TERM
)] && [string match
*xterm
* $::env(TERM
)]}
52 proc colorstr
{color str
} {
55 if {[string range
$color 0 4] eq
{bold-
}} {
57 set color
[string range
$color 5 end
]
60 red
{set colorcode
{31}}
61 green
{set colorcode
{32}}
62 yellow
{set colorcode
{33}}
63 blue
{set colorcode
{34}}
64 magenta
{set colorcode
{35}}
65 cyan
{set colorcode
{36}}
66 white
{set colorcode
{37}}
67 default {set colorcode
{37}}
69 if {$colorcode ne
{}} {
70 return "\033\[$b;${colorcode};40m$str\033\[0m"
77 proc test
{name code
{okpattern undefined
}} {
78 # abort if tagged with a tag to deny
79 foreach tag
$::denytags {
80 if {[lsearch $::tags $tag] >= 0} {
85 # check if tagged with at least 1 tag to allow when there *is* a list
86 # of tags to allow, because default policy is to run everything
87 if {[llength $::allowtags] > 0} {
89 foreach tag
$::allowtags {
90 if {[lsearch $::tags $tag] >= 0} {
101 lappend details
$::curfile
102 lappend details
$::tags
103 lappend details
$name
105 send_data_packet
$::test_server_fd testing
$name
107 if {[catch {set retval
[uplevel 1 $code]} error]} {
108 if {[string match
"assertion:*" $error]} {
109 set msg
[string range
$error 10 end
]
111 lappend ::tests_failed $details
114 send_data_packet
$::test_server_fd err
$name
116 # Re-raise, let handler up the stack take care of this.
117 error $error $::errorInfo
120 if {$okpattern eq
"undefined" ||
$okpattern eq
$retval ||
[string match
$okpattern $retval]} {
122 send_data_packet
$::test_server_fd ok
$name
124 set msg
"Expected '$okpattern' to equal or match '$retval'"
126 lappend ::tests_failed $details
129 send_data_packet
$::test_server_fd err
$name
134 set output
[exec leaks redis-server
]
135 if {![string match
{*0 leaks
*} $output]} {
136 send_data_packet
$::test_server_fd err
"Detected a memory leak in test '$name': $output"