]> git.saurik.com Git - redis.git/blob - tests/test_helper.tcl
Merge branch 'master' into intset-split
[redis.git] / tests / test_helper.tcl
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
5 set tcl_precision 17
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
11
12 set ::host 127.0.0.1
13 set ::port 16379
14 set ::traceleaks 0
15 set ::valgrind 0
16 set ::denytags {}
17 set ::allowtags {}
18 set ::external 0; # If "1" this means, we are running against external instance
19
20 proc execute_tests name {
21 source "tests/$name.tcl"
22 }
23
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.
27 set ::servers {}
28 proc 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.
36 proc r {args} {
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
45 proc 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
61 # Provide easy access to INFO properties. Same semantic as "proc r".
62 proc 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]
69 }
70
71 proc cleanup {} {
72 catch {exec rm -rf {*}[glob tests/tmp/redis.conf.*]}
73 catch {exec rm -rf {*}[glob tests/tmp/server.*]}
74 }
75
76 proc main {} {
77 cleanup
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"
88 execute_tests "unit/cas"
89 execute_tests "integration/replication"
90 execute_tests "integration/aof"
91 execute_tests "unit/pubsub"
92
93 # run tests with VM enabled
94 set ::global_overrides {vm-enabled yes}
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"
104 execute_tests "unit/cas"
105
106 cleanup
107 puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
108 if {$::failed > 0} {
109 puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
110 exit 1
111 }
112 }
113
114 # parse arguments
115 for {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
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
134 } else {
135 puts "Wrong argument: $opt"
136 exit 1
137 }
138 }
139
140 if {[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 }