3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
13 # The focus of this file is testing the CLI shell tool.
14 # These tests are specific to the .stats command.
16 # 2015-03-19: Added tests for .trace
20 # shell4-1.*: Basic tests specific to the "stats" command.
21 # shell4-2.*: Basic tests for ".trace"
22 # shell4-3.*: The ".read" command takes the shell out of interactive mode
23 # shell4-4.*: Input redirects cannot recurse too much
25 set testdir [file dirname $argv0]
26 source $testdir/tester.tcl
27 set CLI [test_cli_invocation]
28 set CLI_ONLY [test_find_cli]
30 forcedelete test.db test.db-journal test.db-wal
33 #----------------------------------------------------------------------------
34 # Test cases shell4-1.*: Tests specific to the "stats" command.
37 # should default to off
38 do_test shell4-1.1.1 {
39 set res [catchcmd "test.db" ".show"]
40 list [regexp {stats: off} $res]
43 do_test shell4-1.1.2 {
44 set res [catchcmd "test.db" ".show"]
45 list [regexp {stats: on} $res]
48 # -stats should turn it on
49 do_test shell4-1.2.1 {
50 set res [catchcmd "-stats test.db" ".show"]
51 list [regexp {stats: on} $res]
54 do_test shell4-1.2.2 {
55 set res [catchcmd "-stats test.db" ".show"]
56 list [regexp {stats: off} $res]
59 # .stats ON|OFF Turn stats on or off
60 #do_test shell4-1.3.1 {
61 # catchcmd "test.db" ".stats"
62 #} {1 {Usage: .stats on|off}}
63 do_test shell4-1.3.2 {
64 catchcmd "test.db" ".stats ON"
66 do_test shell4-1.3.3 {
67 catchcmd "test.db" ".stats OFF"
69 do_test shell4-1.3.4 {
71 catchcmd "test.db" ".stats OFF BAD"
72 } {1 {Usage: .stats ?on|off|stmt|vmstep?}}
74 # NB. whitespace is important
75 do_test shell4-1.4.1 {
76 set res [catchcmd "test.db" {.show}]
77 list [regexp {stats: off} $res]
80 do_test shell4-1.4.2 {
81 set res [catchcmd "test.db" {.stats ON
84 list [regexp {stats: on} $res]
87 do_test shell4-1.4.3 {
88 set res [catchcmd "test.db" {.stats OFF
91 list [regexp {stats: off} $res]
94 # make sure stats not present when off
95 do_test shell4-1.5.1 {
96 set res [catchcmd "test.db" {SELECT 1;}]
97 list [regexp {Memory Used} $res] \
98 [regexp {Heap Usage} $res] \
99 [regexp {Autoindex Inserts} $res]
102 # make sure stats are present when on
103 do_test shell4-1.5.2 {
104 set res [catchcmd "test.db" {.stats ON
107 list [regexp {Memory Used} $res] \
108 [regexp {Heap Usage} $res] \
109 [regexp {Autoindex Inserts} $res]
114 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown"
115 } {1 {Unknown option "--unknown" on ".trace"}}
117 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
120 catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n"
123 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
124 } {0 {CREATE TABLE t1(x);
127 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
128 } {0 {SELECT * FROM t1;}}
130 catchcmd ":memory:" {
134 } {0 {SELECT * FROM t1;}}
138 set fd [open t1.txt wb]
139 puts $fd "SELECT 'squirrel';"
141 exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
144 set fd [open t1.txt wb]
145 puts $fd "SELECT 'pound: \302\243';"
147 exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
151 set fd [open t1.txt wb]
152 puts $fd ".read t1.txt"
154 catchcmd ":memory:" ".read t1.txt"
155 } {1 {Input nesting limit (25) reached at line 1. Check recursion.}}