/ Check-in [29e3c8da]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Updated and added new test cases for CLI.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 29e3c8da1bd3971215036e5f5cfa5b25c6caa81f
User & Date: shaneh 2009-12-17 21:07:54
Context
2009-12-17
22:12
Fixed some TCL test cases to work if SQLITE_OMIT_TRIGGER is defined. check-in: 85e3c734 user: shaneh tags: trunk
21:07
Updated and added new test cases for CLI. check-in: 29e3c8da user: shaneh tags: trunk
21:07
In shell.c (CLI), modified local_getline() to remove '\r' as well as '\n' from end of lines. This provides consistency between MSVC and CYGWIN builds. check-in: b1b48be1 user: shaneh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tool/shell1.test.

    19     19   #   shell1-1.*: Basic command line option handling.
    20     20   #   shell1-2.*: Basic "dot" command token parsing.
    21     21   #   shell1-3.*: Basic test that "dot" command can be called.
    22     22   #
    23     23   
    24     24   package require sqlite3
    25     25   
    26         -set CLI "./sqlite"
           26  +set CLI "./sqlite3"
    27     27   
    28     28   proc do_test {name cmd expected} {
    29     29     puts -nonewline "$name ..."
    30     30     set res [uplevel $cmd]
    31     31     if {$res eq $expected} {
    32     32       puts Ok
    33     33     } else {
................................................................................
    43     43   }
    44     44   
    45     45   proc catchsql {sql} {
    46     46     set rc [catch {uplevel [list db eval $sql]} msg]
    47     47     list $rc $msg
    48     48   }
    49     49   
    50         -proc catchcmd {db cmd} {
           50  +proc catchcmd {db {cmd ""}} {
    51     51     global CLI
    52     52     set out [open cmds.txt w]
    53     53     puts $out $cmd
    54     54     close $out
    55     55     set line "exec $CLI $db < cmds.txt"
    56     56     set rc [catch { eval $line } msg]
    57     57     list $rc $msg
................................................................................
    75     75   do_test shell1-1.1.2 {
    76     76     set res [catchcmd "-bad test.db \"select 3\" \"select 4\"" ""]
    77     77     set rc [lindex $res 0]
    78     78     list $rc \
    79     79          [regexp {Error: too many options: "select 4"} $res]
    80     80   } {1 1}
    81     81   # error on extra options
    82         -do_test shell1-1.3.2 {
           82  +do_test shell1-1.1.3 {
    83     83     set res [catchcmd "-bad FOO test.db BAD" ".quit"]
    84     84     set rc [lindex $res 0]
    85     85     list $rc \
    86     86          [regexp {Error: too many options: "BAD"} $res]
    87     87   } {1 1}
    88     88   
    89     89   # -help
................................................................................
    94     94          [regexp {Usage} $res] \
    95     95          [regexp {\-init} $res] \
    96     96          [regexp {\-version} $res]
    97     97   } {1 1 1 1}
    98     98   
    99     99   # -init filename       read/process named file
   100    100   do_test shell1-1.3.1 {
   101         -  catchcmd "-init FOO test.db" "" 
          101  +  catchcmd "-init FOO test.db" ""
   102    102   } {0 {}}
   103    103   do_test shell1-1.3.2 {
   104    104     set res [catchcmd "-init FOO test.db .quit BAD" ""]
   105    105     set rc [lindex $res 0]
   106    106     list $rc \
   107    107          [regexp {Error: too many options: "BAD"} $res]
   108    108   } {1 1}
................................................................................
   191    191     list $rc \
   192    192          [regexp {Error: missing argument for option: -nullvalue} $res]
   193    193   } {1 1}
   194    194   
   195    195   # -version             show SQLite version
   196    196   do_test shell1-1.16.1 {
   197    197     catchcmd "-version test.db" "" 
   198         -} {0 3.6.20}
          198  +} {0 3.6.21}
   199    199   
   200    200   #----------------------------------------------------------------------------
   201    201   # Test cases shell1-2.*: Basic "dot" command token parsing.
   202    202   #
   203    203   
   204    204   # check first token handling
   205    205   do_test shell1-2.1.1 {
   206         -  catchcmd " test.db" ".foo" 
          206  +  catchcmd "test.db" ".foo" 
   207    207   } {1 {Error: unknown command or invalid arguments:  "foo". Enter ".help" for help}}
   208    208   do_test shell1-2.1.2 {
   209         -  catchcmd " test.db" ".\"foo OFF\""
          209  +  catchcmd "test.db" ".\"foo OFF\""
   210    210   } {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
   211    211   do_test shell1-2.1.3 {
   212         -  catchcmd " test.db" ".\'foo OFF\'"
          212  +  catchcmd "test.db" ".\'foo OFF\'"
   213    213   } {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
   214    214   
   215    215   # unbalanced quotes
   216    216   do_test shell1-2.2.1 {
   217         -  catchcmd " test.db" ".\"foo OFF"
          217  +  catchcmd "test.db" ".\"foo OFF"
   218    218   } {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
   219    219   do_test shell1-2.2.2 {
   220         -  catchcmd " test.db" ".\'foo OFF"
          220  +  catchcmd "test.db" ".\'foo OFF"
   221    221   } {1 {Error: unknown command or invalid arguments:  "foo OFF". Enter ".help" for help}}
   222    222   do_test shell1-2.2.3 {
   223         -  catchcmd " test.db" ".explain \"OFF"
          223  +  catchcmd "test.db" ".explain \"OFF"
   224    224   } {0 {}}
   225    225   do_test shell1-2.2.4 {
   226         -  catchcmd " test.db" ".explain \'OFF"
          226  +  catchcmd "test.db" ".explain \'OFF"
   227    227   } {0 {}}
   228    228   do_test shell1-2.2.5 {
   229         -  catchcmd " test.db" ".mode \"insert FOO"
          229  +  catchcmd "test.db" ".mode \"insert FOO"
   230    230   } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
   231    231   do_test shell1-2.2.6 {
   232         -  catchcmd " test.db" ".mode \'insert FOO"
          232  +  catchcmd "test.db" ".mode \'insert FOO"
   233    233   } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
   234    234   
   235    235   # check multiple tokens, and quoted tokens
   236    236   do_test shell1-2.3.1 {
   237         -  catchcmd " test.db" ".explain 1"
          237  +  catchcmd "test.db" ".explain 1"
   238    238   } {0 {}}
   239    239   do_test shell1-2.3.2 {
   240         -  catchcmd " test.db" ".explain on"
          240  +  catchcmd "test.db" ".explain on"
   241    241   } {0 {}}
   242    242   do_test shell1-2.3.3 {
   243         -  catchcmd " test.db" ".explain \"1 2 3\""
          243  +  catchcmd "test.db" ".explain \"1 2 3\""
   244    244   } {0 {}}
   245    245   do_test shell1-2.3.4 {
   246         -  catchcmd " test.db" ".explain \"OFF\""
          246  +  catchcmd "test.db" ".explain \"OFF\""
   247    247   } {0 {}}
   248    248   do_test shell1-2.3.5 {
   249         -  catchcmd " test.db" ".\'explain\' \'OFF\'"
          249  +  catchcmd "test.db" ".\'explain\' \'OFF\'"
   250    250   } {0 {}}
   251    251   do_test shell1-2.3.6 {
   252         -  catchcmd " test.db" ".explain \'OFF\'"
          252  +  catchcmd "test.db" ".explain \'OFF\'"
   253    253   } {0 {}}
   254    254   do_test shell1-2.3.7 {
   255         -  catchcmd " test.db" ".\'explain\' \'OFF\'"
          255  +  catchcmd "test.db" ".\'explain\' \'OFF\'"
   256    256   } {0 {}}
   257    257   
   258    258   # check quoted args are unquoted
   259    259   do_test shell1-2.4.1 {
   260         -  catchcmd " test.db" ".mode FOO"
          260  +  catchcmd "test.db" ".mode FOO"
   261    261   } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
   262    262   do_test shell1-2.4.2 {
   263         -  catchcmd " test.db" ".mode csv"
          263  +  catchcmd "test.db" ".mode csv"
   264    264   } {0 {}}
   265    265   do_test shell1-2.4.2 {
   266         -  catchcmd " test.db" ".mode \"csv\""
          266  +  catchcmd "test.db" ".mode \"csv\""
   267    267   } {0 {}}
   268    268   
   269    269   
   270    270   #----------------------------------------------------------------------------
   271    271   # Test cases shell1-3.*: Basic test that "dot" command can be called.
   272    272   #
   273    273   
   274    274   # .backup ?DB? FILE      Backup DB (default "main") to FILE
   275    275   do_test shell1-3.1.1 {
   276         -  catchcmd " test.db" ".backup"
          276  +  catchcmd "test.db" ".backup"
   277    277   } {1 {Error: unknown command or invalid arguments:  "backup". Enter ".help" for help}}
   278    278   do_test shell1-3.1.2 {
   279         -  # catchcmd " test.db" ".backup FOO"
   280         -  #TBD!!! this asserts currently
   281         -} {}
          279  +  catchcmd "test.db" ".backup FOO"
          280  +} {0 {}}
   282    281   do_test shell1-3.1.3 {
   283         -  catchcmd " test.db" ".backup FOO BAR"
          282  +  catchcmd "test.db" ".backup FOO BAR"
   284    283   } {1 {Error: unknown database FOO}}
   285    284   do_test shell1-3.1.4 {
   286    285     # too many arguments
   287         -  catchcmd " test.db" ".backup FOO BAR BAD"
          286  +  catchcmd "test.db" ".backup FOO BAR BAD"
   288    287   } {1 {Error: unknown command or invalid arguments:  "backup". Enter ".help" for help}}
   289    288   
   290    289   # .bail ON|OFF           Stop after hitting an error.  Default OFF
   291    290   do_test shell1-3.2.1 {
   292         -  catchcmd " test.db" ".bail"
          291  +  catchcmd "test.db" ".bail"
   293    292   } {1 {Error: unknown command or invalid arguments:  "bail". Enter ".help" for help}}
   294    293   do_test shell1-3.2.2 {
   295         -  catchcmd " test.db" ".bail ON"
          294  +  catchcmd "test.db" ".bail ON"
   296    295   } {0 {}}
   297    296   do_test shell1-3.2.3 {
   298         -  catchcmd " test.db" ".bail OFF"
          297  +  catchcmd "test.db" ".bail OFF"
   299    298   } {0 {}}
   300    299   do_test shell1-3.2.4 {
   301    300     # too many arguments
   302         -  catchcmd " test.db" ".bail OFF BAD"
          301  +  catchcmd "test.db" ".bail OFF BAD"
   303    302   } {1 {Error: unknown command or invalid arguments:  "bail". Enter ".help" for help}}
   304    303   
   305    304   # .databases             List names and files of attached databases
   306    305   do_test shell1-3.3.1 {
   307         -  set res [catchcmd " test.db" ".databases"]
          306  +  set res [catchcmd "test.db" ".databases"]
   308    307     regexp {0.*main.*test\.db} $res
   309    308   } {1}
   310    309   do_test shell1-3.3.2 {
   311    310     # too many arguments
   312         -  catchcmd " test.db" ".databases BAD"
          311  +  catchcmd "test.db" ".databases BAD"
   313    312   } {1 {Error: unknown command or invalid arguments:  "databases". Enter ".help" for help}}
   314    313   
   315    314   # .dump ?TABLE? ...      Dump the database in an SQL text format
   316    315   #                          If TABLE specified, only dump tables matching
   317    316   #                          LIKE pattern TABLE.
   318    317   do_test shell1-3.4.1 {
   319         -  set res [catchcmd " test.db" ".dump"]
          318  +  set res [catchcmd "test.db" ".dump"]
   320    319     list [regexp {BEGIN TRANSACTION;} $res] \
   321    320          [regexp {COMMIT;} $res]
   322    321   } {1 1}
   323    322   do_test shell1-3.4.2 {
   324         -  set res [catchcmd " test.db" ".dump FOO"]
          323  +  set res [catchcmd "test.db" ".dump FOO"]
   325    324     list [regexp {BEGIN TRANSACTION;} $res] \
   326    325          [regexp {COMMIT;} $res]
   327    326   } {1 1}
   328    327   do_test shell1-3.4.3 {
   329    328     # too many arguments
   330         -  catchcmd " test.db" ".dump FOO BAD"
          329  +  catchcmd "test.db" ".dump FOO BAD"
   331    330   } {1 {Error: unknown command or invalid arguments:  "dump". Enter ".help" for help}}
   332    331   
   333    332   # .echo ON|OFF           Turn command echo on or off
   334    333   do_test shell1-3.5.1 {
   335         -  catchcmd " test.db" ".echo"
          334  +  catchcmd "test.db" ".echo"
   336    335   } {1 {Error: unknown command or invalid arguments:  "echo". Enter ".help" for help}}
   337    336   do_test shell1-3.5.2 {
   338         -  catchcmd " test.db" ".echo ON"
          337  +  catchcmd "test.db" ".echo ON"
   339    338   } {0 {}}
   340    339   do_test shell1-3.5.3 {
   341         -  catchcmd " test.db" ".echo OFF"
          340  +  catchcmd "test.db" ".echo OFF"
   342    341   } {0 {}}
   343    342   do_test shell1-3.5.4 {
   344    343     # too many arguments
   345         -  catchcmd " test.db" ".echo OFF BAD"
          344  +  catchcmd "test.db" ".echo OFF BAD"
   346    345   } {1 {Error: unknown command or invalid arguments:  "echo". Enter ".help" for help}}
   347    346   
   348    347   # .exit                  Exit this program
   349    348   do_test shell1-3.6.1 {
   350         -  catchcmd " test.db" ".exit"
          349  +  catchcmd "test.db" ".exit"
   351    350   } {0 {}}
   352    351   do_test shell1-3.6.2 {
   353    352     # too many arguments
   354         -  catchcmd " test.db" ".exit BAD"
          353  +  catchcmd "test.db" ".exit BAD"
   355    354   } {1 {Error: unknown command or invalid arguments:  "exit". Enter ".help" for help}}
   356    355   
   357    356   # .explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.
   358    357   do_test shell1-3.7.1 {
   359         -  catchcmd " test.db" ".explain"
          358  +  catchcmd "test.db" ".explain"
   360    359     # explain is the exception to the booleans.  without an option, it turns it on.
   361    360   } {0 {}}
   362    361   do_test shell1-3.7.2 {
   363         -  catchcmd " test.db" ".explain ON"
          362  +  catchcmd "test.db" ".explain ON"
   364    363   } {0 {}}
   365    364   do_test shell1-3.7.3 {
   366         -  catchcmd " test.db" ".explain OFF"
          365  +  catchcmd "test.db" ".explain OFF"
   367    366   } {0 {}}
   368    367   do_test shell1-3.7.4 {
   369    368     # too many arguments
   370         -  catchcmd " test.db" ".explain OFF BAD"
          369  +  catchcmd "test.db" ".explain OFF BAD"
   371    370   } {1 {Error: unknown command or invalid arguments:  "explain". Enter ".help" for help}}
   372    371   
   373    372   # .genfkey ?OPTIONS?     Options are:
   374    373   #                          --no-drop: Do not drop old fkey triggers.
   375    374   #                          --ignore-errors: Ignore tables with fkey errors
   376    375   #                          --exec: Execute generated SQL immediately
   377    376   #                        See file tool/genfkey.README in the source
   378    377   #                        distribution for further information.
   379    378   do_test shell1-3.8.1 {
   380         -  catchcmd " test.db" ".genfkey"
          379  +  catchcmd "test.db" ".genfkey"
   381    380   } {0 {}}
   382    381   do_test shell1-3.8.2 {
   383         -  catchcmd " test.db" ".genfkey FOO"
          382  +  catchcmd "test.db" ".genfkey FOO"
   384    383   } {1 {unknown option: FOO}}
   385    384   
   386    385   # .header(s) ON|OFF      Turn display of headers on or off
   387    386   do_test shell1-3.9.1 {
   388         -  catchcmd " test.db" ".header"
          387  +  catchcmd "test.db" ".header"
   389    388   } {1 {Error: unknown command or invalid arguments:  "header". Enter ".help" for help}}
   390    389   do_test shell1-3.9.2 {
   391         -  catchcmd " test.db" ".header ON"
          390  +  catchcmd "test.db" ".header ON"
   392    391   } {0 {}}
   393    392   do_test shell1-3.9.3 {
   394         -  catchcmd " test.db" ".header OFF"
          393  +  catchcmd "test.db" ".header OFF"
   395    394   } {0 {}}
   396    395   do_test shell1-3.9.4 {
   397    396     # too many arguments
   398         -  catchcmd " test.db" ".header OFF BAD"
          397  +  catchcmd "test.db" ".header OFF BAD"
   399    398   } {1 {Error: unknown command or invalid arguments:  "header". Enter ".help" for help}}
   400    399   
   401    400   do_test shell1-3.9.5 {
   402         -  catchcmd " test.db" ".headers"
          401  +  catchcmd "test.db" ".headers"
   403    402   } {1 {Error: unknown command or invalid arguments:  "headers". Enter ".help" for help}}
   404    403   do_test shell1-3.9.6 {
   405         -  catchcmd " test.db" ".headers ON"
          404  +  catchcmd "test.db" ".headers ON"
   406    405   } {0 {}}
   407    406   do_test shell1-3.9.7 {
   408         -  catchcmd " test.db" ".headers OFF"
          407  +  catchcmd "test.db" ".headers OFF"
   409    408   } {0 {}}
   410    409   do_test shell1-3.9.8 {
   411    410     # too many arguments
   412         -  catchcmd " test.db" ".headers OFF BAD"
          411  +  catchcmd "test.db" ".headers OFF BAD"
   413    412   } {1 {Error: unknown command or invalid arguments:  "headers". Enter ".help" for help}}
   414    413   
   415    414   # .help                  Show this message
   416    415   do_test shell1-3.10.1 {
   417         -  set res [catchcmd " test.db" ".help"]
          416  +  set res [catchcmd "test.db" ".help"]
   418    417     # look for a few of the possible help commands
   419    418     list [regexp {.help} $res] \
   420    419          [regexp {.quit} $res] \
   421    420          [regexp {.show} $res]
   422    421   } {1 1 1}
   423    422   do_test shell1-3.10.2 {
   424    423     # we allow .help to take extra args (it is help after all)
   425         -  set res [catchcmd " test.db" ".help BAD"]
          424  +  set res [catchcmd "test.db" ".help BAD"]
   426    425     # look for a few of the possible help commands
   427    426     list [regexp {.help} $res] \
   428    427          [regexp {.quit} $res] \
   429    428          [regexp {.show} $res]
   430    429   } {1 1 1}
   431    430   
   432    431   # .import FILE TABLE     Import data from FILE into TABLE
   433    432   do_test shell1-3.11.1 {
   434         -  catchcmd " test.db" ".import"
          433  +  catchcmd "test.db" ".import"
   435    434   } {1 {Error: unknown command or invalid arguments:  "import". Enter ".help" for help}}
   436    435   do_test shell1-3.11.2 {
   437         -  catchcmd " test.db" ".import FOO"
          436  +  catchcmd "test.db" ".import FOO"
   438    437   } {1 {Error: unknown command or invalid arguments:  "import". Enter ".help" for help}}
   439    438   do_test shell1-3.11.2 {
   440         -  catchcmd " test.db" ".import FOO BAR"
          439  +  catchcmd "test.db" ".import FOO BAR"
   441    440   } {1 {Error: no such table: BAR}}
   442    441   do_test shell1-3.11.3 {
   443    442     # too many arguments
   444         -  catchcmd " test.db" ".import FOO BAR BAD"
          443  +  catchcmd "test.db" ".import FOO BAR BAD"
   445    444   } {1 {Error: unknown command or invalid arguments:  "import". Enter ".help" for help}}
   446    445   
   447    446   # .indices ?TABLE?       Show names of all indices
   448    447   #                          If TABLE specified, only show indices for tables
   449    448   #                          matching LIKE pattern TABLE.
   450    449   do_test shell1-3.12.1 {
   451         -  catchcmd " test.db" ".indices"
          450  +  catchcmd "test.db" ".indices"
   452    451   } {0 {}}
   453    452   do_test shell1-3.12.2 {
   454         -  catchcmd " test.db" ".indices FOO"
          453  +  catchcmd "test.db" ".indices FOO"
   455    454   } {0 {}}
   456    455   do_test shell1-3.12.3 {
   457    456     # too many arguments
   458         -  catchcmd " test.db" ".indices FOO BAD"
          457  +  catchcmd "test.db" ".indices FOO BAD"
   459    458   } {1 {Error: unknown command or invalid arguments:  "indices". Enter ".help" for help}}
   460    459   
   461    460   # .mode MODE ?TABLE?     Set output mode where MODE is one of:
   462    461   #                          csv      Comma-separated values
   463    462   #                          column   Left-aligned columns.  (See .width)
   464    463   #                          html     HTML <table> code
   465    464   #                          insert   SQL insert statements for TABLE
   466    465   #                          line     One value per line
   467    466   #                          list     Values delimited by .separator string
   468    467   #                          tabs     Tab-separated values
   469    468   #                          tcl      TCL list elements
   470    469   do_test shell1-3.13.1 {
   471         -  catchcmd " test.db" ".mode"
          470  +  catchcmd "test.db" ".mode"
   472    471   } {1 {Error: unknown command or invalid arguments:  "mode". Enter ".help" for help}}
   473    472   do_test shell1-3.13.2 {
   474         -  catchcmd " test.db" ".mode FOO"
          473  +  catchcmd "test.db" ".mode FOO"
   475    474   } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
   476    475   do_test shell1-3.13.3 {
   477         -  catchcmd " test.db" ".mode csv"
          476  +  catchcmd "test.db" ".mode csv"
   478    477   } {0 {}}
   479    478   do_test shell1-3.13.4 {
   480         -  catchcmd " test.db" ".mode column"
          479  +  catchcmd "test.db" ".mode column"
   481    480   } {0 {}}
   482    481   do_test shell1-3.13.5 {
   483         -  catchcmd " test.db" ".mode html"
          482  +  catchcmd "test.db" ".mode html"
   484    483   } {0 {}}
   485    484   do_test shell1-3.13.6 {
   486         -  catchcmd " test.db" ".mode insert"
          485  +  catchcmd "test.db" ".mode insert"
   487    486   } {0 {}}
   488    487   do_test shell1-3.13.7 {
   489         -  catchcmd " test.db" ".mode line"
          488  +  catchcmd "test.db" ".mode line"
   490    489   } {0 {}}
   491    490   do_test shell1-3.13.8 {
   492         -  catchcmd " test.db" ".mode list"
          491  +  catchcmd "test.db" ".mode list"
   493    492   } {0 {}}
   494    493   do_test shell1-3.13.9 {
   495         -  catchcmd " test.db" ".mode tabs"
          494  +  catchcmd "test.db" ".mode tabs"
   496    495   } {0 {}}
   497    496   do_test shell1-3.13.10 {
   498         -  catchcmd " test.db" ".mode tcl"
          497  +  catchcmd "test.db" ".mode tcl"
   499    498   } {0 {}}
   500    499   do_test shell1-3.13.11 {
   501    500     # too many arguments
   502         -  catchcmd " test.db" ".mode tcl BAD"
          501  +  catchcmd "test.db" ".mode tcl BAD"
   503    502   } {1 {Error: invalid arguments:  "BAD". Enter ".help" for help}}
   504    503   
   505    504   # don't allow partial mode type matches
   506    505   do_test shell1-3.13.12 {
   507         -  catchcmd " test.db" ".mode l"
          506  +  catchcmd "test.db" ".mode l"
   508    507   } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
   509    508   do_test shell1-3.13.13 {
   510         -  catchcmd " test.db" ".mode li"
          509  +  catchcmd "test.db" ".mode li"
   511    510   } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
   512    511   do_test shell1-3.13.14 {
   513         -  catchcmd " test.db" ".mode lin"
          512  +  catchcmd "test.db" ".mode lin"
   514    513   } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
   515    514   
   516    515   # .nullvalue STRING      Print STRING in place of NULL values
   517    516   do_test shell1-3.14.1 {
   518         -  catchcmd " test.db" ".nullvalue"
          517  +  catchcmd "test.db" ".nullvalue"
   519    518   } {1 {Error: unknown command or invalid arguments:  "nullvalue". Enter ".help" for help}}
   520    519   do_test shell1-3.14.2 {
   521         -  catchcmd " test.db" ".nullvalue FOO"
          520  +  catchcmd "test.db" ".nullvalue FOO"
   522    521   } {0 {}}
   523    522   do_test shell1-3.14.3 {
   524    523     # too many arguments
   525         -  catchcmd " test.db" ".nullvalue FOO BAD"
          524  +  catchcmd "test.db" ".nullvalue FOO BAD"
   526    525   } {1 {Error: unknown command or invalid arguments:  "nullvalue". Enter ".help" for help}}
   527    526   
   528    527   # .output FILENAME       Send output to FILENAME
   529    528   do_test shell1-3.15.1 {
   530         -  catchcmd " test.db" ".output"
          529  +  catchcmd "test.db" ".output"
   531    530   } {1 {Error: unknown command or invalid arguments:  "output". Enter ".help" for help}}
   532    531   do_test shell1-3.15.2 {
   533         -  catchcmd " test.db" ".output FOO"
          532  +  catchcmd "test.db" ".output FOO"
   534    533   } {0 {}}
   535    534   do_test shell1-3.15.3 {
   536    535     # too many arguments
   537         -  catchcmd " test.db" ".output FOO BAD"
          536  +  catchcmd "test.db" ".output FOO BAD"
   538    537   } {1 {Error: unknown command or invalid arguments:  "output". Enter ".help" for help}}
   539    538   
   540    539   # .output stdout         Send output to the screen
   541    540   do_test shell1-3.16.1 {
   542         -  catchcmd " test.db" ".output stdout"
          541  +  catchcmd "test.db" ".output stdout"
   543    542   } {0 {}}
   544    543   do_test shell1-3.16.2 {
   545    544     # too many arguments
   546         -  catchcmd " test.db" ".output stdout BAD"
          545  +  catchcmd "test.db" ".output stdout BAD"
   547    546   } {1 {Error: unknown command or invalid arguments:  "output". Enter ".help" for help}}
   548    547   
   549    548   # .prompt MAIN CONTINUE  Replace the standard prompts
   550    549   do_test shell1-3.17.1 {
   551         -  catchcmd " test.db" ".prompt"
          550  +  catchcmd "test.db" ".prompt"
   552    551   } {1 {Error: unknown command or invalid arguments:  "prompt". Enter ".help" for help}}
   553    552   do_test shell1-3.17.2 {
   554         -  catchcmd " test.db" ".prompt FOO"
          553  +  catchcmd "test.db" ".prompt FOO"
   555    554   } {0 {}}
   556    555   do_test shell1-3.17.3 {
   557         -  catchcmd " test.db" ".prompt FOO BAR"
          556  +  catchcmd "test.db" ".prompt FOO BAR"
   558    557   } {0 {}}
   559    558   do_test shell1-3.17.4 {
   560    559     # too many arguments
   561         -  catchcmd " test.db" ".prompt FOO BAR BAD"
          560  +  catchcmd "test.db" ".prompt FOO BAR BAD"
   562    561   } {1 {Error: unknown command or invalid arguments:  "prompt". Enter ".help" for help}}
   563    562   
   564    563   # .quit                  Exit this program
   565    564   do_test shell1-3.18.1 {
   566         -  catchcmd " test.db" ".quit"
          565  +  catchcmd "test.db" ".quit"
   567    566   } {0 {}}
   568    567   do_test shell1-3.18.2 {
   569    568     # too many arguments
   570         -  catchcmd " test.db" ".quit BAD"
          569  +  catchcmd "test.db" ".quit BAD"
   571    570   } {1 {Error: unknown command or invalid arguments:  "quit". Enter ".help" for help}}
   572    571   
   573    572   # .read FILENAME         Execute SQL in FILENAME
   574    573   do_test shell1-3.19.1 {
   575         -  catchcmd " test.db" ".read"
          574  +  catchcmd "test.db" ".read"
   576    575   } {1 {Error: unknown command or invalid arguments:  "read". Enter ".help" for help}}
   577    576   do_test shell1-3.19.2 {
   578    577     file delete -force FOO
   579         -  catchcmd " test.db" ".read FOO"
          578  +  catchcmd "test.db" ".read FOO"
   580    579   } {1 {Error: cannot open "FOO"}}
   581    580   do_test shell1-3.19.3 {
   582    581     # too many arguments
   583         -  catchcmd " test.db" ".read FOO BAD"
          582  +  catchcmd "test.db" ".read FOO BAD"
   584    583   } {1 {Error: unknown command or invalid arguments:  "read". Enter ".help" for help}}
   585    584   
   586    585   # .restore ?DB? FILE     Restore content of DB (default "main") from FILE
   587    586   do_test shell1-3.20.1 {
   588         -  catchcmd " test.db" ".restore"
          587  +  catchcmd "test.db" ".restore"
   589    588   } {1 {Error: unknown command or invalid arguments:  "restore". Enter ".help" for help}}
   590    589   do_test shell1-3.20.2 {
   591         -  # catchcmd " test.db" ".restore FOO"
   592         -  #TBD!!! this asserts currently
   593         -} {}
          590  +  catchcmd "test.db" ".restore FOO"
          591  +} {0 {}}
   594    592   do_test shell1-3.20.3 {
   595         -  catchcmd " test.db" ".restore FOO BAR"
          593  +  catchcmd "test.db" ".restore FOO BAR"
   596    594   } {1 {Error: unknown database FOO}}
   597    595   do_test shell1-3.20.4 {
   598    596     # too many arguments
   599         -  catchcmd " test.db" ".restore FOO BAR BAD"
          597  +  catchcmd "test.db" ".restore FOO BAR BAD"
   600    598   } {1 {Error: unknown command or invalid arguments:  "restore". Enter ".help" for help}}
   601    599   
   602    600   # .schema ?TABLE?        Show the CREATE statements
   603    601   #                          If TABLE specified, only show tables matching
   604    602   #                          LIKE pattern TABLE.
   605    603   do_test shell1-3.21.1 {
   606         -  catchcmd " test.db" ".schema"
          604  +  catchcmd "test.db" ".schema"
   607    605   } {0 {}}
   608    606   do_test shell1-3.21.2 {
   609         -  catchcmd " test.db" ".schema FOO"
          607  +  catchcmd "test.db" ".schema FOO"
   610    608   } {0 {}}
   611    609   do_test shell1-3.21.3 {
   612    610     # too many arguments
   613         -  catchcmd " test.db" ".schema FOO BAD"
          611  +  catchcmd "test.db" ".schema FOO BAD"
   614    612   } {1 {Error: unknown command or invalid arguments:  "schema". Enter ".help" for help}}
   615    613   
   616    614   # .separator STRING      Change separator used by output mode and .import
   617    615   do_test shell1-3.22.1 {
   618         -  catchcmd " test.db" ".separator"
          616  +  catchcmd "test.db" ".separator"
   619    617   } {1 {Error: unknown command or invalid arguments:  "separator". Enter ".help" for help}}
   620    618   do_test shell1-3.22.2 {
   621         -  catchcmd " test.db" ".separator FOO"
          619  +  catchcmd "test.db" ".separator FOO"
   622    620   } {0 {}}
   623    621   do_test shell1-3.22.3 {
   624    622     # too many arguments
   625         -  catchcmd " test.db" ".separator FOO BAD"
          623  +  catchcmd "test.db" ".separator FOO BAD"
   626    624   } {1 {Error: unknown command or invalid arguments:  "separator". Enter ".help" for help}}
   627    625   
   628    626   # .show                  Show the current values for various settings
   629    627   do_test shell1-3.23.1 {
   630         -  set res [catchcmd " test.db" ".show"]
          628  +  set res [catchcmd "test.db" ".show"]
   631    629     list [regexp {echo:} $res] \
   632    630          [regexp {explain:} $res] \
   633    631          [regexp {headers:} $res] \
   634    632          [regexp {mode:} $res] \
   635    633          [regexp {nullvalue:} $res] \
   636    634          [regexp {output:} $res] \
   637    635          [regexp {separator:} $res] \
   638    636          [regexp {width:} $res]
   639    637   } {1 1 1 1 1 1 1 1}
   640    638   do_test shell1-3.23.2 {
   641    639     # too many arguments
   642         -  catchcmd " test.db" ".show BAD"
          640  +  catchcmd "test.db" ".show BAD"
   643    641   } {1 {Error: unknown command or invalid arguments:  "show". Enter ".help" for help}}
   644    642   
   645    643   # .tables ?TABLE?        List names of tables
   646    644   #                          If TABLE specified, only list tables matching
   647    645   #                          LIKE pattern TABLE.
   648    646   do_test shell1-3.24.1 {
   649         -  catchcmd " test.db" ".tables"
          647  +  catchcmd "test.db" ".tables"
   650    648   } {0 {}}
   651    649   do_test shell1-3.24.2 {
   652         -  catchcmd " test.db" ".tables FOO"
          650  +  catchcmd "test.db" ".tables FOO"
   653    651   } {0 {}}
   654    652   do_test shell1-3.24.3 {
   655    653     # too many arguments
   656         -  catchcmd " test.db" ".tables FOO BAD"
          654  +  catchcmd "test.db" ".tables FOO BAD"
   657    655   } {1 {Error: unknown command or invalid arguments:  "tables". Enter ".help" for help}}
   658    656   
   659    657   # .timeout MS            Try opening locked tables for MS milliseconds
   660    658   do_test shell1-3.25.1 {
   661         -  catchcmd " test.db" ".timeout"
          659  +  catchcmd "test.db" ".timeout"
   662    660   } {1 {Error: unknown command or invalid arguments:  "timeout". Enter ".help" for help}}
   663    661   do_test shell1-3.25.2 {
   664         -  catchcmd " test.db" ".timeout zzz"
          662  +  catchcmd "test.db" ".timeout zzz"
   665    663     # this should be treated the same as a '0' timeout
   666    664   } {0 {}}
   667    665   do_test shell1-3.25.3 {
   668         -  catchcmd " test.db" ".timeout 1"
          666  +  catchcmd "test.db" ".timeout 1"
   669    667   } {0 {}}
   670    668   do_test shell1-3.25.4 {
   671    669     # too many arguments
   672         -  catchcmd " test.db" ".timeout 1 BAD"
          670  +  catchcmd "test.db" ".timeout 1 BAD"
   673    671   } {1 {Error: unknown command or invalid arguments:  "timeout". Enter ".help" for help}}
   674    672   
   675    673   # .width NUM NUM ...     Set column widths for "column" mode
   676    674   do_test shell1-3.26.1 {
   677         -  catchcmd " test.db" ".width"
          675  +  catchcmd "test.db" ".width"
   678    676   } {1 {Error: unknown command or invalid arguments:  "width". Enter ".help" for help}}
   679    677   do_test shell1-3.26.2 {
   680         -  catchcmd " test.db" ".width xxx"
          678  +  catchcmd "test.db" ".width xxx"
   681    679     # this should be treated the same as a '0' width for col 1
   682    680   } {0 {}}
   683    681   do_test shell1-3.26.3 {
   684         -  catchcmd " test.db" ".width xxx yyy"
          682  +  catchcmd "test.db" ".width xxx yyy"
   685    683     # this should be treated the same as a '0' width for col 1 and 2
   686    684   } {0 {}}
   687    685   do_test shell1-3.26.4 {
   688         -  catchcmd " test.db" ".width 1 1"
          686  +  catchcmd "test.db" ".width 1 1"
   689    687     # this should be treated the same as a '1' width for col 1 and 2
   690    688   } {0 {}}
   691    689   
   692    690   # .timer ON|OFF          Turn the CPU timer measurement on or off
   693    691   do_test shell1-3.27.1 {
   694         -  catchcmd " test.db" ".timer"
          692  +  catchcmd "test.db" ".timer"
   695    693   } {1 {Error: unknown command or invalid arguments:  "timer". Enter ".help" for help}}
   696    694   do_test shell1-3.27.2 {
   697         -  catchcmd " test.db" ".timer ON"
          695  +  catchcmd "test.db" ".timer ON"
   698    696   } {0 {}}
   699    697   do_test shell1-3.27.3 {
   700         -  catchcmd " test.db" ".timer OFF"
          698  +  catchcmd "test.db" ".timer OFF"
   701    699   } {0 {}}
   702    700   do_test shell1-3.27.4 {
   703    701     # too many arguments
   704         -  catchcmd " test.db" ".timer OFF BAD"
          702  +  catchcmd "test.db" ".timer OFF BAD"
   705    703   } {1 {Error: unknown command or invalid arguments:  "timer". Enter ".help" for help}}
   706    704   
   707         -# 
          705  +
          706  +#

Changes to tool/shell2.test.

    17     17   # Test plan:
    18     18   #
    19     19   #   shell2-1.*: Misc. test of various tickets and reported errors.
    20     20   #
    21     21   
    22     22   package require sqlite3
    23     23   
    24         -set CLI "./sqlite"
           24  +set CLI "./sqlite3"
    25     25   
    26     26   proc do_test {name cmd expected} {
    27     27     puts -nonewline "$name ..."
    28     28     set res [uplevel $cmd]
    29     29     if {$res eq $expected} {
    30     30       puts Ok
    31     31     } else {
................................................................................
    41     41   }
    42     42   
    43     43   proc catchsql {sql} {
    44     44     set rc [catch {uplevel [list db eval $sql]} msg]
    45     45     list $rc $msg
    46     46   }
    47     47   
    48         -proc catchcmd {db cmd} {
           48  +proc catchcmd {db {cmd ""}} {
    49     49     global CLI
    50     50     set out [open cmds.txt w]
    51     51     puts $out $cmd
    52     52     close $out
    53     53     set line "exec $CLI $db < cmds.txt"
    54     54     set rc [catch { eval $line } msg]
    55     55     list $rc $msg

Added tool/shell3.test.

            1  +# 2009 Dec 16
            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: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
           15  +#
           16  +
           17  +# Test plan:
           18  +#
           19  +#   shell3-1.*: Basic tests for running SQL statments from command line.
           20  +#   shell3-2.*: Basic tests for running SQL file from command line.
           21  +#
           22  +
           23  +package require sqlite3
           24  +
           25  +set CLI "./sqlite3"
           26  +
           27  +proc do_test {name cmd expected} {
           28  +  puts -nonewline "$name ..."
           29  +  set res [uplevel $cmd]
           30  +  if {$res eq $expected} {
           31  +    puts Ok
           32  +  } else {
           33  +    puts Error
           34  +    puts "  Got: $res"
           35  +    puts "  Expected: $expected"
           36  +    exit
           37  +  }
           38  +}
           39  +
           40  +proc execsql {sql} {
           41  +  uplevel [list db eval $sql]
           42  +}
           43  +
           44  +proc catchsql {sql} {
           45  +  set rc [catch {uplevel [list db eval $sql]} msg]
           46  +  list $rc $msg
           47  +}
           48  +
           49  +proc catchcmd {db {cmd ""}} {
           50  +  global CLI
           51  +  set out [open cmds.txt w]
           52  +  puts $out $cmd
           53  +  close $out
           54  +  set line "exec $CLI $db < cmds.txt"
           55  +  set rc [catch { eval $line } msg]
           56  +  list $rc $msg
           57  +}
           58  +
           59  +file delete -force test.db test.db.journal
           60  +sqlite3 db test.db
           61  +
           62  +
           63  +#----------------------------------------------------------------------------
           64  +#   shell3-1.*: Basic tests for running SQL statments from command line.
           65  +#
           66  +
           67  +# Run SQL statement from command line
           68  +do_test shell3-1.1 {
           69  +  file delete -force foo.db
           70  +  set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
           71  +  set fexist [file exist foo.db]
           72  +  list $rc $fexist
           73  +} {{0 {}} 1}
           74  +do_test shell3-1.2 {
           75  +  catchcmd "foo.db" ".tables"
           76  +} {0 t1}
           77  +do_test shell3-1.3 {
           78  +  catchcmd "foo.db \"DROP TABLE t1;\""
           79  +} {0 {}}
           80  +do_test shell3-1.4 {
           81  +  catchcmd "foo.db" ".tables"
           82  +} {0 {}}
           83  +do_test shell3-1.5 {
           84  +  catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\""
           85  +} {0 {}}
           86  +do_test shell3-1.6 {
           87  +  catchcmd "foo.db" ".tables"
           88  +} {0 {}}
           89  +do_test shell3-1.7 {
           90  +  catchcmd "foo.db \"CREATE TABLE\""
           91  +} {1 {Error: near "TABLE": syntax error}}
           92  +
           93  +#----------------------------------------------------------------------------
           94  +#   shell3-2.*: Basic tests for running SQL file from command line.
           95  +#
           96  +
           97  +# Run SQL file from command line
           98  +do_test shell3-2.1 {
           99  +  file delete -force foo.db
          100  +  set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
          101  +  set fexist [file exist foo.db]
          102  +  list $rc $fexist
          103  +} {{0 {}} 1}
          104  +do_test shell3-2.2 {
          105  +  catchcmd "foo.db" ".tables"
          106  +} {0 t1}
          107  +do_test shell3-2.3 {
          108  +  catchcmd "foo.db" "DROP TABLE t1;"
          109  +} {0 {}}
          110  +do_test shell3-2.4 {
          111  +  catchcmd "foo.db" ".tables"
          112  +} {0 {}}
          113  +do_test shell3-2.5 {
          114  +  catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;"
          115  +} {0 {}}
          116  +do_test shell3-2.6 {
          117  +  catchcmd "foo.db" ".tables"
          118  +} {0 {}}
          119  +do_test shell3-2.7 {
          120  +  catchcmd "foo.db" "CREATE TABLE"
          121  +} {1 {Error: incomplete SQL: CREATE TABLE}}
          122  +
          123  +