shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 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 | # |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 22 | set testdir [file dirname $argv0] |
| 23 | source $testdir/tester.tcl |
dan | 089555c | 2016-03-15 09:55:44 +0000 | [diff] [blame] | 24 | set CLI [test_find_cli] |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 25 | db close |
| 26 | forcedelete test.db test.db-journal test.db-wal |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 27 | sqlite3 db test.db |
| 28 | |
drh | 60c4249 | 2016-03-26 15:36:36 +0000 | [diff] [blame] | 29 | # There are inconsistencies in command-line argument quoting on Windows. |
| 30 | # In particular, individual applications are responsible for command-line |
| 31 | # parsing in Windows, not the shell. Depending on whether the sqlite3.exe |
| 32 | # program is compiled with MinGW or MSVC, the command-line parsing is |
| 33 | # different. This causes problems for the tests below. To avoid |
| 34 | # issues, these tests are disabled for windows. |
| 35 | # |
| 36 | if {$::tcl_platform(platform)=="windows"} { |
drh | 4f69540 | 2016-03-25 20:10:20 +0000 | [diff] [blame] | 37 | finish_test |
| 38 | return |
| 39 | } |
| 40 | |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 41 | #---------------------------------------------------------------------------- |
| 42 | # shell3-1.*: Basic tests for running SQL statments from command line. |
| 43 | # |
| 44 | |
| 45 | # Run SQL statement from command line |
| 46 | do_test shell3-1.1 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 47 | forcedelete foo.db |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 48 | set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ] |
| 49 | set fexist [file exist foo.db] |
| 50 | list $rc $fexist |
| 51 | } {{0 {}} 1} |
| 52 | do_test shell3-1.2 { |
| 53 | catchcmd "foo.db" ".tables" |
| 54 | } {0 t1} |
| 55 | do_test shell3-1.3 { |
| 56 | catchcmd "foo.db \"DROP TABLE t1;\"" |
| 57 | } {0 {}} |
| 58 | do_test shell3-1.4 { |
| 59 | catchcmd "foo.db" ".tables" |
| 60 | } {0 {}} |
| 61 | do_test shell3-1.5 { |
| 62 | catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\"" |
| 63 | } {0 {}} |
| 64 | do_test shell3-1.6 { |
| 65 | catchcmd "foo.db" ".tables" |
| 66 | } {0 {}} |
| 67 | do_test shell3-1.7 { |
| 68 | catchcmd "foo.db \"CREATE TABLE\"" |
drh | 6116ee4 | 2018-01-10 00:40:06 +0000 | [diff] [blame^] | 69 | } {1 {Error: incomplete input}} |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 70 | |
| 71 | #---------------------------------------------------------------------------- |
| 72 | # shell3-2.*: Basic tests for running SQL file from command line. |
| 73 | # |
| 74 | |
| 75 | # Run SQL file from command line |
| 76 | do_test shell3-2.1 { |
mistachkin | 9ac9931 | 2013-09-13 23:26:47 +0000 | [diff] [blame] | 77 | forcedelete foo.db |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 78 | set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ] |
| 79 | set fexist [file exist foo.db] |
| 80 | list $rc $fexist |
| 81 | } {{0 {}} 1} |
| 82 | do_test shell3-2.2 { |
| 83 | catchcmd "foo.db" ".tables" |
| 84 | } {0 t1} |
| 85 | do_test shell3-2.3 { |
| 86 | catchcmd "foo.db" "DROP TABLE t1;" |
| 87 | } {0 {}} |
| 88 | do_test shell3-2.4 { |
| 89 | catchcmd "foo.db" ".tables" |
| 90 | } {0 {}} |
| 91 | do_test shell3-2.5 { |
| 92 | catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;" |
| 93 | } {0 {}} |
| 94 | do_test shell3-2.6 { |
| 95 | catchcmd "foo.db" ".tables" |
| 96 | } {0 {}} |
| 97 | do_test shell3-2.7 { |
| 98 | catchcmd "foo.db" "CREATE TABLE" |
drh | 6116ee4 | 2018-01-10 00:40:06 +0000 | [diff] [blame^] | 99 | } {1 {Error: near line 1: incomplete input}} |
shaneh | ca7dfda | 2009-12-17 21:07:54 +0000 | [diff] [blame] | 100 | |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 101 | finish_test |