]>
git.saurik.com Git - redis.git/blob - tests/integration/redis-cli.tcl
4f180dafbc385b47d2ca295c6b87669757c04632
1 start_server
{tags
{"cli"}} {
4 set fd
[open [format "|src/redis-cli -p %d -n 9" [srv port
]] "r+"]
5 fconfigure $fd -buffering none
6 fconfigure $fd -blocking false
7 fconfigure $fd -translation binary
8 assert_equal
"redis> " [read_cli
$fd]
18 while {[string length
$buf] == 0} {
19 # wait some time and try again
26 proc write_cli
{fd buf
} {
31 proc run_command
{fd cmd
} {
33 set lines
[split [read_cli
$fd] "\n"]
34 assert_equal
"redis> " [lindex $lines end
]
35 join [lrange $lines 0 end-1
] "\n"
38 proc test_interactive_cli
{name code
} {
41 test
"Interactive CLI: $name" $code
46 proc run_nontty_cli
{args
} {
47 set fd
[open [format "|src/redis-cli -p %d -n 9 $args" [srv port
]] "r"]
48 fconfigure $fd -buffering none
49 fconfigure $fd -translation binary
50 set resp
[read $fd 1048576]
55 proc test_nontty_cli
{name code
} {
56 test
"Non-interactive non-TTY CLI: $name" $code
59 proc run_tty_cli
{args
} {
61 set resp
[run_nontty_cli
{*}$args]
66 proc test_tty_cli
{name code
} {
67 test
"Non-interactive TTY CLI: $name" $code
70 test_interactive_cli
"INFO response should be printed raw" {
71 set lines
[split [run_command
$fd info] "\n"]
73 assert
[regexp {^
[a-z0-9_
]+:[a-z0-9_
]+} $line]
77 test_interactive_cli
"Status reply" {
78 assert_equal
"OK" [run_command
$fd "set key foo"]
81 test_interactive_cli
"Integer reply" {
82 assert_equal
"(integer) 1" [run_command
$fd "incr counter"]
85 test_interactive_cli
"Bulk reply" {
87 assert_equal
"\"foo\"" [run_command
$fd "get key"]
90 test_interactive_cli
"Multi-bulk reply" {
93 assert_equal
"1. \"foo\"\n2. \"bar\"" [run_command
$fd "lrange list 0 -1"]
96 test_interactive_cli
"Parsing quotes" {
97 assert_equal
"OK" [run_command
$fd "set key \"bar\""]
98 assert_equal
"bar" [r get key
]
99 assert_equal
"OK" [run_command
$fd "set key \" bar \""]
100 assert_equal
" bar " [r get key
]
101 assert_equal
"OK" [run_command
$fd "set key \"\\\"bar\\\"\""]
102 assert_equal
"\"bar\"" [r get key
]
103 assert_equal
"OK" [run_command
$fd "set key \"\tbar\t\""]
104 assert_equal
"\tbar\t" [r get key
]
107 assert_equal
"Invalid argument(s)" [run_command
$fd "get \"\"key"]
108 assert_equal
"Invalid argument(s)" [run_command
$fd "get \"key\"x"]
110 # quotes after the argument are weird, but should be allowed
111 assert_equal
"OK" [run_command
$fd "set key\"\" bar"]
112 assert_equal
"bar" [r get key
]
115 test_tty_cli
"Status reply" {
116 assert_equal
"OK\n" [run_tty_cli
set key bar
]
117 assert_equal
"bar" [r get key
]
120 test_tty_cli
"Integer reply" {
122 assert_equal
"(integer) 1\n" [run_tty_cli
incr counter
]
125 test_tty_cli
"Bulk reply" {
126 r
set key
"tab\tnewline\n"
127 assert_equal
"\"tab\\tnewline\\n\"\n" [run_tty_cli get key
]
130 test_tty_cli
"Multi-bulk reply" {
134 assert_equal
"1. \"foo\"\n2. \"bar\"\n" [run_tty_cli
lrange list 0 -1]
137 test_nontty_cli
"Status reply" {
138 assert_equal
"OK" [run_nontty_cli
set key bar
]
139 assert_equal
"bar" [r get key
]
142 test_nontty_cli
"Integer reply" {
144 assert_equal
"1" [run_nontty_cli
incr counter
]
147 test_nontty_cli
"Bulk reply" {
148 r
set key
"tab\tnewline\n"
149 assert_equal
"tab\tnewline\n" [run_nontty_cli get key
]
152 test_nontty_cli
"Multi-bulk reply" {
156 assert_equal
"foo\nbar" [run_nontty_cli
lrange list 0 -1]