Testrunner.tcl enhancements: (1) Attempt to build the SQLite tcl extension
[sqlite.git] / test / shell3.test
blobef3ea784ff7f4579f6f902ccda41ec8ea1d31d96
1 # 2009 Dec 16
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 #***********************************************************************
11 # TESTRUNNER: shell
13 # The focus of this file is testing the CLI shell tool.
15 # $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
18 # Test plan:
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.
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
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.
39 if {$::tcl_platform(platform)=="windows"} {
40   finish_test
41   return
44 #----------------------------------------------------------------------------
45 #   shell3-1.*: Basic tests for running SQL statments from command line.
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 {Error: in prepare, incomplete input}}
74 #----------------------------------------------------------------------------
75 #   shell3-2.*: Basic tests for running SQL file from command line.
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}}
105 #----------------------------------------------------------------------------
106 #   shell3-3.*: Basic tests for processing odd SQL constructs.
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 ('
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--.
133 a["b"]
136 .*/ x
137 'y}} 1}
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}}
148 finish_test