shaneh | ac81cd7 | 2009-11-10 17:07:30 +0000 | [diff] [blame] | 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: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $ |
| 15 | # |
| 16 | |
| 17 | # Test plan: |
| 18 | # |
| 19 | # shell2-1.*: Misc. test of various tickets and reported errors. |
| 20 | # |
| 21 | |
| 22 | package require sqlite3 |
| 23 | |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 24 | set CLI "./sqlite" |
| 25 | |
shaneh | ac81cd7 | 2009-11-10 17:07:30 +0000 | [diff] [blame] | 26 | proc do_test {name cmd expected} { |
| 27 | puts -nonewline "$name ..." |
| 28 | set res [uplevel $cmd] |
| 29 | if {$res eq $expected} { |
| 30 | puts Ok |
| 31 | } else { |
| 32 | puts Error |
| 33 | puts " Got: $res" |
| 34 | puts " Expected: $expected" |
| 35 | exit |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | proc execsql {sql} { |
| 40 | uplevel [list db eval $sql] |
| 41 | } |
| 42 | |
| 43 | proc catchsql {sql} { |
| 44 | set rc [catch {uplevel [list db eval $sql]} msg] |
| 45 | list $rc $msg |
| 46 | } |
| 47 | |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 48 | proc catchcmd {db cmd} { |
| 49 | global CLI |
shaneh | ac81cd7 | 2009-11-10 17:07:30 +0000 | [diff] [blame] | 50 | set out [open cmds.txt w] |
| 51 | puts $out $cmd |
| 52 | close $out |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 53 | set line "exec $CLI $db < cmds.txt" |
| 54 | set rc [catch { eval $line } msg] |
shaneh | ac81cd7 | 2009-11-10 17:07:30 +0000 | [diff] [blame] | 55 | list $rc $msg |
| 56 | } |
| 57 | |
| 58 | file delete -force test.db test.db.journal |
| 59 | sqlite3 db test.db |
| 60 | |
| 61 | |
| 62 | #---------------------------------------------------------------------------- |
| 63 | # shell2-1.*: Misc. test of various tickets and reported errors. |
| 64 | # |
| 65 | |
| 66 | # Batch mode not creating databases. |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 67 | # Reported on mailing list by Ken Zalewski. |
shaneh | ac81cd7 | 2009-11-10 17:07:30 +0000 | [diff] [blame] | 68 | # Ticket [aeff892c57]. |
| 69 | do_test shell2-1.1.1 { |
| 70 | file delete -force foo.db |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 71 | set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ] |
shaneh | ac81cd7 | 2009-11-10 17:07:30 +0000 | [diff] [blame] | 72 | set fexist [file exist foo.db] |
| 73 | list $rc $fexist |
| 74 | } {{0 {}} 1} |
| 75 | |
shaneh | 5fc2501 | 2009-11-11 04:17:07 +0000 | [diff] [blame] | 76 | # Shell silently ignores extra parameters. |
| 77 | # Ticket [f5cb008a65]. |
| 78 | do_test shell2-1.2.1 { |
| 79 | set rc [catch { eval exec $CLI \":memory:\" \"select 3\" \"select 4\" } msg] |
| 80 | list $rc \ |
| 81 | [regexp {Error: too many options: "select 4"} $msg] |
| 82 | } {1 1} |
| 83 | |
| 84 |
|
| 85 | |