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