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_find_cli]
28 forcedelete test.db test.db-journal test.db-wal
31 #----------------------------------------------------------------------------
32 # Test cases shell4-1.*: Tests specific to the "stats" command.
35 # should default to off
36 do_test shell4-1.1.1 {
37 set res [catchcmd "test.db" ".show"]
38 list [regexp {stats: off} $res]
41 do_test shell4-1.1.2 {
42 set res [catchcmd "test.db" ".show"]
43 list [regexp {stats: on} $res]
46 # -stats should turn it on
47 do_test shell4-1.2.1 {
48 set res [catchcmd "-stats test.db" ".show"]
49 list [regexp {stats: on} $res]
52 do_test shell4-1.2.2 {
53 set res [catchcmd "-stats test.db" ".show"]
54 list [regexp {stats: off} $res]
57 # .stats ON|OFF Turn stats on or off
58 #do_test shell4-1.3.1 {
59 # catchcmd "test.db" ".stats"
60 #} {1 {Usage: .stats on|off}}
61 do_test shell4-1.3.2 {
62 catchcmd "test.db" ".stats ON"
64 do_test shell4-1.3.3 {
65 catchcmd "test.db" ".stats OFF"
67 do_test shell4-1.3.4 {
69 catchcmd "test.db" ".stats OFF BAD"
70 } {1 {Usage: .stats ?on|off|stmt|vmstep?}}
72 # NB. whitespace is important
73 do_test shell4-1.4.1 {
74 set res [catchcmd "test.db" {.show}]
75 list [regexp {stats: off} $res]
78 do_test shell4-1.4.2 {
79 set res [catchcmd "test.db" {.stats ON
82 list [regexp {stats: on} $res]
85 do_test shell4-1.4.3 {
86 set res [catchcmd "test.db" {.stats OFF
89 list [regexp {stats: off} $res]
92 # make sure stats not present when off
93 do_test shell4-1.5.1 {
94 set res [catchcmd "test.db" {SELECT 1;}]
95 list [regexp {Memory Used} $res] \
96 [regexp {Heap Usage} $res] \
97 [regexp {Autoindex Inserts} $res]
100 # make sure stats are present when on
101 do_test shell4-1.5.2 {
102 set res [catchcmd "test.db" {.stats ON
105 list [regexp {Memory Used} $res] \
106 [regexp {Heap Usage} $res] \
107 [regexp {Autoindex Inserts} $res]
112 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown"
113 } {1 {Unknown option "--unknown" on ".trace"}}
115 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
118 catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n"
121 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
122 } {0 {CREATE TABLE t1(x);
125 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
126 } {0 {SELECT * FROM t1;}}
130 set fd [open t1.txt wb]
131 puts $fd "SELECT 'squirrel';"
133 exec $::CLI :memory: --interactive ".read t1.txt"
136 set fd [open t1.txt wb]
137 puts $fd "SELECT 'pound: \302\243';"
139 exec $::CLI :memory: --interactive ".read t1.txt"
143 set fd [open t1.txt wb]
144 puts $fd ".read t1.txt"
146 catchcmd ":memory:" ".read t1.txt"
147 } {1 {Input nesting limit (25) reached at line 1. Check recursion.}}