| OLD | NEW |
| 1 # 2010 July 28 | 1 # 2010 July 28 |
| 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 # These tests are specific to the .stats command. | 13 # These tests are specific to the .stats command. |
| 14 # | 14 # |
| 15 # 2015-03-19: Added tests for .trace | 15 # 2015-03-19: Added tests for .trace |
| 16 | 16 |
| 17 # Test plan: | 17 # Test plan: |
| 18 # | 18 # |
| 19 # shell4-1.*: Basic tests specific to the "stats" command. | 19 # shell4-1.*: Basic tests specific to the "stats" command. |
| 20 # shell4-2.*: Basic tests for ".trace" | 20 # shell4-2.*: Basic tests for ".trace" |
| 21 # shell4-3.*: The ".read" command takes the shell out of interactive mode |
| 21 # | 22 # |
| 22 set testdir [file dirname $argv0] | 23 set testdir [file dirname $argv0] |
| 23 source $testdir/tester.tcl | 24 source $testdir/tester.tcl |
| 24 if {$tcl_platform(platform)=="windows"} { | 25 set CLI [test_find_cli] |
| 25 set CLI "sqlite3.exe" | |
| 26 } else { | |
| 27 set CLI "./sqlite3" | |
| 28 } | |
| 29 if {![file executable $CLI]} { | |
| 30 finish_test | |
| 31 return | |
| 32 } | |
| 33 db close | 26 db close |
| 34 forcedelete test.db test.db-journal test.db-wal | 27 forcedelete test.db test.db-journal test.db-wal |
| 35 sqlite3 db test.db | 28 sqlite3 db test.db |
| 36 | 29 |
| 37 #---------------------------------------------------------------------------- | 30 #---------------------------------------------------------------------------- |
| 38 # Test cases shell4-1.*: Tests specific to the "stats" command. | 31 # Test cases shell4-1.*: Tests specific to the "stats" command. |
| 39 # | 32 # |
| 40 | 33 |
| 41 # should default to off | 34 # should default to off |
| 42 do_test shell4-1.1.1 { | 35 do_test shell4-1.1.1 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 54 set res [catchcmd "-stats test.db" ".show"] | 47 set res [catchcmd "-stats test.db" ".show"] |
| 55 list [regexp {stats: on} $res] | 48 list [regexp {stats: on} $res] |
| 56 } {1} | 49 } {1} |
| 57 | 50 |
| 58 do_test shell4-1.2.2 { | 51 do_test shell4-1.2.2 { |
| 59 set res [catchcmd "-stats test.db" ".show"] | 52 set res [catchcmd "-stats test.db" ".show"] |
| 60 list [regexp {stats: off} $res] | 53 list [regexp {stats: off} $res] |
| 61 } {0} | 54 } {0} |
| 62 | 55 |
| 63 # .stats ON|OFF Turn stats on or off | 56 # .stats ON|OFF Turn stats on or off |
| 64 do_test shell4-1.3.1 { | 57 #do_test shell4-1.3.1 { |
| 65 catchcmd "test.db" ".stats" | 58 # catchcmd "test.db" ".stats" |
| 66 } {1 {Usage: .stats on|off}} | 59 #} {1 {Usage: .stats on|off}} |
| 67 do_test shell4-1.3.2 { | 60 do_test shell4-1.3.2 { |
| 68 catchcmd "test.db" ".stats ON" | 61 catchcmd "test.db" ".stats ON" |
| 69 } {0 {}} | 62 } {0 {}} |
| 70 do_test shell4-1.3.3 { | 63 do_test shell4-1.3.3 { |
| 71 catchcmd "test.db" ".stats OFF" | 64 catchcmd "test.db" ".stats OFF" |
| 72 } {0 {}} | 65 } {0 {}} |
| 73 do_test shell4-1.3.4 { | 66 do_test shell4-1.3.4 { |
| 74 # too many arguments | 67 # too many arguments |
| 75 catchcmd "test.db" ".stats OFF BAD" | 68 catchcmd "test.db" ".stats OFF BAD" |
| 76 } {1 {Usage: .stats on|off}} | 69 } {1 {Usage: .stats ?on|off?}} |
| 77 | 70 |
| 78 # NB. whitespace is important | 71 # NB. whitespace is important |
| 79 do_test shell4-1.4.1 { | 72 do_test shell4-1.4.1 { |
| 80 set res [catchcmd "test.db" {.show}] | 73 set res [catchcmd "test.db" {.show}] |
| 81 list [regexp {stats: off} $res] | 74 list [regexp {stats: off} $res] |
| 82 } {1} | 75 } {1} |
| 83 | 76 |
| 84 do_test shell4-1.4.2 { | 77 do_test shell4-1.4.2 { |
| 85 set res [catchcmd "test.db" {.stats ON | 78 set res [catchcmd "test.db" {.stats ON |
| 86 .show | 79 .show |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 ifcapable trace { | 118 ifcapable trace { |
| 126 do_test shell4-2.4 { | 119 do_test shell4-2.4 { |
| 127 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;" | 120 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;" |
| 128 } {0 {CREATE TABLE t1(x); | 121 } {0 {CREATE TABLE t1(x); |
| 129 SELECT * FROM t1;}} | 122 SELECT * FROM t1;}} |
| 130 do_test shell4-2.5 { | 123 do_test shell4-2.5 { |
| 131 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;" | 124 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;" |
| 132 } {0 {SELECT * FROM t1;}} | 125 } {0 {SELECT * FROM t1;}} |
| 133 } | 126 } |
| 134 | 127 |
| 128 do_test shell4-3.1 { |
| 129 set fd [open t1.txt wb] |
| 130 puts $fd "SELECT 'squirrel';" |
| 131 close $fd |
| 132 exec $::CLI :memory: --interactive ".read t1.txt" |
| 133 } {squirrel} |
| 134 do_test shell4-3.2 { |
| 135 set fd [open t1.txt wb] |
| 136 puts $fd "SELECT 'pound: \302\243';" |
| 137 close $fd |
| 138 exec $::CLI :memory: --interactive ".read t1.txt" |
| 139 } {pound: £} |
| 135 | 140 |
| 136 finish_test | 141 finish_test |
| OLD | NEW |