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 #***********************************************************************
12 # The focus of this file is testing the CLI shell tool.
13 # These tests are specific to the .stats command.
15 # 2015-03-19: Added tests for .trace
19 # shell4-1.*: Basic tests specific to the "stats" command.
20 # shell4-2.*: Basic tests for ".trace"
21 # shell4-3.*: The ".read" command takes the shell out of interactive mode
22 # shell4-4.*: Input redirects cannot recurse too much
24 set testdir [file dirname $argv0]
25 source $testdir/tester.tcl
26 set CLI [test_cli_invocation]
27 set CLI_ONLY [test_find_cli]
29 forcedelete test.db test.db-journal test.db-wal
32 #----------------------------------------------------------------------------
33 # Test cases shell4-1.*: Tests specific to the "stats" command.
36 # should default to off
37 do_test shell4-1.1.1 {
38 set res [catchcmd "test.db" ".show"]
39 list [regexp {stats: off} $res]
42 do_test shell4-1.1.2 {
43 set res [catchcmd "test.db" ".show"]
44 list [regexp {stats: on} $res]
47 # -stats should turn it on
48 do_test shell4-1.2.1 {
49 set res [catchcmd "-stats test.db" ".show"]
50 list [regexp {stats: on} $res]
53 do_test shell4-1.2.2 {
54 set res [catchcmd "-stats test.db" ".show"]
55 list [regexp {stats: off} $res]
58 # .stats ON|OFF Turn stats on or off
59 #do_test shell4-1.3.1 {
60 # catchcmd "test.db" ".stats"
61 #} {1 {Usage: .stats on|off}}
62 do_test shell4-1.3.2 {
63 catchcmd "test.db" ".stats ON"
65 do_test shell4-1.3.3 {
66 catchcmd "test.db" ".stats OFF"
68 do_test shell4-1.3.4 {
70 catchcmd "test.db" ".stats OFF BAD"
71 } {1 {Usage: .stats ?on|off|stmt|vmstep?}}
73 # NB. whitespace is important
74 do_test shell4-1.4.1 {
75 set res [catchcmd "test.db" {.show}]
76 list [regexp {stats: off} $res]
79 do_test shell4-1.4.2 {
80 set res [catchcmd "test.db" {.stats ON
83 list [regexp {stats: on} $res]
86 do_test shell4-1.4.3 {
87 set res [catchcmd "test.db" {.stats OFF
90 list [regexp {stats: off} $res]
93 # make sure stats not present when off
94 do_test shell4-1.5.1 {
95 set res [catchcmd "test.db" {SELECT 1;}]
96 list [regexp {Memory Used} $res] \
97 [regexp {Heap Usage} $res] \
98 [regexp {Autoindex Inserts} $res]
101 # make sure stats are present when on
102 do_test shell4-1.5.2 {
103 set res [catchcmd "test.db" {.stats ON
106 list [regexp {Memory Used} $res] \
107 [regexp {Heap Usage} $res] \
108 [regexp {Autoindex Inserts} $res]
113 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown"
114 } {1 {Unknown option "--unknown" on ".trace"}}
116 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
119 catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n"
122 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
123 } {0 {CREATE TABLE t1(x);
126 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
127 } {0 {SELECT * FROM t1;}}
129 catchcmd ":memory:" {
133 } {0 {SELECT * FROM t1;}}
137 set fd [open t1.txt wb]
138 puts $fd "SELECT 'squirrel';"
140 exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
143 set fd [open t1.txt wb]
144 puts $fd "SELECT 'pound: \302\243';"
146 exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
150 set fd [open t1.txt wb]
151 puts $fd ".read t1.txt"
153 catchcmd ":memory:" ".read t1.txt"
154 } {1 {Input nesting limit (25) reached at line 1. Check recursion.}}