]> git.saurik.com Git - redis.git/blame - tests/test_helper.tcl
TODO updated
[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
45# Provide easy access to INFO properties. Same semantic as "proc r".
46proc s {args} {
47 set level 0
48 if {[string is integer [lindex $args 0]]} {
49 set level [lindex $args 0]
50 set args [lrange $args 1 end]
51 }
52 status [srv $level "client"] [lindex $args 0]
98578b57
PN
53}
54
f166bb1d 55proc cleanup {} {
c4669d25 56 catch {exec rm -rf {*}[glob tests/tmp/redis.conf.*]}
57 catch {exec rm -rf {*}[glob tests/tmp/server.*]}
f166bb1d
PN
58}
59
98578b57 60proc main {} {
f166bb1d 61 cleanup
98578b57
PN
62 execute_tests "unit/auth"
63 execute_tests "unit/protocol"
64 execute_tests "unit/basic"
65 execute_tests "unit/type/list"
66 execute_tests "unit/type/set"
67 execute_tests "unit/type/zset"
68 execute_tests "unit/type/hash"
69 execute_tests "unit/sort"
70 execute_tests "unit/expire"
71 execute_tests "unit/other"
c20c189d 72 execute_tests "unit/cas"
85ecc65e 73 execute_tests "integration/replication"
53cbf66c 74 execute_tests "integration/aof"
f166bb1d
PN
75
76 # run tests with VM enabled
d4507ec6 77 set ::global_overrides {vm-enabled yes}
f166bb1d
PN
78 execute_tests "unit/protocol"
79 execute_tests "unit/basic"
80 execute_tests "unit/type/list"
81 execute_tests "unit/type/set"
82 execute_tests "unit/type/zset"
83 execute_tests "unit/type/hash"
84 execute_tests "unit/sort"
85 execute_tests "unit/expire"
86 execute_tests "unit/other"
c20c189d 87 execute_tests "unit/cas"
98578b57
PN
88
89 puts "\n[expr $::passed+$::failed] tests, $::passed passed, $::failed failed"
90 if {$::failed > 0} {
91 puts "\n*** WARNING!!! $::failed FAILED TESTS ***\n"
92 }
f166bb1d
PN
93
94 cleanup
98578b57
PN
95}
96
73bd6c58
PN
97# parse arguments
98for {set j 0} {$j < [llength $argv]} {incr j} {
99 set opt [lindex $argv $j]
100 set arg [lindex $argv [expr $j+1]]
101 if {$opt eq {--tags}} {
102 foreach tag $arg {
103 if {[string index $tag 0] eq "-"} {
104 lappend ::denytags [string range $tag 1 end]
105 } else {
106 lappend ::allowtags $tag
107 }
108 }
109 incr j
7d04fc75 110 } elseif {$opt eq {--host}} {
111 set ::external 1
112 set ::host $arg
113 incr j
114 } elseif {$opt eq {--port}} {
115 set ::port $arg
116 incr j
73bd6c58
PN
117 } else {
118 puts "Wrong argument: $opt"
119 exit 1
120 }
121}
122
436f18b6
PN
123if {[catch { main } err]} {
124 if {[string length $err] > 0} {
125 # only display error when not generated by the test suite
126 if {$err ne "exception"} {
127 puts $err
128 }
129 exit 1
130 }
131}