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 29if {[info exists env(MSYSCON)] && $env(MSYSCON)=="sh.exe"} { 30 puts "shell3 tests do not work with the mingw shell due to dodgy\ 31 command-line parsing" 32 finish_test 33 return 34} 35 36#---------------------------------------------------------------------------- 37# shell3-1.*: Basic tests for running SQL statments from command line. 38# 39 40# Run SQL statement from command line 41do_test shell3-1.1 { 42 forcedelete foo.db 43 set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ] 44 set fexist [file exist foo.db] 45 list $rc $fexist 46} {{0 {}} 1} 47do_test shell3-1.2 { 48 catchcmd "foo.db" ".tables" 49} {0 t1} 50do_test shell3-1.3 { 51 catchcmd "foo.db \"DROP TABLE t1;\"" 52} {0 {}} 53do_test shell3-1.4 { 54 catchcmd "foo.db" ".tables" 55} {0 {}} 56do_test shell3-1.5 { 57 catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\"" 58} {0 {}} 59do_test shell3-1.6 { 60 catchcmd "foo.db" ".tables" 61} {0 {}} 62do_test shell3-1.7 { 63 catchcmd "foo.db \"CREATE TABLE\"" 64} {1 {Error: near "TABLE": syntax error}} 65 66#---------------------------------------------------------------------------- 67# shell3-2.*: Basic tests for running SQL file from command line. 68# 69 70# Run SQL file from command line 71do_test shell3-2.1 { 72 forcedelete foo.db 73 set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ] 74 set fexist [file exist foo.db] 75 list $rc $fexist 76} {{0 {}} 1} 77do_test shell3-2.2 { 78 catchcmd "foo.db" ".tables" 79} {0 t1} 80do_test shell3-2.3 { 81 catchcmd "foo.db" "DROP TABLE t1;" 82} {0 {}} 83do_test shell3-2.4 { 84 catchcmd "foo.db" ".tables" 85} {0 {}} 86do_test shell3-2.5 { 87 catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;" 88} {0 {}} 89do_test shell3-2.6 { 90 catchcmd "foo.db" ".tables" 91} {0 {}} 92do_test shell3-2.7 { 93 catchcmd "foo.db" "CREATE TABLE" 94} {1 {Error: incomplete SQL: CREATE TABLE}} 95 96finish_test 97