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 | |
| 24 | proc do_test {name cmd expected} { |
| 25 | puts -nonewline "$name ..." |
| 26 | set res [uplevel $cmd] |
| 27 | if {$res eq $expected} { |
| 28 | puts Ok |
| 29 | } else { |
| 30 | puts Error |
| 31 | puts " Got: $res" |
| 32 | puts " Expected: $expected" |
| 33 | exit |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | proc execsql {sql} { |
| 38 | uplevel [list db eval $sql] |
| 39 | } |
| 40 | |
| 41 | proc catchsql {sql} { |
| 42 | set rc [catch {uplevel [list db eval $sql]} msg] |
| 43 | list $rc $msg |
| 44 | } |
| 45 | |
| 46 | proc catchcmd {options db cmd} { |
| 47 | set out [open cmds.txt w] |
| 48 | puts $out $cmd |
| 49 | close $out |
| 50 | set rc [catch { exec ./sqlite $options $db < cmds.txt } msg] |
| 51 | list $rc $msg |
| 52 | } |
| 53 | |
| 54 | file delete -force test.db test.db.journal |
| 55 | sqlite3 db test.db |
| 56 | |
| 57 | |
| 58 | #---------------------------------------------------------------------------- |
| 59 | # shell2-1.*: Misc. test of various tickets and reported errors. |
| 60 | # |
| 61 | |
| 62 | # Batch mode not creating databases. |
| 63 | # Reported on mailing list by Ken Zalewski <kennyz@nycap.rr.com>. |
| 64 | # Ticket [aeff892c57]. |
| 65 | do_test shell2-1.1.1 { |
| 66 | file delete -force foo.db |
| 67 | set rc [ catchcmd "-batch" "foo.db" "CREATE TABLE t1(a);" ] |
| 68 | set fexist [file exist foo.db] |
| 69 | list $rc $fexist |
| 70 | } {{0 {}} 1} |
| 71 | |