blob: dae82ababb9beb649fc7193203d5ce5e24211963 [file] [log] [blame]
shanehac81cd72009-11-10 17:07:30 +00001# 2009 Nov 11
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# shell2-1.*: Misc. test of various tickets and reported errors.
20#
21
22package require sqlite3
23
shanehca7dfda2009-12-17 21:07:54 +000024set CLI "./sqlite3"
shaneh5fc25012009-11-11 04:17:07 +000025
shanehac81cd72009-11-10 17:07:30 +000026proc do_test {name cmd expected} {
27 puts -nonewline "$name ..."
28 set res [uplevel $cmd]
29 if {$res eq $expected} {
30 puts Ok
31 } else {
32 puts Error
33 puts " Got: $res"
34 puts " Expected: $expected"
35 exit
36 }
37}
38
39proc execsql {sql} {
40 uplevel [list db eval $sql]
41}
42
43proc catchsql {sql} {
44 set rc [catch {uplevel [list db eval $sql]} msg]
45 list $rc $msg
46}
47
shanehca7dfda2009-12-17 21:07:54 +000048proc catchcmd {db {cmd ""}} {
shaneh5fc25012009-11-11 04:17:07 +000049 global CLI
shanehac81cd72009-11-10 17:07:30 +000050 set out [open cmds.txt w]
51 puts $out $cmd
52 close $out
shaneh5fc25012009-11-11 04:17:07 +000053 set line "exec $CLI $db < cmds.txt"
54 set rc [catch { eval $line } msg]
shanehac81cd72009-11-10 17:07:30 +000055 list $rc $msg
56}
57
58file delete -force test.db test.db.journal
59sqlite3 db test.db
60
61
62#----------------------------------------------------------------------------
63# shell2-1.*: Misc. test of various tickets and reported errors.
64#
65
66# Batch mode not creating databases.
shaneh5fc25012009-11-11 04:17:07 +000067# Reported on mailing list by Ken Zalewski.
shanehac81cd72009-11-10 17:07:30 +000068# Ticket [aeff892c57].
69do_test shell2-1.1.1 {
70 file delete -force foo.db
shaneh5fc25012009-11-11 04:17:07 +000071 set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ]
shanehac81cd72009-11-10 17:07:30 +000072 set fexist [file exist foo.db]
73 list $rc $fexist
74} {{0 {}} 1}
75
shaneh5fc25012009-11-11 04:17:07 +000076# Shell silently ignores extra parameters.
77# Ticket [f5cb008a65].
78do_test shell2-1.2.1 {
79 set rc [catch { eval exec $CLI \":memory:\" \"select 3\" \"select 4\" } msg]
80 list $rc \
81 [regexp {Error: too many options: "select 4"} $msg]
82} {1 1}
83
shanehca7dfda2009-12-17 21:07:54 +000084
shaneh5fc25012009-11-11 04:17:07 +000085