]> git.saurik.com Git - redis.git/blame - tests/test_helper.tcl
minor typo fixed in a comment
[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 {}
28proc srv {level property} {
29 set srv [lindex $::servers end+$level]
30 dict get $srv $property
31}
32
33# Provide easy access to the client for the inner server. It's possible to
34# prepend the argument list with a negative level to access clients for
35# servers running in outer blocks.
98578b57 36proc r {args} {
1c4114be
PN
37 set level 0
38 if {[string is integer [lindex $args 0]]} {
39 set level [lindex $args 0]
40 set args [lrange $args 1 end]
41 }
42 [srv $level "client"] {*}$args
43}
44
5eedc9c6
PN
45proc redis_deferring_client {args} {
46 set level 0
47 if {[llength $args] > 0 && [string is integer [lindex $args 0]]} {
48 set level [lindex $args 0]
49 set args [lrange $args 1 end]
50 }
51
52 # create client that defers reading reply
53 set client [redis [srv $level "host"] [srv $level "port"] 1]
54
55 # select the right db and read the response (OK)
56 $client select 9
57 $client read
58 return $client
59}
60
1c4114be
PN
61# Provide easy access to INFO properties. Same semantic as "proc r".
62proc s {args} {
63 set level 0
64 if {[string is integer [lindex $args 0]]} {
65 set level [lindex $args 0]
66 set args [lrange $args 1 end]
67 }
68 status [srv $level "client"] [lindex $args 0]
98578b57
PN
69}
70
f166bb1d 71proc cleanup {} {
c4669d25 72 catch {exec rm -rf {*}[glob tests/tmp/redis.conf.*]}
73 catch {exec rm -rf {*}[glob tests/tmp/server.*]}
f166bb1d
PN
74}
75
98578b57 76proc main {} {
f166bb1d 77 cleanup
98578b57
PN
78 execute_tests "unit/auth"
79 execute_tests "unit/protocol"
80 execute_tests "unit/basic"
81 execute_tests "unit/type/list"
82 execute_tests "unit/type/set"
83 execute_tests "unit/type/zset"
84 execute_tests "unit/type/hash"
85 execute_tests "unit/sort"
86 execute_tests "unit/expire"
87 execute_tests "unit/other"
c20c189d 88 execute_tests "unit/cas"
85ecc65e 89 execute_tests "integration/replication"
53cbf66c 90 execute_tests "integration/aof"
4589a823 91 execute_tests "unit/pubsub"
f166bb1d
PN
92
93 # run tests with VM enabled
d4507ec6 94 set ::global_overrides {vm-enabled yes}
f166bb1d
PN
95 execute_tests "unit/protocol"
96 execute_tests "unit/basic"
97 execute_tests "unit/type/list"
98 execute_tests "unit/type/set"
99 execute_tests "unit/type/zset"
100 execute_tests "unit/type/hash"
101 execute_tests "unit/sort"
102 execute_tests "unit/expire"
103 execute_tests "unit/other"
c20c189d 104 execute_tests "unit/cas"
98578b57
PN
105
106 puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
107 if {$::failed > 0} {
108 puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
109 }
f166bb1d
PN
110
111 cleanup
98578b57
PN
112}
113
73bd6c58
PN
114# parse arguments
115for {set j 0} {$j < [llength $argv]} {incr j} {
116 set opt [lindex $argv $j]
117 set arg [lindex $argv [expr $j+1]]
118 if {$opt eq {--tags}} {
119 foreach tag $arg {
120 if {[string index $tag 0] eq "-"} {
121 lappend ::denytags [string range $tag 1 end]
122 } else {
123 lappend ::allowtags $tag
124 }
125 }
126 incr j
7d04fc75 127 } elseif {$opt eq {--host}} {
128 set ::external 1
129 set ::host $arg
130 incr j
131 } elseif {$opt eq {--port}} {
132 set ::port $arg
133 incr j
73bd6c58
PN
134 } else {
135 puts "Wrong argument: $opt"
136 exit 1
137 }
138}
139
436f18b6
PN
140if {[catch { main } err]} {
141 if {[string length $err] > 0} {
142 # only display error when not generated by the test suite
143 if {$err ne "exception"} {
144 puts $err
145 }
146 exit 1
147 }
148}