• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 2009 Nov 11
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
6#    May you do good and not evil.
7#    May you find forgiveness for yourself and forgive others.
8#    May you share freely, never taking more than you give.
9#
10#***********************************************************************
11#
12# The focus of this file is testing the CLI shell tool.
13#
14# $Id: shell1.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
15#
16
17# Test plan:
18#
19#   shell1-1.*: Basic command line option handling.
20#   shell1-2.*: Basic "dot" command token parsing.
21#   shell1-3.*: Basic test that "dot" command can be called.
22#
23
24package require sqlite3
25
26set CLI "./sqlite3"
27
28proc do_test {name cmd expected} {
29  puts -nonewline "$name ..."
30  set res [uplevel $cmd]
31  if {$res eq $expected} {
32    puts Ok
33  } else {
34    puts Error
35    puts "  Got: $res"
36    puts "  Expected: $expected"
37    exit
38  }
39}
40
41proc execsql {sql} {
42  uplevel [list db eval $sql]
43}
44
45proc catchsql {sql} {
46  set rc [catch {uplevel [list db eval $sql]} msg]
47  list $rc $msg
48}
49
50proc catchcmd {db {cmd ""}} {
51  global CLI
52  set out [open cmds.txt w]
53  puts $out $cmd
54  close $out
55  set line "exec $CLI $db < cmds.txt"
56  set rc [catch { eval $line } msg]
57  list $rc $msg
58}
59
60file delete -force test.db test.db.journal
61sqlite3 db test.db
62
63#----------------------------------------------------------------------------
64# Test cases shell1-1.*: Basic command line option handling.
65#
66
67# invalid option
68do_test shell1-1.1.1 {
69  set res [catchcmd "-bad test.db" ""]
70  set rc [lindex $res 0]
71  list $rc \
72       [regexp {Error: unknown option: -bad} $res]
73} {1 1}
74# error on extra options
75do_test shell1-1.1.2 {
76  set res [catchcmd "-bad test.db \"select 3\" \"select 4\"" ""]
77  set rc [lindex $res 0]
78  list $rc \
79       [regexp {Error: too many options: "select 4"} $res]
80} {1 1}
81# error on extra options
82do_test shell1-1.1.3 {
83  set res [catchcmd "-bad FOO test.db BAD" ".quit"]
84  set rc [lindex $res 0]
85  list $rc \
86       [regexp {Error: too many options: "BAD"} $res]
87} {1 1}
88
89# -help
90do_test shell1-1.2.1 {
91  set res [catchcmd "-help test.db" ""]
92  set rc [lindex $res 0]
93  list $rc \
94       [regexp {Usage} $res] \
95       [regexp {\-init} $res] \
96       [regexp {\-version} $res]
97} {1 1 1 1}
98
99# -init filename       read/process named file
100do_test shell1-1.3.1 {
101  catchcmd "-init FOO test.db" ""
102} {0 {}}
103do_test shell1-1.3.2 {
104  set res [catchcmd "-init FOO test.db .quit BAD" ""]
105  set rc [lindex $res 0]
106  list $rc \
107       [regexp {Error: too many options: "BAD"} $res]
108} {1 1}
109
110# -echo                print commands before execution
111do_test shell1-1.4.1 {
112  catchcmd "-echo test.db" ""
113} {0 {}}
114
115# -[no]header          turn headers on or off
116do_test shell1-1.5.1 {
117  catchcmd "-header test.db" ""
118} {0 {}}
119do_test shell1-1.5.2 {
120  catchcmd "-noheader test.db" ""
121} {0 {}}
122
123# -bail                stop after hitting an error
124do_test shell1-1.6.1 {
125  catchcmd "-bail test.db" ""
126} {0 {}}
127
128# -interactive         force interactive I/O
129do_test shell1-1.7.1 {
130  set res [catchcmd "-interactive test.db" ".quit"]
131  set rc [lindex $res 0]
132  list $rc \
133       [regexp {SQLite version} $res] \
134       [regexp {Enter SQL statements} $res]
135} {0 1 1}
136
137# -batch               force batch I/O
138do_test shell1-1.8.1 {
139  catchcmd "-batch test.db" ""
140} {0 {}}
141
142# -column              set output mode to 'column'
143do_test shell1-1.9.1 {
144  catchcmd "-column test.db" ""
145} {0 {}}
146
147# -csv                 set output mode to 'csv'
148do_test shell1-1.10.1 {
149  catchcmd "-csv test.db" ""
150} {0 {}}
151
152# -html                set output mode to HTML
153do_test shell1-1.11.1 {
154  catchcmd "-html test.db" ""
155} {0 {}}
156
157# -line                set output mode to 'line'
158do_test shell1-1.12.1 {
159  catchcmd "-line test.db" ""
160} {0 {}}
161
162# -list                set output mode to 'list'
163do_test shell1-1.13.1 {
164  catchcmd "-list test.db" ""
165} {0 {}}
166
167# -separator 'x'       set output field separator (|)
168do_test shell1-1.14.1 {
169  catchcmd "-separator 'x' test.db" ""
170} {0 {}}
171do_test shell1-1.14.2 {
172  catchcmd "-separator x test.db" ""
173} {0 {}}
174do_test shell1-1.14.3 {
175  set res [catchcmd "-separator" ""]
176  set rc [lindex $res 0]
177  list $rc \
178       [regexp {Error: missing argument for option: -separator} $res]
179} {1 1}
180
181# -stats               print memory stats before each finalize
182do_test shell1-1.14b.1 {
183  catchcmd "-stats test.db" ""
184} {0 {}}
185
186# -nullvalue 'text'    set text string for NULL values
187do_test shell1-1.15.1 {
188  catchcmd "-nullvalue 'x' test.db" ""
189} {0 {}}
190do_test shell1-1.15.2 {
191  catchcmd "-nullvalue x test.db" ""
192} {0 {}}
193do_test shell1-1.15.3 {
194  set res [catchcmd "-nullvalue" ""]
195  set rc [lindex $res 0]
196  list $rc \
197       [regexp {Error: missing argument for option: -nullvalue} $res]
198} {1 1}
199
200# -version             show SQLite version
201do_test shell1-1.16.1 {
202  catchcmd "-version test.db" ""
203} {0 3.7.6.3}
204
205#----------------------------------------------------------------------------
206# Test cases shell1-2.*: Basic "dot" command token parsing.
207#
208
209# check first token handling
210do_test shell1-2.1.1 {
211  catchcmd "test.db" ".foo"
212} {1 {Error: unknown command or invalid arguments:  "foo". Enter ".help" for help}}
213do_test shell1-2.1.2 {
214  catchcmd "test.db" ".\"foo OFF\""
215} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
216do_test shell1-2.1.3 {
217  catchcmd "test.db" ".\'foo OFF\'"
218} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
219
220# unbalanced quotes
221do_test shell1-2.2.1 {
222  catchcmd "test.db" ".\"foo OFF"
223} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
224do_test shell1-2.2.2 {
225  catchcmd "test.db" ".\'foo OFF"
226} {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
227do_test shell1-2.2.3 {
228  catchcmd "test.db" ".explain \"OFF"
229} {0 {}}
230do_test shell1-2.2.4 {
231  catchcmd "test.db" ".explain \'OFF"
232} {0 {}}
233do_test shell1-2.2.5 {
234  catchcmd "test.db" ".mode \"insert FOO"
235} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
236do_test shell1-2.2.6 {
237  catchcmd "test.db" ".mode \'insert FOO"
238} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
239
240# check multiple tokens, and quoted tokens
241do_test shell1-2.3.1 {
242  catchcmd "test.db" ".explain 1"
243} {0 {}}
244do_test shell1-2.3.2 {
245  catchcmd "test.db" ".explain on"
246} {0 {}}
247do_test shell1-2.3.3 {
248  catchcmd "test.db" ".explain \"1 2 3\""
249} {0 {}}
250do_test shell1-2.3.4 {
251  catchcmd "test.db" ".explain \"OFF\""
252} {0 {}}
253do_test shell1-2.3.5 {
254  catchcmd "test.db" ".\'explain\' \'OFF\'"
255} {0 {}}
256do_test shell1-2.3.6 {
257  catchcmd "test.db" ".explain \'OFF\'"
258} {0 {}}
259do_test shell1-2.3.7 {
260  catchcmd "test.db" ".\'explain\' \'OFF\'"
261} {0 {}}
262
263# check quoted args are unquoted
264do_test shell1-2.4.1 {
265  catchcmd "test.db" ".mode FOO"
266} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
267do_test shell1-2.4.2 {
268  catchcmd "test.db" ".mode csv"
269} {0 {}}
270do_test shell1-2.4.2 {
271  catchcmd "test.db" ".mode \"csv\""
272} {0 {}}
273
274
275#----------------------------------------------------------------------------
276# Test cases shell1-3.*: Basic test that "dot" command can be called.
277#
278
279# .backup ?DB? FILE      Backup DB (default "main") to FILE
280do_test shell1-3.1.1 {
281  catchcmd "test.db" ".backup"
282} {1 {Error: unknown command or invalid arguments:  "backup". Enter ".help" for help}}
283do_test shell1-3.1.2 {
284  catchcmd "test.db" ".backup FOO"
285} {0 {}}
286do_test shell1-3.1.3 {
287  catchcmd "test.db" ".backup FOO BAR"
288} {1 {Error: unknown database FOO}}
289do_test shell1-3.1.4 {
290  # too many arguments
291  catchcmd "test.db" ".backup FOO BAR BAD"
292} {1 {Error: unknown command or invalid arguments:  "backup". Enter ".help" for help}}
293
294# .bail ON|OFF           Stop after hitting an error.  Default OFF
295do_test shell1-3.2.1 {
296  catchcmd "test.db" ".bail"
297} {1 {Error: unknown command or invalid arguments:  "bail". Enter ".help" for help}}
298do_test shell1-3.2.2 {
299  catchcmd "test.db" ".bail ON"
300} {0 {}}
301do_test shell1-3.2.3 {
302  catchcmd "test.db" ".bail OFF"
303} {0 {}}
304do_test shell1-3.2.4 {
305  # too many arguments
306  catchcmd "test.db" ".bail OFF BAD"
307} {1 {Error: unknown command or invalid arguments:  "bail". Enter ".help" for help}}
308
309# .databases             List names and files of attached databases
310do_test shell1-3.3.1 {
311  set res [catchcmd "test.db" ".databases"]
312  regexp {0.*main.*test\.db} $res
313} {1}
314do_test shell1-3.3.2 {
315  # too many arguments
316  catchcmd "test.db" ".databases BAD"
317} {1 {Error: unknown command or invalid arguments:  "databases". Enter ".help" for help}}
318
319# .dump ?TABLE? ...      Dump the database in an SQL text format
320#                          If TABLE specified, only dump tables matching
321#                          LIKE pattern TABLE.
322do_test shell1-3.4.1 {
323  set res [catchcmd "test.db" ".dump"]
324  list [regexp {BEGIN TRANSACTION;} $res] \
325       [regexp {COMMIT;} $res]
326} {1 1}
327do_test shell1-3.4.2 {
328  set res [catchcmd "test.db" ".dump FOO"]
329  list [regexp {BEGIN TRANSACTION;} $res] \
330       [regexp {COMMIT;} $res]
331} {1 1}
332do_test shell1-3.4.3 {
333  # too many arguments
334  catchcmd "test.db" ".dump FOO BAD"
335} {1 {Error: unknown command or invalid arguments:  "dump". Enter ".help" for help}}
336
337# .echo ON|OFF           Turn command echo on or off
338do_test shell1-3.5.1 {
339  catchcmd "test.db" ".echo"
340} {1 {Error: unknown command or invalid arguments:  "echo". Enter ".help" for help}}
341do_test shell1-3.5.2 {
342  catchcmd "test.db" ".echo ON"
343} {0 {}}
344do_test shell1-3.5.3 {
345  catchcmd "test.db" ".echo OFF"
346} {0 {}}
347do_test shell1-3.5.4 {
348  # too many arguments
349  catchcmd "test.db" ".echo OFF BAD"
350} {1 {Error: unknown command or invalid arguments:  "echo". Enter ".help" for help}}
351
352# .exit                  Exit this program
353do_test shell1-3.6.1 {
354  catchcmd "test.db" ".exit"
355} {0 {}}
356do_test shell1-3.6.2 {
357  # too many arguments
358  catchcmd "test.db" ".exit BAD"
359} {1 {Error: unknown command or invalid arguments:  "exit". Enter ".help" for help}}
360
361# .explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.
362do_test shell1-3.7.1 {
363  catchcmd "test.db" ".explain"
364  # explain is the exception to the booleans.  without an option, it turns it on.
365} {0 {}}
366do_test shell1-3.7.2 {
367  catchcmd "test.db" ".explain ON"
368} {0 {}}
369do_test shell1-3.7.3 {
370  catchcmd "test.db" ".explain OFF"
371} {0 {}}
372do_test shell1-3.7.4 {
373  # too many arguments
374  catchcmd "test.db" ".explain OFF BAD"
375} {1 {Error: unknown command or invalid arguments:  "explain". Enter ".help" for help}}
376
377
378# .header(s) ON|OFF      Turn display of headers on or off
379do_test shell1-3.9.1 {
380  catchcmd "test.db" ".header"
381} {1 {Error: unknown command or invalid arguments:  "header". Enter ".help" for help}}
382do_test shell1-3.9.2 {
383  catchcmd "test.db" ".header ON"
384} {0 {}}
385do_test shell1-3.9.3 {
386  catchcmd "test.db" ".header OFF"
387} {0 {}}
388do_test shell1-3.9.4 {
389  # too many arguments
390  catchcmd "test.db" ".header OFF BAD"
391} {1 {Error: unknown command or invalid arguments:  "header". Enter ".help" for help}}
392
393do_test shell1-3.9.5 {
394  catchcmd "test.db" ".headers"
395} {1 {Error: unknown command or invalid arguments:  "headers". Enter ".help" for help}}
396do_test shell1-3.9.6 {
397  catchcmd "test.db" ".headers ON"
398} {0 {}}
399do_test shell1-3.9.7 {
400  catchcmd "test.db" ".headers OFF"
401} {0 {}}
402do_test shell1-3.9.8 {
403  # too many arguments
404  catchcmd "test.db" ".headers OFF BAD"
405} {1 {Error: unknown command or invalid arguments:  "headers". Enter ".help" for help}}
406
407# .help                  Show this message
408do_test shell1-3.10.1 {
409  set res [catchcmd "test.db" ".help"]
410  # look for a few of the possible help commands
411  list [regexp {.help} $res] \
412       [regexp {.quit} $res] \
413       [regexp {.show} $res]
414} {1 1 1}
415do_test shell1-3.10.2 {
416  # we allow .help to take extra args (it is help after all)
417  set res [catchcmd "test.db" ".help BAD"]
418  # look for a few of the possible help commands
419  list [regexp {.help} $res] \
420       [regexp {.quit} $res] \
421       [regexp {.show} $res]
422} {1 1 1}
423
424# .import FILE TABLE     Import data from FILE into TABLE
425do_test shell1-3.11.1 {
426  catchcmd "test.db" ".import"
427} {1 {Error: unknown command or invalid arguments:  "import". Enter ".help" for help}}
428do_test shell1-3.11.2 {
429  catchcmd "test.db" ".import FOO"
430} {1 {Error: unknown command or invalid arguments:  "import". Enter ".help" for help}}
431do_test shell1-3.11.2 {
432  catchcmd "test.db" ".import FOO BAR"
433} {1 {Error: no such table: BAR}}
434do_test shell1-3.11.3 {
435  # too many arguments
436  catchcmd "test.db" ".import FOO BAR BAD"
437} {1 {Error: unknown command or invalid arguments:  "import". Enter ".help" for help}}
438
439# .indices ?TABLE?       Show names of all indices
440#                          If TABLE specified, only show indices for tables
441#                          matching LIKE pattern TABLE.
442do_test shell1-3.12.1 {
443  catchcmd "test.db" ".indices"
444} {0 {}}
445do_test shell1-3.12.2 {
446  catchcmd "test.db" ".indices FOO"
447} {0 {}}
448do_test shell1-3.12.3 {
449  # too many arguments
450  catchcmd "test.db" ".indices FOO BAD"
451} {1 {Error: unknown command or invalid arguments:  "indices". Enter ".help" for help}}
452
453# .mode MODE ?TABLE?     Set output mode where MODE is one of:
454#                          csv      Comma-separated values
455#                          column   Left-aligned columns.  (See .width)
456#                          html     HTML <table> code
457#                          insert   SQL insert statements for TABLE
458#                          line     One value per line
459#                          list     Values delimited by .separator string
460#                          tabs     Tab-separated values
461#                          tcl      TCL list elements
462do_test shell1-3.13.1 {
463  catchcmd "test.db" ".mode"
464} {1 {Error: unknown command or invalid arguments:  "mode". Enter ".help" for help}}
465do_test shell1-3.13.2 {
466  catchcmd "test.db" ".mode FOO"
467} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
468do_test shell1-3.13.3 {
469  catchcmd "test.db" ".mode csv"
470} {0 {}}
471do_test shell1-3.13.4 {
472  catchcmd "test.db" ".mode column"
473} {0 {}}
474do_test shell1-3.13.5 {
475  catchcmd "test.db" ".mode html"
476} {0 {}}
477do_test shell1-3.13.6 {
478  catchcmd "test.db" ".mode insert"
479} {0 {}}
480do_test shell1-3.13.7 {
481  catchcmd "test.db" ".mode line"
482} {0 {}}
483do_test shell1-3.13.8 {
484  catchcmd "test.db" ".mode list"
485} {0 {}}
486do_test shell1-3.13.9 {
487  catchcmd "test.db" ".mode tabs"
488} {0 {}}
489do_test shell1-3.13.10 {
490  catchcmd "test.db" ".mode tcl"
491} {0 {}}
492do_test shell1-3.13.11 {
493  # too many arguments
494  catchcmd "test.db" ".mode tcl BAD"
495} {1 {Error: invalid arguments:  "BAD". Enter ".help" for help}}
496
497# don't allow partial mode type matches
498do_test shell1-3.13.12 {
499  catchcmd "test.db" ".mode l"
500} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
501do_test shell1-3.13.13 {
502  catchcmd "test.db" ".mode li"
503} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
504do_test shell1-3.13.14 {
505  catchcmd "test.db" ".mode lin"
506} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
507
508# .nullvalue STRING      Print STRING in place of NULL values
509do_test shell1-3.14.1 {
510  catchcmd "test.db" ".nullvalue"
511} {1 {Error: unknown command or invalid arguments:  "nullvalue". Enter ".help" for help}}
512do_test shell1-3.14.2 {
513  catchcmd "test.db" ".nullvalue FOO"
514} {0 {}}
515do_test shell1-3.14.3 {
516  # too many arguments
517  catchcmd "test.db" ".nullvalue FOO BAD"
518} {1 {Error: unknown command or invalid arguments:  "nullvalue". Enter ".help" for help}}
519
520# .output FILENAME       Send output to FILENAME
521do_test shell1-3.15.1 {
522  catchcmd "test.db" ".output"
523} {1 {Error: unknown command or invalid arguments:  "output". Enter ".help" for help}}
524do_test shell1-3.15.2 {
525  catchcmd "test.db" ".output FOO"
526} {0 {}}
527do_test shell1-3.15.3 {
528  # too many arguments
529  catchcmd "test.db" ".output FOO BAD"
530} {1 {Error: unknown command or invalid arguments:  "output". Enter ".help" for help}}
531
532# .output stdout         Send output to the screen
533do_test shell1-3.16.1 {
534  catchcmd "test.db" ".output stdout"
535} {0 {}}
536do_test shell1-3.16.2 {
537  # too many arguments
538  catchcmd "test.db" ".output stdout BAD"
539} {1 {Error: unknown command or invalid arguments:  "output". Enter ".help" for help}}
540
541# .prompt MAIN CONTINUE  Replace the standard prompts
542do_test shell1-3.17.1 {
543  catchcmd "test.db" ".prompt"
544} {1 {Error: unknown command or invalid arguments:  "prompt". Enter ".help" for help}}
545do_test shell1-3.17.2 {
546  catchcmd "test.db" ".prompt FOO"
547} {0 {}}
548do_test shell1-3.17.3 {
549  catchcmd "test.db" ".prompt FOO BAR"
550} {0 {}}
551do_test shell1-3.17.4 {
552  # too many arguments
553  catchcmd "test.db" ".prompt FOO BAR BAD"
554} {1 {Error: unknown command or invalid arguments:  "prompt". Enter ".help" for help}}
555
556# .quit                  Exit this program
557do_test shell1-3.18.1 {
558  catchcmd "test.db" ".quit"
559} {0 {}}
560do_test shell1-3.18.2 {
561  # too many arguments
562  catchcmd "test.db" ".quit BAD"
563} {1 {Error: unknown command or invalid arguments:  "quit". Enter ".help" for help}}
564
565# .read FILENAME         Execute SQL in FILENAME
566do_test shell1-3.19.1 {
567  catchcmd "test.db" ".read"
568} {1 {Error: unknown command or invalid arguments:  "read". Enter ".help" for help}}
569do_test shell1-3.19.2 {
570  file delete -force FOO
571  catchcmd "test.db" ".read FOO"
572} {1 {Error: cannot open "FOO"}}
573do_test shell1-3.19.3 {
574  # too many arguments
575  catchcmd "test.db" ".read FOO BAD"
576} {1 {Error: unknown command or invalid arguments:  "read". Enter ".help" for help}}
577
578# .restore ?DB? FILE     Restore content of DB (default "main") from FILE
579do_test shell1-3.20.1 {
580  catchcmd "test.db" ".restore"
581} {1 {Error: unknown command or invalid arguments:  "restore". Enter ".help" for help}}
582do_test shell1-3.20.2 {
583  catchcmd "test.db" ".restore FOO"
584} {0 {}}
585do_test shell1-3.20.3 {
586  catchcmd "test.db" ".restore FOO BAR"
587} {1 {Error: unknown database FOO}}
588do_test shell1-3.20.4 {
589  # too many arguments
590  catchcmd "test.db" ".restore FOO BAR BAD"
591} {1 {Error: unknown command or invalid arguments:  "restore". Enter ".help" for help}}
592
593# .schema ?TABLE?        Show the CREATE statements
594#                          If TABLE specified, only show tables matching
595#                          LIKE pattern TABLE.
596do_test shell1-3.21.1 {
597  catchcmd "test.db" ".schema"
598} {0 {}}
599do_test shell1-3.21.2 {
600  catchcmd "test.db" ".schema FOO"
601} {0 {}}
602do_test shell1-3.21.3 {
603  # too many arguments
604  catchcmd "test.db" ".schema FOO BAD"
605} {1 {Error: unknown command or invalid arguments:  "schema". Enter ".help" for help}}
606
607# .separator STRING      Change separator used by output mode and .import
608do_test shell1-3.22.1 {
609  catchcmd "test.db" ".separator"
610} {1 {Error: unknown command or invalid arguments:  "separator". Enter ".help" for help}}
611do_test shell1-3.22.2 {
612  catchcmd "test.db" ".separator FOO"
613} {0 {}}
614do_test shell1-3.22.3 {
615  # too many arguments
616  catchcmd "test.db" ".separator FOO BAD"
617} {1 {Error: unknown command or invalid arguments:  "separator". Enter ".help" for help}}
618
619# .show                  Show the current values for various settings
620do_test shell1-3.23.1 {
621  set res [catchcmd "test.db" ".show"]
622  list [regexp {echo:} $res] \
623       [regexp {explain:} $res] \
624       [regexp {headers:} $res] \
625       [regexp {mode:} $res] \
626       [regexp {nullvalue:} $res] \
627       [regexp {output:} $res] \
628       [regexp {separator:} $res] \
629       [regexp {stats:} $res] \
630       [regexp {width:} $res]
631} {1 1 1 1 1 1 1 1 1}
632do_test shell1-3.23.2 {
633  # too many arguments
634  catchcmd "test.db" ".show BAD"
635} {1 {Error: unknown command or invalid arguments:  "show". Enter ".help" for help}}
636
637# .stats ON|OFF          Turn stats on or off
638do_test shell1-3.23b.1 {
639  catchcmd "test.db" ".stats"
640} {1 {Error: unknown command or invalid arguments:  "stats". Enter ".help" for help}}
641do_test shell1-3.23b.2 {
642  catchcmd "test.db" ".stats ON"
643} {0 {}}
644do_test shell1-3.23b.3 {
645  catchcmd "test.db" ".stats OFF"
646} {0 {}}
647do_test shell1-3.23b.4 {
648  # too many arguments
649  catchcmd "test.db" ".stats OFF BAD"
650} {1 {Error: unknown command or invalid arguments:  "stats". Enter ".help" for help}}
651
652# .tables ?TABLE?        List names of tables
653#                          If TABLE specified, only list tables matching
654#                          LIKE pattern TABLE.
655do_test shell1-3.24.1 {
656  catchcmd "test.db" ".tables"
657} {0 {}}
658do_test shell1-3.24.2 {
659  catchcmd "test.db" ".tables FOO"
660} {0 {}}
661do_test shell1-3.24.3 {
662  # too many arguments
663  catchcmd "test.db" ".tables FOO BAD"
664} {1 {Error: unknown command or invalid arguments:  "tables". Enter ".help" for help}}
665
666# .timeout MS            Try opening locked tables for MS milliseconds
667do_test shell1-3.25.1 {
668  catchcmd "test.db" ".timeout"
669} {1 {Error: unknown command or invalid arguments:  "timeout". Enter ".help" for help}}
670do_test shell1-3.25.2 {
671  catchcmd "test.db" ".timeout zzz"
672  # this should be treated the same as a '0' timeout
673} {0 {}}
674do_test shell1-3.25.3 {
675  catchcmd "test.db" ".timeout 1"
676} {0 {}}
677do_test shell1-3.25.4 {
678  # too many arguments
679  catchcmd "test.db" ".timeout 1 BAD"
680} {1 {Error: unknown command or invalid arguments:  "timeout". Enter ".help" for help}}
681
682# .width NUM NUM ...     Set column widths for "column" mode
683do_test shell1-3.26.1 {
684  catchcmd "test.db" ".width"
685} {1 {Error: unknown command or invalid arguments:  "width". Enter ".help" for help}}
686do_test shell1-3.26.2 {
687  catchcmd "test.db" ".width xxx"
688  # this should be treated the same as a '0' width for col 1
689} {0 {}}
690do_test shell1-3.26.3 {
691  catchcmd "test.db" ".width xxx yyy"
692  # this should be treated the same as a '0' width for col 1 and 2
693} {0 {}}
694do_test shell1-3.26.4 {
695  catchcmd "test.db" ".width 1 1"
696  # this should be treated the same as a '1' width for col 1 and 2
697} {0 {}}
698
699# .timer ON|OFF          Turn the CPU timer measurement on or off
700do_test shell1-3.27.1 {
701  catchcmd "test.db" ".timer"
702} {1 {Error: unknown command or invalid arguments:  "timer". Enter ".help" for help}}
703do_test shell1-3.27.2 {
704  catchcmd "test.db" ".timer ON"
705} {0 {}}
706do_test shell1-3.27.3 {
707  catchcmd "test.db" ".timer OFF"
708} {0 {}}
709do_test shell1-3.27.4 {
710  # too many arguments
711  catchcmd "test.db" ".timer OFF BAD"
712} {1 {Error: unknown command or invalid arguments:  "timer". Enter ".help" for help}}
713
714puts "CLI tests completed successfully"
715