-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
test_local_cmds.tcl
executable file
·342 lines (292 loc) · 7.57 KB
/
test_local_cmds.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#! /usr/bin/env expect -f
source [file join [file dirname $argv0] common.tcl]
start_server $argv
spawn $argv sql
eexpect root@
start_test "Check that times are displayed by default on interactive terminals."
send "select 1;\r"
eexpect "(1 row)"
eexpect "Time:"
eexpect root@
end_test
start_test "Check that \\? prints the help text."
send "\\?\r"
eexpect "You are using"
eexpect "More documentation"
eexpect root@
end_test
start_test "Check that \\! invokes external commands."
send "\\! echo -n he; echo llo\r"
eexpect "hello"
eexpect "root@"
end_test
start_test "Check that \\q terminates the client."
send "\\q\r"
eexpect eof
spawn $argv sql --format=tsv
eexpect root@
end_test
start_test "Check that quit terminates the client."
send "quit\r"
eexpect eof
spawn $argv sql --format=tsv
eexpect root@
end_test
start_test "Check that quit does not terminate the client in the middle of a statement."
send "select\rquit\r;\r"
eexpect "column \"quit\" does not exist"
eexpect root@
end_test
start_test "Check that exit terminates the client."
send "exit\r"
eexpect eof
spawn $argv sql --format=tsv
eexpect root@
end_test
start_test "Check that \\| reads statements."
send "\\| echo 'select '; echo '38 + 4;'\r"
eexpect 42
eexpect root@
end_test
start_test "Check that \\| does not execute upon encountering an error."
send "\\| echo 'create database dontcreate;'; exit 1\r"
eexpect "error in external command"
eexpect root@
send "drop database dontcreate;\r"
eexpect "database * does not exist"
eexpect root@
end_test
start_test "Check that a buit-in command in between tokens of a statement is processed locally."
send "select\r"
eexpect " ->"
send "\\?\r"
eexpect " ->"
send "1;\r"
expect "Time"
eexpect root@
end_test
start_test "Check that \\set without argument prints the current options"
send "\\set\r"
eexpect "display_format\ttsv"
eexpect root@
end_test
start_test "Check that \\set display_format properly errors out"
send "\\set display_format blabla\r"
eexpect "invalid table display format"
# check we don't see a stray "cannot change option during multi-line editing" tacked at the end
eexpect "html, raw)\r\n"
eexpect root@
end_test
start_test "Check that \\set can change the display format"
send "\\set display_format csv\r\\set\r"
eexpect "display_format,csv"
eexpect root@
send "\\set display_format=tsv\r\\set\r"
eexpect "display_format\ttsv"
eexpect root@
end_test
start_test "Check that \\x toggles display format"
send "\\x\r\\set\r"
eexpect "Option*|*display_format"
eexpect "Value*|*records"
eexpect root@
send "\\x\r\\set\r"
eexpect "display_format*|*table"
eexpect root@
end_test
start_test "Check that \\x with on or off enables/disables records display format"
send "\\x on\r\\set\r"
eexpect "Option*|*display_format"
eexpect "Value*|*records"
eexpect root@
send "\\x off\r\\set\r"
eexpect "display_format*|*table"
eexpect root@
end_test
start_test "Check various ways to set a boolean flag."
send "\\set display_format=tsv\r"
send "\\set show_times=false\r\\set\r"
eexpect "show_times\tfalse"
eexpect root@
send "\\set show_times=true\r\\set\r"
eexpect "show_times\ttrue"
eexpect root@
send "\\set show_times=0\r\\set\r"
eexpect "show_times\tfalse"
eexpect root@
send "\\set show_times=1\r\\set\r"
eexpect "show_times\ttrue"
eexpect root@
send "\\set show_times=off\r\\set\r"
eexpect "show_times\tfalse"
eexpect root@
send "\\set show_times=on\r\\set\r"
eexpect "show_times\ttrue"
eexpect root@
send "\\set show_times=blah\r"
eexpect "invalid syntax"
eexpect root@
end_test
start_test "Check that a built-in command in the middle of a token (eg a string) is processed locally."
send "select 'hello\r"
eexpect " ->"
send "\\?\r"
eexpect " ->"
send "world' as woo;\r"
eexpect "hello\r\nworld"
eexpect "Time"
eexpect root@
end_test
start_test "Check that \\set can change the display of query times"
# check the override
send "\\unset show_times\r\\set\r"
eexpect "show_times\tfalse"
eexpect root@
send "select 1 as woo;\r"
eexpect "woo\r\n1\r\n"
expect {
"Time:" {
report "unexpected Time"
exit 1
}
root@ {}
}
eexpect "/defaultdb> "
# restore
send "\\set show_times\r"
end_test
start_test "Check that \\h with invalid commands print a reminder."
send "\\h invalid\r"
eexpect "no help available"
eexpect "Try"
expect "with no argument"
eexpect root@
end_test
start_test "Check that \\h with no argument prints a full list."
send "\\h\r"
eexpect "TRUNCATE"
eexpect "SHOW"
eexpect "ROLLBACK"
eexpect root@
end_test
start_test "Check that \\h with a known statement prints details."
send "\\h select\r"
eexpect "Command:"
eexpect "SELECT"
eexpect "data manipulation"
eexpect "FROM"
eexpect "ORDER BY"
eexpect "See also"
eexpect root@
end_test
start_test "Check that \\h with a documented clause name prints details."
send "\\h <source>\r"
eexpect "Command:"
eexpect "<SOURCE>"
eexpect "data manipulation"
eexpect "JOIN"
eexpect "SHOW"
eexpect "See also"
eexpect root@
end_test
start_test "Check that \\hf without argument prints a list."
send "\\hf\r"
eexpect "abs"
eexpect "count"
eexpect "round"
eexpect root@
end_test
start_test "Check that \\hf with a valid function name prints that functions help."
send "\\hf version\r"
eexpect "Category:"
eexpect "Signature"
eexpect root@
end_test
start_test "Check that \\hf with an invalid function name prints an error."
send "\\hf invalid\r"
eexpect "no help available"
eexpect "Try"
eexpect "with no argument"
eexpect root@
end_test
start_test "Check that \\echo behaves well."
send "\\echo\r"
eexpect "\r\n"
eexpect "\r\n"
eexpect root@
send "\\echo hello world\r"
# echo removes double spaces within the line. That's expected.
eexpect "hello world"
eexpect root@
end_test
start_test "Check that commands are also recognized with a final semicolon."
send "\\set;\r"
eexpect "display_format"
eexpect root@
send "\\h select;\r"
eexpect SELECT
eexpect Description
eexpect root@
end_test
start_test "Check that the output of queries can be redirected to a file."
send "\\o logs/query-output.txt\r"
eexpect root@
send "select 'hello world';\r"
eexpect root@
system "grep world logs/query-output.txt"
end_test
start_test "Check that the query output can be reset to stdout."
send "\\o\r"
eexpect root@
send "select 'hel'||'lo';\r"
eexpect "hello"
eexpect root@
end_test
# Finally terminate with Ctrl+D.
send_eof
eexpect eof
spawn /bin/bash
send "PS1=':''/# '\r"
eexpect ":/# "
start_test "Check that non-interactive built-in commands are only accepted at the start of a statement."
send "(echo '\\set check_syntax'; echo 'select '; echo '\\help'; echo ';') | $argv sql\r"
eexpect "statement ignored"
eexpect ":/# "
send "(echo '\\unset check_syntax'; echo 'select '; echo '\\help'; echo '1;') | $argv sql\r"
eexpect "ERROR: at or near"
eexpect "syntax error"
eexpect ":/# "
end_test
stop_server $argv
start_test "Check that client-side options can be overridden with set"
# First establish a baseline with all the defaults.
send "$argv demo --no-example-database\r"
eexpect root@
send "\\set display_format csv\r"
send "\\set\r"
eexpect "auto_trace,off"
eexpect "check_syntax,true"
eexpect "echo,false"
eexpect "errexit,false"
eexpect "prompt1,%n@"
eexpect "show_times,true"
eexpect root@
send_eof
eexpect ":/# "
# Then verify that the defaults can be overridden.
send "$argv demo --no-example-database --set=auto_trace=on --set=check_syntax=false --set=echo=true --set=errexit=true --set=prompt1=%n@haa --set=show_times=false\r"
eexpect root@
send "\\set display_format csv\r"
send "\\set\r"
eexpect "auto_trace,\"on"
eexpect "check_syntax,false"
eexpect "echo,true"
eexpect "errexit,true"
eexpect "prompt1,%n@haa"
eexpect "show_times,false"
eexpect root@
send_eof
eexpect ":/# "
end_test
send "exit 0\r"
eexpect eof