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 # shell2-1.*: Misc. test of various tickets and reported errors.
22 package require sqlite3
26 proc do_test {name cmd expected} {
27 puts -nonewline "$name ..."
28 set res [uplevel $cmd]
29 if {$res eq $expected} {
34 puts " Expected: $expected"
40 uplevel [list db eval $sql]
44 set rc [catch {uplevel [list db eval $sql]} msg]
48 proc catchcmd {db {cmd ""}} {
50 set out [open cmds.txt w]
53 set line "exec $CLI $db < cmds.txt"
54 set rc [catch { eval $line } msg]
58 file delete -force test.db test.db.journal
62 #----------------------------------------------------------------------------
63 # shell2-1.*: Misc. test of various tickets and reported errors.
66 # Batch mode not creating databases.
67 # Reported on mailing list by Ken Zalewski.
68 # Ticket [aeff892c57].
69 do_test shell2-1.1.1 {
70 file delete -force foo.db
71 set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ]
72 set fexist [file exist foo.db]
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]
81 [regexp {Error: too many options: "select 4"} $msg]
84 # Test a problem reported on the mailing list. The shell was at one point
85 # returning the generic SQLITE_ERROR message ("SQL error or missing database")
86 # instead of the "too many levels..." message in the test below.
89 catchcmd "-batch test.db" {
90 PRAGMA recursive_triggers = ON;
91 CREATE TABLE t5(a PRIMARY KEY, b, c);
92 INSERT INTO t5 VALUES(1, 2, 3);
93 CREATE TRIGGER au_tble AFTER UPDATE ON t5 BEGIN
94 UPDATE OR IGNORE t5 SET a = new.a, c = 10;
97 UPDATE OR REPLACE t5 SET a = 4 WHERE a = 1;
99 } {1 {Error: near line 9: too many levels of trigger recursion}}
103 # Shell not echoing all commands with echo on.
104 # Ticket [eb620916be].
107 # NB. whitespace is important
108 do_test shell2-1.4.1 {
109 file delete -force foo.db
110 catchcmd "foo.db" {CREATE TABLE foo(a);
111 INSERT INTO foo(a) VALUES(1);
115 # Test with echo on using command line option
116 # NB. whitespace is important
117 do_test shell2-1.4.2 {
118 file delete -force foo.db
119 catchcmd "-echo foo.db" {CREATE TABLE foo(a);
120 INSERT INTO foo(a) VALUES(1);
122 } {0 {CREATE TABLE foo(a);
123 INSERT INTO foo(a) VALUES(1);
127 # Test with echo on using dot command
128 # NB. whitespace is important
129 do_test shell2-1.4.3 {
130 file delete -force foo.db
131 catchcmd "foo.db" {.echo ON
133 INSERT INTO foo(a) VALUES(1);
135 } {0 {CREATE TABLE foo(a);
136 INSERT INTO foo(a) VALUES(1);
140 # Test with echo on using dot command and
141 # turning off mid- processing.
142 # NB. whitespace is important
143 do_test shell2-1.4.4 {
144 file delete -force foo.db
145 catchcmd "foo.db" {.echo ON
148 INSERT INTO foo(a) VALUES(1);
150 } {0 {CREATE TABLE foo(a);
154 # Test with echo on using dot command and
155 # multiple commands per line.
156 # NB. whitespace is important
157 do_test shell2-1.4.5 {
158 file delete -force foo.db
159 catchcmd "foo.db" {.echo ON
160 CREATE TABLE foo1(a);
161 INSERT INTO foo1(a) VALUES(1);
162 CREATE TABLE foo2(b);
163 INSERT INTO foo2(b) VALUES(1);
164 SELECT * FROM foo1; SELECT * FROM foo2;
165 INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
166 SELECT * FROM foo1; SELECT * FROM foo2;
168 } {0 {CREATE TABLE foo1(a);
169 INSERT INTO foo1(a) VALUES(1);
170 CREATE TABLE foo2(b);
171 INSERT INTO foo2(b) VALUES(1);
176 INSERT INTO foo1(a) VALUES(2);
177 INSERT INTO foo2(b) VALUES(2);
185 # Test with echo on and headers on using dot command and
186 # multiple commands per line.
187 # NB. whitespace is important
188 do_test shell2-1.4.6 {
189 file delete -force foo.db
190 catchcmd "foo.db" {.echo ON
192 CREATE TABLE foo1(a);
193 INSERT INTO foo1(a) VALUES(1);
194 CREATE TABLE foo2(b);
195 INSERT INTO foo2(b) VALUES(1);
196 SELECT * FROM foo1; SELECT * FROM foo2;
197 INSERT INTO foo1(a) VALUES(2); INSERT INTO foo2(b) VALUES(2);
198 SELECT * FROM foo1; SELECT * FROM foo2;
201 CREATE TABLE foo1(a);
202 INSERT INTO foo1(a) VALUES(1);
203 CREATE TABLE foo2(b);
204 INSERT INTO foo2(b) VALUES(1);
211 INSERT INTO foo1(a) VALUES(2);
212 INSERT INTO foo2(b) VALUES(2);
222 puts "CLI tests completed successfully"