3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # The focus of this file is testing the CLI shell tool.
14 # $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
19 # shell3-1.*: Basic tests for running SQL statments from command line.
20 # shell3-2.*: Basic tests for running SQL file from command line.
23 package require sqlite3
27 proc do_test {name cmd expected} {
28 puts -nonewline "$name ..."
29 set res [uplevel $cmd]
30 if {$res eq $expected} {
35 puts " Expected: $expected"
41 uplevel [list db eval $sql]
45 set rc [catch {uplevel [list db eval $sql]} msg]
49 proc catchcmd {db {cmd ""}} {
51 set out [open cmds.txt w]
54 set line "exec $CLI $db < cmds.txt"
55 set rc [catch { eval $line } msg]
59 file delete -force test.db test.db.journal
63 #----------------------------------------------------------------------------
64 # shell3-1.*: Basic tests for running SQL statments from command line.
67 # Run SQL statement from command line
69 file delete -force foo.db
70 set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
71 set fexist [file exist foo.db]
75 catchcmd "foo.db" ".tables"
78 catchcmd "foo.db \"DROP TABLE t1;\""
81 catchcmd "foo.db" ".tables"
84 catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\""
87 catchcmd "foo.db" ".tables"
90 catchcmd "foo.db \"CREATE TABLE\""
91 } {1 {Error: near "TABLE": syntax error}}
93 #----------------------------------------------------------------------------
94 # shell3-2.*: Basic tests for running SQL file from command line.
97 # Run SQL file from command line
99 file delete -force foo.db
100 set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
101 set fexist [file exist foo.db]
105 catchcmd "foo.db" ".tables"
108 catchcmd "foo.db" "DROP TABLE t1;"
111 catchcmd "foo.db" ".tables"
114 catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;"
117 catchcmd "foo.db" ".tables"
120 catchcmd "foo.db" "CREATE TABLE"
121 } {1 {Error: incomplete SQL: CREATE TABLE}}
124 puts "CLI tests completed successfully"