Debian Codegraph @

test/shell3.test

raw
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 # TESTRUNNER: shell
12 #
13 # The focus of this file is testing the CLI shell tool.
14 #
15 # $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
16 #
17
18 # Test plan:
19 #
20 # shell3-1.*: Basic tests for running SQL statments from command line.
21 # shell3-2.*: Basic tests for running SQL file from command line.
22 # shell3-3.*: Basic tests for processing odd SQL constructs.
23 #
24 set testdir [file dirname $argv0]
25 source $testdir/tester.tcl
26 set CLI [test_cli_invocation]
27 db close
28 forcedelete test.db test.db-journal test.db-wal
29 sqlite3 db test.db
30
31
32 # There are inconsistencies in command-line argument quoting on Windows.
33 # In particular, individual applications are responsible for command-line
34 # parsing in Windows, not the shell. Depending on whether the sqlite3.exe
35 # program is compiled with MinGW or MSVC, the command-line parsing is
36 # different. This causes problems for the tests below. To avoid
37 # issues, these tests are disabled for windows.
38 #
39 if {$::tcl_platform(platform) eq "windows"} {
40 finish_test
41 return
42 }
43
44 #----------------------------------------------------------------------------
45 # shell3-1.*: Basic tests for running SQL statments from command line.
46 #
47
48 # Run SQL statement from command line
49 do_test shell3-1.1 {
50 forcedelete foo.db
51 set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
52 set fexist [file exist foo.db]
53 list $rc $fexist
54 } {{0 {}} 1}
55 do_test shell3-1.2 {
56 catchcmd "foo.db" ".tables"
57 } {0 t1}
58 do_test shell3-1.3 {
59 catchcmd "foo.db \"DROP TABLE t1;\""
60 } {0 {}}
61 do_test shell3-1.4 {
62 catchcmd "foo.db" ".tables"
63 } {0 {}}
64 do_test shell3-1.5 {
65 catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\""
66 } {0 {}}
67 do_test shell3-1.6 {
68 catchcmd "foo.db" ".tables"
69 } {0 {}}
70 do_test shell3-1.7 {
71 catchcmd "foo.db \"CREATE TABLE\""
72 } {1 {Parse error in 2nd command line argument: incomplete input}}
73
74 #----------------------------------------------------------------------------
75 # shell3-2.*: Basic tests for running SQL file from command line.
76 #
77
78 # Run SQL file from command line
79 do_test shell3-2.1 {
80 forcedelete foo.db
81 set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
82 set fexist [file exist foo.db]
83 list $rc $fexist
84 } {{0 {}} 1}
85 do_test shell3-2.2 {
86 catchcmd "foo.db" ".tables"
87 } {0 t1}
88 do_test shell3-2.3 {
89 catchcmd "foo.db" "DROP TABLE t1;"
90 } {0 {}}
91 do_test shell3-2.4 {
92 catchcmd "foo.db" ".tables"
93 } {0 {}}
94 do_test shell3-2.5 {
95 catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;"
96 } {0 {}}
97 do_test shell3-2.6 {
98 catchcmd "foo.db" ".tables"
99 } {0 {}}
100 do_test shell3-2.7 {
101 catchcmd "foo.db" "CREATE TABLE"
102 } {1 {Parse error near line 1: incomplete input}}
103
104
105 #----------------------------------------------------------------------------
106 # shell3-3.*: Basic tests for processing odd SQL constructs.
107 #
108
109 # Run combinations of odd identifiers, comments, semicolon placement
110 do_test shell3-3.1 {
111 forcedelete foo.db
112 set rc [ catchcmd "foo.db" {CREATE TABLE t1("
113 a--.
114 " --x
115 ); CREATE TABLE t2("a[""b""]");
116 .header on
117 INSERT INTO t1 VALUES ('
118 x''y');
119 INSERT INTO t2 VALUES ('
120 /*.
121 .*/ x
122 ''y');
123 SELECT * from t1 limit 1;
124 SELECT * from t2 limit 1;
125 } ]
126 set fexist [file exist foo.db]
127 list $rc $fexist
128 } {{0 {
129 a--.
130
131
132 x'y
133 a["b"]
134
135 /*.
136 .*/ x
137 'y}} 1}
138
139 do_test shell3-3.2 {
140 catchcmd "" {
141 .open xyz.db
142 SELECT ;
143 }
144 } {1 {Parse error near line 3: near ";": syntax error
145 SELECT ;
146 ^--- error here}}
147
148 finish_test