]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add some very basic tests for the commands available from the CLI.
authorshaneh <shaneh@noemail.net>
Fri, 6 Nov 2009 03:22:54 +0000 (03:22 +0000)
committershaneh <shaneh@noemail.net>
Fri, 6 Nov 2009 03:22:54 +0000 (03:22 +0000)
FossilOrigin-Name: 6bf43338049f956b447139c90df472682e28222a

manifest
manifest.uuid
tool/shell1.test [new file with mode: 0644]

index eb2afb9b7773cc841e748578e39f1d9a0aa6baf0..cf04987808878d770d2cc4420dcaeeb3b2ff986f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,5 @@
------BEGIN PGP SIGNED MESSAGE-----
-Hash: SHA1
-
-C Remove\s"const"\sfrom\sparameter\sof\ssqlite3BtreeFactory()\sto\savoid\sa\scompiler\nwarning.
-D 2009-11-04T13:30:02
+C Add\ssome\svery\sbasic\stests\sfor\sthe\scommands\savailable\sfrom\sthe\sCLI.
+D 2009-11-06T03:22:55
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in a77dfde96ad86aafd3f71651a4333a104debe86a
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -753,6 +750,7 @@ F tool/mksqlite3h.tcl eb100dce83f24b501b325b340f8b5eb8e5106b3b
 F tool/mksqlite3internalh.tcl 7b43894e21bcb1bb39e11547ce7e38a063357e87
 F tool/omittest.tcl 27d6f6e3b1e95aeb26a1c140e6eb57771c6d794a
 F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
+F tool/shell1.test 404512b1c3f839e97e42666120346d267b5c5b47
 F tool/showdb.c 8ab8b3b53884312aafb7ef60982e255a6c31d238
 F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
 F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe
@@ -764,14 +762,10 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 24a4d520d540d92b611abc4eb57dc6da9be4eac6
-R a2178242a921307d19fbc8b7d2eec4f0
-U drh
-Z a8d4aa9309aed4b69860cd88128a4708
------BEGIN PGP SIGNATURE-----
-Version: GnuPG v1.4.6 (GNU/Linux)
-
-iD8DBQFK8YHdoxKgR168RlERAs0DAJ447A8mNmnCD0zy/gACLgqIHsmF8QCfYMHu
-do95dSeuDXCMLnSZQtGGeQE=
-=FnZg
------END PGP SIGNATURE-----
+P eb7a544fe49d1626bacecfe53ddc03fe082e3243
+R fae9bb1bfda84b08471983345efa3e3e
+T *branch * trunk
+T *sym-trunk *
+T -sym-release *
+U shaneh
+Z 22d0b71b08c4b8d13c9518094d3a312f
index d60694a03f97fed58b7ed40ac589eb8af45e6603..2dd58347fb9652603649b8b9b44d961dcaea4cfb 100644 (file)
@@ -1 +1 @@
-eb7a544fe49d1626bacecfe53ddc03fe082e3243
\ No newline at end of file
+6bf43338049f956b447139c90df472682e28222a
\ No newline at end of file
diff --git a/tool/shell1.test b/tool/shell1.test
new file mode 100644 (file)
index 0000000..1a3b532
--- /dev/null
@@ -0,0 +1,357 @@
+# 2009 Nov 11
+#
+# 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: shell1.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
+#
+
+# Test plan:
+#
+#   shell-1.*: Basic test that command can be called.
+#
+
+package require 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"
+  }
+}
+
+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 {cmd} {
+  set out [open cmds.txt w]
+  puts $out $cmd
+  close $out
+  set rc [catch { exec ./sqlite3 test.db < cmds.txt } msg]
+  list $rc $msg
+}
+
+file delete -force test.db test.db.journal
+sqlite3 db test.db
+
+#----------------------------------------------------------------------------
+# Test cases shell-1.* Basic test that command can be called.
+#
+
+# .backup ?DB? FILE      Backup DB (default "main") to FILE
+do_test shell-1.1.1 {
+} {}
+
+# .bail ON|OFF           Stop after hitting an error.  Default OFF
+do_test shell-1.2.1 {
+  catchcmd ".bail"
+} {1 {Error: unknown command or invalid arguments:  "bail". Enter ".help" for help}}
+do_test shell-1.2.2 {
+  catchcmd ".bail ON"
+} {0 {}}
+do_test shell-1.2.3 {
+  catchcmd ".bail OFF"
+} {0 {}}
+
+# .databases             List names and files of attached databases
+do_test shell-1.3.1 {
+  set res [catchcmd ".databases"]
+  regexp {0.*main.*test\.db} $res
+} {1}
+
+# .dump ?TABLE? ...      Dump the database in an SQL text format
+#                          If TABLE specified, only dump tables matching
+#                          LIKE pattern TABLE.
+do_test shell-1.4.1 {
+  set res [catchcmd ".dump"]
+  list [regexp {BEGIN TRANSACTION;} $res] \
+       [regexp {COMMIT;} $res]
+} {1 1}
+do_test shell-1.4.2 {
+  set res [catchcmd ".dump FOO"]
+  list [regexp {BEGIN TRANSACTION;} $res] \
+       [regexp {COMMIT;} $res]
+} {1 1}
+
+# .echo ON|OFF           Turn command echo on or off
+do_test shell-1.5.1 {
+  catchcmd ".echo"
+} {1 {Error: unknown command or invalid arguments:  "echo". Enter ".help" for help}}
+do_test shell-1.5.2 {
+  catchcmd ".echo ON"
+} {0 {}}
+do_test shell-1.5.3 {
+  catchcmd ".echo OFF"
+} {0 {}}
+
+# .exit                  Exit this program
+do_test shell-1.6.1 {
+  catchcmd ".exit"
+} {0 {}}
+
+# .explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.
+do_test shell-1.7.1 {
+  catchcmd ".echo"
+} {1 {Error: unknown command or invalid arguments:  "echo". Enter ".help" for help}}
+do_test shell-1.7.2 {
+  catchcmd ".explain ON"
+} {0 {}}
+do_test shell-1.7.3 {
+  catchcmd ".explain OFF"
+} {0 {}}
+
+# .genfkey ?OPTIONS?     Options are:
+#                          --no-drop: Do not drop old fkey triggers.
+#                          --ignore-errors: Ignore tables with fkey errors
+#                          --exec: Execute generated SQL immediately
+#                        See file tool/genfkey.README in the source
+#                        distribution for further information.
+do_test shell-1.8.1 {
+} {}
+
+# .header(s) ON|OFF      Turn display of headers on or off
+do_test shell-1.9.1 {
+  catchcmd ".header"
+} {1 {Error: unknown command or invalid arguments:  "header". Enter ".help" for help}}
+do_test shell-1.9.2 {
+  catchcmd ".header ON"
+} {0 {}}
+do_test shell-1.9.3 {
+  catchcmd ".header OFF"
+} {0 {}}
+do_test shell-1.9.4 {
+  catchcmd ".headers"
+} {1 {Error: unknown command or invalid arguments:  "headers". Enter ".help" for help}}
+do_test shell-1.9.5 {
+  catchcmd ".headers ON"
+} {0 {}}
+do_test shell-1.9.6 {
+  catchcmd ".headers OFF"
+} {0 {}}
+
+# .help                  Show this message
+do_test shell-1.10.1 {
+  set res [catchcmd ".help"]
+  # look for a few of the possible help commands
+  list [regexp {.help} $res] \
+       [regexp {.quit} $res] \
+       [regexp {.show} $res]
+} {1 1 1}
+
+# .import FILE TABLE     Import data from FILE into TABLE
+do_test shell-1.11.1 {
+  catchcmd ".import"
+} {1 {Error: unknown command or invalid arguments:  "import". Enter ".help" for help}}
+do_test shell-1.11.2 {
+  catchcmd ".import FOO"
+} {1 {Error: unknown command or invalid arguments:  "import". Enter ".help" for help}}
+do_test shell-1.11.2 {
+  catchcmd ".import FOO BAR"
+} {1 {Error: no such table: BAR}}
+
+# .indices ?TABLE?       Show names of all indices
+#                          If TABLE specified, only show indices for tables
+#                          matching LIKE pattern TABLE.
+do_test shell-1.12.1 {
+  catchcmd ".indices"
+} {0 {}}
+do_test shell-1.12.2 {
+  catchcmd ".indices FOO"
+} {0 {}}
+
+# .mode MODE ?TABLE?     Set output mode where MODE is one of:
+#                          csv      Comma-separated values
+#                          column   Left-aligned columns.  (See .width)
+#                          html     HTML <table> code
+#                          insert   SQL insert statements for TABLE
+#                          line     One value per line
+#                          list     Values delimited by .separator string
+#                          tabs     Tab-separated values
+#                          tcl      TCL list elements
+do_test shell-1.13.1 {
+  catchcmd ".mode"
+} {1 {Error: unknown command or invalid arguments:  "mode". Enter ".help" for help}}
+do_test shell-1.13.2 {
+  catchcmd ".mode FOO"
+} {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
+do_test shell-1.13.3 {
+  catchcmd ".mode csv"
+} {0 {}}
+do_test shell-1.13.4 {
+  catchcmd ".mode column"
+} {0 {}}
+do_test shell-1.13.5 {
+  catchcmd ".mode html"
+} {0 {}}
+do_test shell-1.13.6 {
+  catchcmd ".mode insert"
+} {0 {}}
+do_test shell-1.13.7 {
+  catchcmd ".mode line"
+} {0 {}}
+do_test shell-1.13.8 {
+  catchcmd ".mode list"
+} {0 {}}
+do_test shell-1.13.9 {
+  catchcmd ".mode tabs"
+} {0 {}}
+do_test shell-1.13.10 {
+  catchcmd ".mode tcl"
+} {0 {}}
+
+# .nullvalue STRING      Print STRING in place of NULL values
+do_test shell-1.14.1 {
+  catchcmd ".nullvalue"
+} {1 {Error: unknown command or invalid arguments:  "nullvalue". Enter ".help" for help}}
+do_test shell-1.14.2 {
+  catchcmd ".nullvalue FOO"
+} {0 {}}
+
+# .output FILENAME       Send output to FILENAME
+do_test shell-1.15.1 {
+  catchcmd ".output"
+} {1 {Error: unknown command or invalid arguments:  "output". Enter ".help" for help}}
+do_test shell-1.15.2 {
+  catchcmd ".output FOO"
+} {0 {}}
+
+# .output stdout         Send output to the screen
+do_test shell-1.16.1 {
+  catchcmd ".output stdout"
+} {0 {}}
+
+# .prompt MAIN CONTINUE  Replace the standard prompts
+do_test shell-1.17.1 {
+  catchcmd ".prompt"
+} {1 {Error: unknown command or invalid arguments:  "prompt". Enter ".help" for help}}
+do_test shell-1.17.2 {
+  catchcmd ".prompt FOO"
+} {0 {}}
+do_test shell-1.17.3 {
+  catchcmd ".prompt FOO BAR"
+} {0 {}}
+
+# .quit                  Exit this program
+do_test shell-1.18.1 {
+  catchcmd ".quit"
+} {0 {}}
+
+# .read FILENAME         Execute SQL in FILENAME
+do_test shell-1.19.1 {
+  catchcmd ".read"
+} {1 {Error: unknown command or invalid arguments:  "read". Enter ".help" for help}}
+do_test shell-1.19.2 {
+  file delete -force FOO
+  catchcmd ".read FOO"
+} {1 {Error: cannot open "FOO"}}
+
+# .restore ?DB? FILE     Restore content of DB (default "main") from FILE
+do_test shell-1.20.1 {
+  catchcmd ".restore"
+} {1 {Error: unknown command or invalid arguments:  "restore". Enter ".help" for help}}
+do_test shell-1.20.2 {
+  # catchcmd ".restore FOO"
+  #TBD!!! this asserts currently
+} {}
+
+# .schema ?TABLE?        Show the CREATE statements
+#                          If TABLE specified, only show tables matching
+#                          LIKE pattern TABLE.
+do_test shell-1.21.1 {
+  catchcmd ".schema"
+} {0 {}}
+do_test shell-1.21.2 {
+  catchcmd ".schema FOO"
+} {0 {}}
+
+# .separator STRING      Change separator used by output mode and .import
+do_test shell-1.22.1 {
+  catchcmd ".separator"
+} {1 {Error: unknown command or invalid arguments:  "separator". Enter ".help" for help}}
+do_test shell-1.22.2 {
+  catchcmd ".separator FOO"
+} {0 {}}
+
+# .show                  Show the current values for various settings
+do_test shell-1.23.1 {
+  set res [catchcmd ".show"]
+  list [regexp {echo:} $res] \
+       [regexp {explain:} $res] \
+       [regexp {headers:} $res] \
+       [regexp {mode:} $res] \
+       [regexp {nullvalue:} $res] \
+       [regexp {output:} $res] \
+       [regexp {separator:} $res] \
+       [regexp {width:} $res]
+} {1 1 1 1 1 1 1 1}
+
+# .tables ?TABLE?        List names of tables
+#                          If TABLE specified, only list tables matching
+#                          LIKE pattern TABLE.
+do_test shell-1.24.1 {
+  catchcmd ".tables"
+} {0 {}}
+do_test shell-1.24.2 {
+  catchcmd ".tables FOO"
+} {0 {}}
+
+# .timeout MS            Try opening locked tables for MS milliseconds
+do_test shell-1.25.1 {
+  catchcmd ".timeout"
+} {1 {Error: unknown command or invalid arguments:  "timeout". Enter ".help" for help}}
+do_test shell-1.25.2 {
+  catchcmd ".timeout zzz"
+  #TBD!!! this should probably produce an error
+} {0 {}}
+do_test shell-1.25.2 {
+  catchcmd ".timeout 1"
+} {0 {}}
+
+# .width NUM NUM ...     Set column widths for "column" mode
+do_test shell-1.26.1 {
+  catchcmd ".width"
+  #TBD!!! this should probably produce an error
+} {0 {}}
+do_test shell-1.26.2 {
+  catchcmd ".width xxx"
+  #TBD!!! this should probably produce an error
+} {0 {}}
+do_test shell-1.26.3 {
+  catchcmd ".width xxx yyy"
+  #TBD!!! this should probably produce an error
+} {0 {}}
+do_test shell-1.26.4 {
+  catchcmd ".width 1 1"
+} {0 {}}
+
+# .timer ON|OFF          Turn the CPU timer measurement on or off
+do_test shell-1.27.1 {
+  catchcmd ".timer"
+} {1 {Error: unknown command or invalid arguments:  "timer". Enter ".help" for help}}
+do_test shell-1.27.2 {
+  catchcmd ".timer ON"
+} {0 {}}
+do_test shell-1.27.3 {
+  catchcmd ".timer OFF"
+} {0 {}}
+
+#