]> git.saurik.com Git - redis.git/blame - tests/test_helper.tcl
Merge remote branch 'pietern/intset-split'
[redis.git] / tests / test_helper.tcl
CommitLineData
98578b57
PN
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
3# more information.
4
5set tcl_precision 17
ab72b483 6source tests/support/redis.tcl
7source tests/support/server.tcl
8source tests/support/tmpfile.tcl
9source tests/support/test.tcl
10source tests/support/util.tcl
98578b57
PN
11
12set ::host 127.0.0.1
47bebf15 13set ::port 16379
98578b57 14set ::traceleaks 0
c4669d25 15set ::valgrind 0
6e0e5bed
PN
16set ::denytags {}
17set ::allowtags {}
7d04fc75 18set ::external 0; # If "1" this means, we are running against external instance
98578b57
PN
19
20proc execute_tests name {
ab72b483 21 source "tests/$name.tcl"
98578b57
PN
22}
23
1c4114be
PN
24# Setup a list to hold a stack of server configs. When calls to start_server
25# are nested, use "srv 0 pid" to get the pid of the inner server. To access
26# outer servers, use "srv -1 pid" etcetera.
27set ::servers {}
f2dd4769
PN
28proc srv {args} {
29 set level 0
30 if {[string is integer [lindex $args 0]]} {
31 set level [lindex $args 0]
32 set property [lindex $args 1]
33 } else {
34 set property [lindex $args 0]
35 }
1c4114be
PN
36 set srv [lindex $::servers end+$level]
37 dict get $srv $property
38}
39
40# Provide easy access to the client for the inner server. It's possible to
41# prepend the argument list with a negative level to access clients for
42# servers running in outer blocks.
98578b57 43proc r {args} {
1c4114be
PN
44 set level 0
45 if {[string is integer [lindex $args 0]]} {
46 set level [lindex $args 0]
47 set args [lrange $args 1 end]
48 }
49 [srv $level "client"] {*}$args
50}
51
5eedc9c6
PN
52proc redis_deferring_client {args} {
53 set level 0
54 if {[llength $args] > 0 && [string is integer [lindex $args 0]]} {
55 set level [lindex $args 0]
56 set args [lrange $args 1 end]
57 }
58
59 # create client that defers reading reply
60 set client [redis [srv $level "host"] [srv $level "port"] 1]
61
62 # select the right db and read the response (OK)
63 $client select 9
64 $client read
65 return $client
66}
67
1c4114be
PN
68# Provide easy access to INFO properties. Same semantic as "proc r".
69proc s {args} {
70 set level 0
71 if {[string is integer [lindex $args 0]]} {
72 set level [lindex $args 0]
73 set args [lrange $args 1 end]
74 }
75 status [srv $level "client"] [lindex $args 0]
98578b57
PN
76}
77
f166bb1d 78proc cleanup {} {
c4669d25 79 catch {exec rm -rf {*}[glob tests/tmp/redis.conf.*]}
80 catch {exec rm -rf {*}[glob tests/tmp/server.*]}
f166bb1d
PN
81}
82
98578b57 83proc main {} {
f166bb1d 84 cleanup
98578b57
PN
85 execute_tests "unit/auth"
86 execute_tests "unit/protocol"
87 execute_tests "unit/basic"
88 execute_tests "unit/type/list"
89 execute_tests "unit/type/set"
90 execute_tests "unit/type/zset"
91 execute_tests "unit/type/hash"
92 execute_tests "unit/sort"
93 execute_tests "unit/expire"
94 execute_tests "unit/other"
c20c189d 95 execute_tests "unit/cas"
85ecc65e 96 execute_tests "integration/replication"
53cbf66c 97 execute_tests "integration/aof"
f2dd4769 98 execute_tests "integration/redis-cli"
4589a823 99 execute_tests "unit/pubsub"
f166bb1d
PN
100
101 # run tests with VM enabled
d4507ec6 102 set ::global_overrides {vm-enabled yes}
f166bb1d
PN
103 execute_tests "unit/protocol"
104 execute_tests "unit/basic"
105 execute_tests "unit/type/list"
106 execute_tests "unit/type/set"
107 execute_tests "unit/type/zset"
108 execute_tests "unit/type/hash"
109 execute_tests "unit/sort"
110 execute_tests "unit/expire"
111 execute_tests "unit/other"
c20c189d 112 execute_tests "unit/cas"
e39c8b50
PN
113
114 cleanup
98578b57
PN
115 puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
116 if {$::failed > 0} {
117 puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
e39c8b50 118 exit 1
98578b57 119 }
98578b57
PN
120}
121
73bd6c58
PN
122# parse arguments
123for {set j 0} {$j < [llength $argv]} {incr j} {
124 set opt [lindex $argv $j]
125 set arg [lindex $argv [expr $j+1]]
126 if {$opt eq {--tags}} {
127 foreach tag $arg {
128 if {[string index $tag 0] eq "-"} {
129 lappend ::denytags [string range $tag 1 end]
130 } else {
131 lappend ::allowtags $tag
132 }
133 }
134 incr j
7d04fc75 135 } elseif {$opt eq {--host}} {
136 set ::external 1
137 set ::host $arg
138 incr j
139 } elseif {$opt eq {--port}} {
140 set ::port $arg
141 incr j
73bd6c58
PN
142 } else {
143 puts "Wrong argument: $opt"
144 exit 1
145 }
146}
147
436f18b6
PN
148if {[catch { main } err]} {
149 if {[string length $err] > 0} {
150 # only display error when not generated by the test suite
151 if {$err ne "exception"} {
152 puts $err
153 }
154 exit 1
155 }
156}