]>
git.saurik.com Git - redis.git/blob - tests/test_helper.tcl
6dc85eff37c4a137fad0c382d76af675335f0d52
1 # Redis test suite. Copyright (C) 2009 Salvatore Sanfilippo antirez@gmail.com
2 # This softare is released under the BSD License. See the COPYING file for
6 source tests
/support
/redis.tcl
7 source tests
/support
/server.tcl
8 source tests
/support
/tmpfile.tcl
9 source tests
/support
/test.tcl
10 source tests
/support
/util.tcl
19 set ::external 0; # If "1" this means, we are running against external instance
20 set ::file ""; # If set, runs only the tests in this comma separated list
21 set ::curfile ""; # Hold the filename of the current suite
22 set ::diskstore 0; # Don't touch this by hand. The test itself will toggle it.
24 proc execute_tests name
{
25 set path
"tests/$name.tcl"
30 # Setup a list to hold a stack of server configs. When calls to start_server
31 # are nested, use "srv 0 pid" to get the pid of the inner server. To access
32 # outer servers, use "srv -1 pid" etcetera.
36 if {[string is integer
[lindex $args 0]]} {
37 set level
[lindex $args 0]
38 set property
[lindex $args 1]
40 set property
[lindex $args 0]
42 set srv
[lindex $::servers end
+$level]
43 dict get
$srv $property
46 # Provide easy access to the client for the inner server. It's possible to
47 # prepend the argument list with a negative level to access clients for
48 # servers running in outer blocks.
51 if {[string is integer
[lindex $args 0]]} {
52 set level
[lindex $args 0]
53 set args
[lrange $args 1 end
]
55 [srv
$level "client"] {*}$args
58 proc reconnect
{args
} {
59 set level
[lindex $args 0]
60 if {[string length
$level] == 0 ||
![string is integer
$level]} {
64 set srv
[lindex $::servers end
+$level]
65 set host
[dict get
$srv "host"]
66 set port
[dict get
$srv "port"]
67 set config
[dict get
$srv "config"]
68 set client
[redis
$host $port]
69 dict
set srv
"client" $client
71 # select the right db when we don't have to authenticate
72 if {![dict exists
$config "requirepass"]} {
76 # re-set $srv in the servers list
77 set ::servers [lreplace $::servers end
+$level 1 $srv]
80 proc redis_deferring_client
{args
} {
82 if {[llength $args] > 0 && [string is integer
[lindex $args 0]]} {
83 set level
[lindex $args 0]
84 set args
[lrange $args 1 end
]
87 # create client that defers reading reply
88 set client
[redis
[srv
$level "host"] [srv
$level "port"] 1]
90 # select the right db and read the response (OK)
96 # Provide easy access to INFO properties. Same semantic as "proc r".
99 if {[string is integer
[lindex $args 0]]} {
100 set level
[lindex $args 0]
101 set args
[lrange $args 1 end
]
103 status
[srv
$level "client"] [lindex $args 0]
107 puts "Cleanup: warning may take some time..."
108 catch {exec rm
-rf {*}[glob tests
/tmp
/redis.conf.
*]}
109 catch {exec rm
-rf {*}[glob tests
/tmp
/server.
*]}
112 proc execute_everything
{} {
113 execute_tests
"unit/printver"
114 execute_tests
"unit/auth"
115 execute_tests
"unit/protocol"
116 execute_tests
"unit/basic"
117 execute_tests
"unit/type/list"
118 execute_tests
"unit/type/set"
119 execute_tests
"unit/type/zset"
120 execute_tests
"unit/type/hash"
121 execute_tests
"unit/sort"
122 execute_tests
"unit/expire"
123 execute_tests
"unit/other"
124 execute_tests
"unit/cas"
125 execute_tests
"unit/quit"
126 execute_tests
"integration/replication"
127 execute_tests
"integration/aof"
128 # execute_tests "integration/redis-cli"
129 execute_tests
"unit/pubsub"
131 return; # No diskstore tests for now...
132 # run tests with diskstore enabled
133 puts "\nRunning diskstore tests... this is slow, press Ctrl+C if not interested.."
135 lappend ::denytags nodiskstore
136 set ::global_overrides {diskstore-enabled yes
}
137 execute_tests
"unit/protocol"
138 execute_tests
"unit/basic"
139 execute_tests
"unit/type/list"
140 execute_tests
"unit/type/set"
141 execute_tests
"unit/type/zset"
142 execute_tests
"unit/type/hash"
143 execute_tests
"unit/sort"
144 execute_tests
"unit/expire"
145 execute_tests
"unit/other"
146 execute_tests
"unit/cas"
152 if {[string length
$::file] > 0} {
153 foreach {file} [split $::file ,] {
161 puts "\n[expr $::num_tests] tests, $::num_passed passed, $::num_failed failed\n"
162 if {$::num_failed > 0} {
165 foreach {test
} $::tests_failed {
166 set header
[lindex $test 0]
168 append header
[join [lindex $test 1] ","]
171 if {$curheader ne
$header} {
172 set curheader
$header
176 set name
[lindex $test 2]
177 set msg
[lindex $test 3]
187 for {set j
0} {$j < [llength $argv]} {incr j
} {
188 set opt
[lindex $argv $j]
189 set arg
[lindex $argv [expr $j+1]]
190 if {$opt eq
{--tags}} {
192 if {[string index
$tag 0] eq
"-"} {
193 lappend ::denytags [string range
$tag 1 end
]
195 lappend ::allowtags $tag
199 } elseif
{$opt eq
{--valgrind}} {
201 } elseif
{$opt eq
{--file}} {
204 } elseif
{$opt eq
{--host}} {
208 } elseif
{$opt eq
{--port}} {
211 } elseif
{$opt eq
{--verbose}} {
214 puts "Wrong argument: $opt"
219 if {[catch { main
} err
]} {
220 if {[string length
$err] > 0} {
221 # only display error when not generated by the test suite
222 if {$err ne
"exception"} {