shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 1 | # 2010 July 28 |
| 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. |
shaneh | 1b8f78c | 2010-08-18 17:16:26 +0000 | [diff] [blame] | 13 | # These tests are specific to the .stats command. |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 14 | # |
drh | 657b4a8 | 2015-03-19 13:30:41 +0000 | [diff] [blame] | 15 | # 2015-03-19: Added tests for .trace |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 16 | |
| 17 | # Test plan: |
| 18 | # |
| 19 | # shell4-1.*: Basic tests specific to the "stats" command. |
drh | 657b4a8 | 2015-03-19 13:30:41 +0000 | [diff] [blame] | 20 | # shell4-2.*: Basic tests for ".trace" |
drh | fc8b40f | 2016-09-07 10:10:18 +0000 | [diff] [blame] | 21 | # shell4-3.*: The ".read" command takes the shell out of interactive mode |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 22 | # |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 23 | set testdir [file dirname $argv0] |
| 24 | source $testdir/tester.tcl |
dan | 089555c | 2016-03-15 09:55:44 +0000 | [diff] [blame] | 25 | set CLI [test_find_cli] |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 26 | db close |
| 27 | forcedelete test.db test.db-journal test.db-wal |
| 28 | sqlite3 db test.db |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 29 | |
| 30 | #---------------------------------------------------------------------------- |
| 31 | # Test cases shell4-1.*: Tests specific to the "stats" command. |
| 32 | # |
| 33 | |
| 34 | # should default to off |
| 35 | do_test shell4-1.1.1 { |
| 36 | set res [catchcmd "test.db" ".show"] |
| 37 | list [regexp {stats: off} $res] |
| 38 | } {1} |
| 39 | |
| 40 | do_test shell4-1.1.2 { |
| 41 | set res [catchcmd "test.db" ".show"] |
| 42 | list [regexp {stats: on} $res] |
| 43 | } {0} |
| 44 | |
| 45 | # -stats should turn it on |
| 46 | do_test shell4-1.2.1 { |
| 47 | set res [catchcmd "-stats test.db" ".show"] |
| 48 | list [regexp {stats: on} $res] |
| 49 | } {1} |
| 50 | |
| 51 | do_test shell4-1.2.2 { |
| 52 | set res [catchcmd "-stats test.db" ".show"] |
| 53 | list [regexp {stats: off} $res] |
| 54 | } {0} |
| 55 | |
| 56 | # .stats ON|OFF Turn stats on or off |
drh | 3478490 | 2016-02-27 17:12:36 +0000 | [diff] [blame] | 57 | #do_test shell4-1.3.1 { |
| 58 | # catchcmd "test.db" ".stats" |
| 59 | #} {1 {Usage: .stats on|off}} |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 60 | do_test shell4-1.3.2 { |
| 61 | catchcmd "test.db" ".stats ON" |
| 62 | } {0 {}} |
| 63 | do_test shell4-1.3.3 { |
| 64 | catchcmd "test.db" ".stats OFF" |
| 65 | } {0 {}} |
| 66 | do_test shell4-1.3.4 { |
| 67 | # too many arguments |
| 68 | catchcmd "test.db" ".stats OFF BAD" |
drh | 3478490 | 2016-02-27 17:12:36 +0000 | [diff] [blame] | 69 | } {1 {Usage: .stats ?on|off?}} |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 70 | |
| 71 | # NB. whitespace is important |
| 72 | do_test shell4-1.4.1 { |
| 73 | set res [catchcmd "test.db" {.show}] |
| 74 | list [regexp {stats: off} $res] |
| 75 | } {1} |
| 76 | |
| 77 | do_test shell4-1.4.2 { |
| 78 | set res [catchcmd "test.db" {.stats ON |
| 79 | .show |
| 80 | }] |
| 81 | list [regexp {stats: on} $res] |
| 82 | } {1} |
| 83 | |
| 84 | do_test shell4-1.4.3 { |
| 85 | set res [catchcmd "test.db" {.stats OFF |
| 86 | .show |
| 87 | }] |
| 88 | list [regexp {stats: off} $res] |
| 89 | } {1} |
| 90 | |
| 91 | # make sure stats not present when off |
| 92 | do_test shell4-1.5.1 { |
| 93 | set res [catchcmd "test.db" {SELECT 1;}] |
drh | abc97a7 | 2010-07-28 17:16:41 +0000 | [diff] [blame] | 94 | list [regexp {Memory Used} $res] \ |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 95 | [regexp {Heap Usage} $res] \ |
| 96 | [regexp {Autoindex Inserts} $res] |
| 97 | } {0 0 0} |
| 98 | |
| 99 | # make sure stats are present when on |
| 100 | do_test shell4-1.5.2 { |
| 101 | set res [catchcmd "test.db" {.stats ON |
| 102 | SELECT 1; |
| 103 | }] |
drh | abc97a7 | 2010-07-28 17:16:41 +0000 | [diff] [blame] | 104 | list [regexp {Memory Used} $res] \ |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 105 | [regexp {Heap Usage} $res] \ |
| 106 | [regexp {Autoindex Inserts} $res] |
| 107 | } {1 1 1} |
| 108 | |
dan | fbf6136 | 2019-02-06 13:48:04 +0000 | [diff] [blame] | 109 | ifcapable trace { |
drh | 657b4a8 | 2015-03-19 13:30:41 +0000 | [diff] [blame] | 110 | do_test shell4-2.1 { |
drh | 707821f | 2018-12-05 13:39:06 +0000 | [diff] [blame] | 111 | catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown" |
| 112 | } {1 {Unknown option "--unknown" on ".trace"}} |
drh | 657b4a8 | 2015-03-19 13:30:41 +0000 | [diff] [blame] | 113 | do_test shell4-2.2 { |
| 114 | catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n" |
| 115 | } {0 {}} |
| 116 | do_test shell4-2.3 { |
drh | 707821f | 2018-12-05 13:39:06 +0000 | [diff] [blame] | 117 | catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n" |
| 118 | } {/^0 {PRAGMA.*}$/} |
drh | 657b4a8 | 2015-03-19 13:30:41 +0000 | [diff] [blame] | 119 | do_test shell4-2.4 { |
| 120 | catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;" |
| 121 | } {0 {CREATE TABLE t1(x); |
| 122 | SELECT * FROM t1;}} |
| 123 | do_test shell4-2.5 { |
| 124 | catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;" |
| 125 | } {0 {SELECT * FROM t1;}} |
dan | 998aaa0 | 2015-03-21 12:22:51 +0000 | [diff] [blame] | 126 | } |
drh | 657b4a8 | 2015-03-19 13:30:41 +0000 | [diff] [blame] | 127 | |
drh | fc8b40f | 2016-09-07 10:10:18 +0000 | [diff] [blame] | 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: £} |
drh | 657b4a8 | 2015-03-19 13:30:41 +0000 | [diff] [blame] | 140 | |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 141 | finish_test |