OLD | NEW |
1 # 2009 Dec 16 | 1 # 2009 Dec 16 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # | 11 # |
12 # The focus of this file is testing the CLI shell tool. | 12 # The focus of this file is testing the CLI shell tool. |
13 # | 13 # |
14 # $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $ | 14 # $Id: shell2.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $ |
15 # | 15 # |
16 | 16 |
17 # Test plan: | 17 # Test plan: |
18 # | 18 # |
19 # shell3-1.*: Basic tests for running SQL statments from command line. | 19 # shell3-1.*: Basic tests for running SQL statments from command line. |
20 # shell3-2.*: Basic tests for running SQL file from command line. | 20 # shell3-2.*: Basic tests for running SQL file from command line. |
21 # | 21 # |
22 | 22 set testdir [file dirname $argv0] |
23 package require sqlite3 | 23 source $testdir/tester.tcl |
24 | 24 if {$tcl_platform(platform)=="windows"} { |
25 set CLI "./sqlite3" | 25 set CLI "sqlite3.exe" |
26 | 26 } else { |
27 proc do_test {name cmd expected} { | 27 set CLI "./sqlite3" |
28 puts -nonewline "$name ..." | |
29 set res [uplevel $cmd] | |
30 if {$res eq $expected} { | |
31 puts Ok | |
32 } else { | |
33 puts Error | |
34 puts " Got: $res" | |
35 puts " Expected: $expected" | |
36 exit | |
37 } | |
38 } | 28 } |
39 | 29 if {![file executable $CLI]} { |
40 proc execsql {sql} { | 30 finish_test |
41 uplevel [list db eval $sql] | 31 return |
42 } | 32 } |
43 | 33 db close |
44 proc catchsql {sql} { | 34 forcedelete test.db test.db-journal test.db-wal |
45 set rc [catch {uplevel [list db eval $sql]} msg] | |
46 list $rc $msg | |
47 } | |
48 | |
49 proc catchcmd {db {cmd ""}} { | |
50 global CLI | |
51 set out [open cmds.txt w] | |
52 puts $out $cmd | |
53 close $out | |
54 set line "exec $CLI $db < cmds.txt" | |
55 set rc [catch { eval $line } msg] | |
56 list $rc $msg | |
57 } | |
58 | |
59 file delete -force test.db test.db.journal | |
60 sqlite3 db test.db | 35 sqlite3 db test.db |
61 | 36 |
62 | |
63 #---------------------------------------------------------------------------- | 37 #---------------------------------------------------------------------------- |
64 # shell3-1.*: Basic tests for running SQL statments from command line. | 38 # shell3-1.*: Basic tests for running SQL statments from command line. |
65 # | 39 # |
66 | 40 |
67 # Run SQL statement from command line | 41 # Run SQL statement from command line |
68 do_test shell3-1.1 { | 42 do_test shell3-1.1 { |
69 file delete -force foo.db | 43 forcedelete foo.db |
70 set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ] | 44 set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ] |
71 set fexist [file exist foo.db] | 45 set fexist [file exist foo.db] |
72 list $rc $fexist | 46 list $rc $fexist |
73 } {{0 {}} 1} | 47 } {{0 {}} 1} |
74 do_test shell3-1.2 { | 48 do_test shell3-1.2 { |
75 catchcmd "foo.db" ".tables" | 49 catchcmd "foo.db" ".tables" |
76 } {0 t1} | 50 } {0 t1} |
77 do_test shell3-1.3 { | 51 do_test shell3-1.3 { |
78 catchcmd "foo.db \"DROP TABLE t1;\"" | 52 catchcmd "foo.db \"DROP TABLE t1;\"" |
79 } {0 {}} | 53 } {0 {}} |
80 do_test shell3-1.4 { | 54 do_test shell3-1.4 { |
81 catchcmd "foo.db" ".tables" | 55 catchcmd "foo.db" ".tables" |
82 } {0 {}} | 56 } {0 {}} |
83 do_test shell3-1.5 { | 57 do_test shell3-1.5 { |
84 catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\"" | 58 catchcmd "foo.db \"CREATE TABLE t1(a); DROP TABLE t1;\"" |
85 } {0 {}} | 59 } {0 {}} |
86 do_test shell3-1.6 { | 60 do_test shell3-1.6 { |
87 catchcmd "foo.db" ".tables" | 61 catchcmd "foo.db" ".tables" |
88 } {0 {}} | 62 } {0 {}} |
89 do_test shell3-1.7 { | 63 do_test shell3-1.7 { |
90 catchcmd "foo.db \"CREATE TABLE\"" | 64 catchcmd "foo.db \"CREATE TABLE\"" |
91 } {1 {Error: near "TABLE": syntax error}} | 65 } {1 {Error: near "TABLE": syntax error}} |
92 | 66 |
93 #---------------------------------------------------------------------------- | 67 #---------------------------------------------------------------------------- |
94 # shell3-2.*: Basic tests for running SQL file from command line. | 68 # shell3-2.*: Basic tests for running SQL file from command line. |
95 # | 69 # |
96 | 70 |
97 # Run SQL file from command line | 71 # Run SQL file from command line |
98 do_test shell3-2.1 { | 72 do_test shell3-2.1 { |
99 file delete -force foo.db | 73 forcedelete foo.db |
100 set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ] | 74 set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ] |
101 set fexist [file exist foo.db] | 75 set fexist [file exist foo.db] |
102 list $rc $fexist | 76 list $rc $fexist |
103 } {{0 {}} 1} | 77 } {{0 {}} 1} |
104 do_test shell3-2.2 { | 78 do_test shell3-2.2 { |
105 catchcmd "foo.db" ".tables" | 79 catchcmd "foo.db" ".tables" |
106 } {0 t1} | 80 } {0 t1} |
107 do_test shell3-2.3 { | 81 do_test shell3-2.3 { |
108 catchcmd "foo.db" "DROP TABLE t1;" | 82 catchcmd "foo.db" "DROP TABLE t1;" |
109 } {0 {}} | 83 } {0 {}} |
110 do_test shell3-2.4 { | 84 do_test shell3-2.4 { |
111 catchcmd "foo.db" ".tables" | 85 catchcmd "foo.db" ".tables" |
112 } {0 {}} | 86 } {0 {}} |
113 do_test shell3-2.5 { | 87 do_test shell3-2.5 { |
114 catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;" | 88 catchcmd "foo.db" "CREATE TABLE t1(a); DROP TABLE t1;" |
115 } {0 {}} | 89 } {0 {}} |
116 do_test shell3-2.6 { | 90 do_test shell3-2.6 { |
117 catchcmd "foo.db" ".tables" | 91 catchcmd "foo.db" ".tables" |
118 } {0 {}} | 92 } {0 {}} |
119 do_test shell3-2.7 { | 93 do_test shell3-2.7 { |
120 catchcmd "foo.db" "CREATE TABLE" | 94 catchcmd "foo.db" "CREATE TABLE" |
121 } {1 {Error: incomplete SQL: CREATE TABLE}} | 95 } {1 {Error: incomplete SQL: CREATE TABLE}} |
122 | 96 |
123 | 97 finish_test |
124 puts "CLI tests completed successfully" | |
OLD | NEW |