xref: /sqlite-3.40.0/test/shell3.test (revision 9bccde3d)
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#
22set testdir [file dirname $argv0]
23source $testdir/tester.tcl
24set CLI [test_find_cli]
25db close
26forcedelete test.db test.db-journal test.db-wal
27sqlite3 db test.db
28
29#----------------------------------------------------------------------------
30#   shell3-1.*: Basic tests for running SQL statments from command line.
31#
32
33# Run SQL statement from command line
34do_test shell3-1.1 {
35  forcedelete foo.db
36  set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
37  set fexist [file exist foo.db]
38  list $rc $fexist
39} {{0 {}} 1}
40do_test shell3-1.2 {
41  catchcmd "foo.db" ".tables"
42} {0 t1}
43do_test shell3-1.3 {
44  catchcmd "foo.db \"DROP TABLE t1;\""
45} {0 {}}
46do_test shell3-1.4 {
47  catchcmd "foo.db" ".tables"
48} {0 {}}
49do_test shell3-1.5 {
50  catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\""
51} {0 {}}
52do_test shell3-1.6 {
53  catchcmd "foo.db" ".tables"
54} {0 {}}
55do_test shell3-1.7 {
56  catchcmd "foo.db \"CREATE TABLE\""
57} {1 {Error: near "TABLE": syntax error}}
58
59#----------------------------------------------------------------------------
60#   shell3-2.*: Basic tests for running SQL file from command line.
61#
62
63# Run SQL file from command line
64do_test shell3-2.1 {
65  forcedelete foo.db
66  set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
67  set fexist [file exist foo.db]
68  list $rc $fexist
69} {{0 {}} 1}
70do_test shell3-2.2 {
71  catchcmd "foo.db" ".tables"
72} {0 t1}
73do_test shell3-2.3 {
74  catchcmd "foo.db" "DROP TABLE t1;"
75} {0 {}}
76do_test shell3-2.4 {
77  catchcmd "foo.db" ".tables"
78} {0 {}}
79do_test shell3-2.5 {
80  catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;"
81} {0 {}}
82do_test shell3-2.6 {
83  catchcmd "foo.db" ".tables"
84} {0 {}}
85do_test shell3-2.7 {
86  catchcmd "foo.db" "CREATE TABLE"
87} {1 {Error: incomplete SQL: CREATE TABLE}}
88
89finish_test
90