summaryrefslogtreecommitdiff
path: root/tool/shell3.test
diff options
context:
space:
mode:
authorHans-Christoph Steiner <hans@eds.org>2012-03-30 20:42:12 -0400
committerHans-Christoph Steiner <hans@eds.org>2012-03-30 20:42:12 -0400
commit7bb481fda9ecb134804b49c2ce77ca28f7eea583 (patch)
tree31b520b9914d3e2453968abe375f2c102772c3dc /tool/shell3.test
Imported Upstream version 2.0.3
Diffstat (limited to 'tool/shell3.test')
-rw-r--r--tool/shell3.test124
1 files changed, 124 insertions, 0 deletions
diff --git a/tool/shell3.test b/tool/shell3.test
new file mode 100644
index 0000000..d37adff
--- /dev/null
+++ b/tool/shell3.test
@@ -0,0 +1,124 @@
+# 2009 Dec 16
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# The focus of this file is testing the CLI shell tool.
+#
+# $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
+#
+
+# Test plan:
+#
+# shell3-1.*: Basic tests for running SQL statments from command line.
+# shell3-2.*: Basic tests for running SQL file from command line.
+#
+
+package require sqlite3
+
+set CLI "./sqlite3"
+
+proc do_test {name cmd expected} {
+ puts -nonewline "$name ..."
+ set res [uplevel $cmd]
+ if {$res eq $expected} {
+ puts Ok
+ } else {
+ puts Error
+ puts " Got: $res"
+ puts " Expected: $expected"
+ exit
+ }
+}
+
+proc execsql {sql} {
+ uplevel [list db eval $sql]
+}
+
+proc catchsql {sql} {
+ set rc [catch {uplevel [list db eval $sql]} msg]
+ list $rc $msg
+}
+
+proc catchcmd {db {cmd ""}} {
+ global CLI
+ set out [open cmds.txt w]
+ puts $out $cmd
+ close $out
+ set line "exec $CLI $db < cmds.txt"
+ set rc [catch { eval $line } msg]
+ list $rc $msg
+}
+
+file delete -force test.db test.db.journal
+sqlite3 db test.db
+
+
+#----------------------------------------------------------------------------
+# shell3-1.*: Basic tests for running SQL statments from command line.
+#
+
+# Run SQL statement from command line
+do_test shell3-1.1 {
+ file delete -force foo.db
+ set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
+ set fexist [file exist foo.db]
+ list $rc $fexist
+} {{0 {}} 1}
+do_test shell3-1.2 {
+ catchcmd "foo.db" ".tables"
+} {0 t1}
+do_test shell3-1.3 {
+ catchcmd "foo.db \"DROP TABLE t1;\""
+} {0 {}}
+do_test shell3-1.4 {
+ catchcmd "foo.db" ".tables"
+} {0 {}}
+do_test shell3-1.5 {
+ catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\""
+} {0 {}}
+do_test shell3-1.6 {
+ catchcmd "foo.db" ".tables"
+} {0 {}}
+do_test shell3-1.7 {
+ catchcmd "foo.db \"CREATE TABLE\""
+} {1 {Error: near "TABLE": syntax error}}
+
+#----------------------------------------------------------------------------
+# shell3-2.*: Basic tests for running SQL file from command line.
+#
+
+# Run SQL file from command line
+do_test shell3-2.1 {
+ file delete -force foo.db
+ set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
+ set fexist [file exist foo.db]
+ list $rc $fexist
+} {{0 {}} 1}
+do_test shell3-2.2 {
+ catchcmd "foo.db" ".tables"
+} {0 t1}
+do_test shell3-2.3 {
+ catchcmd "foo.db" "DROP TABLE t1;"
+} {0 {}}
+do_test shell3-2.4 {
+ catchcmd "foo.db" ".tables"
+} {0 {}}
+do_test shell3-2.5 {
+ catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;"
+} {0 {}}
+do_test shell3-2.6 {
+ catchcmd "foo.db" ".tables"
+} {0 {}}
+do_test shell3-2.7 {
+ catchcmd "foo.db" "CREATE TABLE"
+} {1 {Error: incomplete SQL: CREATE TABLE}}
+
+
+puts "CLI tests completed successfully"