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
23 set testdir [file dirname $argv0]
24 source $testdir/tester.tcl
25 set CLI [test_find_cli]
27 forcedelete test.db test.db-journal test.db-wal
30 #----------------------------------------------------------------------------
31 # Test cases shell4-1.*: Tests specific to the "stats" command.
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]
40 do_test shell4-1.1.2 {
41 set res [catchcmd "test.db" ".show"]
42 list [regexp {stats: on} $res]
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]
51 do_test shell4-1.2.2 {
52 set res [catchcmd "-stats test.db" ".show"]
53 list [regexp {stats: off} $res]
56 # .stats ON|OFF Turn stats on or off
57 #do_test shell4-1.3.1 {
58 # catchcmd "test.db" ".stats"
59 #} {1 {Usage: .stats on|off}}
60 do_test shell4-1.3.2 {
61 catchcmd "test.db" ".stats ON"
63 do_test shell4-1.3.3 {
64 catchcmd "test.db" ".stats OFF"
66 do_test shell4-1.3.4 {
68 catchcmd "test.db" ".stats OFF BAD"
69 } {1 {Usage: .stats ?on|off?}}
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]
77 do_test shell4-1.4.2 {
78 set res [catchcmd "test.db" {.stats ON
81 list [regexp {stats: on} $res]
84 do_test shell4-1.4.3 {
85 set res [catchcmd "test.db" {.stats OFF
88 list [regexp {stats: off} $res]
91 # make sure stats not present when off
92 do_test shell4-1.5.1 {
93 set res [catchcmd "test.db" {SELECT 1;}]
94 list [regexp {Memory Used} $res] \
95 [regexp {Heap Usage} $res] \
96 [regexp {Autoindex Inserts} $res]
99 # make sure stats are present when on
100 do_test shell4-1.5.2 {
101 set res [catchcmd "test.db" {.stats ON
104 list [regexp {Memory Used} $res] \
105 [regexp {Heap Usage} $res] \
106 [regexp {Autoindex Inserts} $res]
110 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace"
111 } {1 {Usage: .trace FILE|off}}
113 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
116 catchcmd ":memory:" ".trace stdout\n.trace\n.trace off\n.dump\n"
117 } {/^1 {PRAGMA.*Usage:.*}$/}
120 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
121 } {0 {CREATE TABLE t1(x);
124 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
125 } {0 {SELECT * FROM t1;}}
129 set fd [open t1.txt wb]
130 puts $fd "SELECT 'squirrel';"
132 exec $::CLI :memory: --interactive ".read t1.txt"
135 set fd [open t1.txt wb]
136 puts $fd "SELECT 'pound: \302\243';"
138 exec $::CLI :memory: --interactive ".read t1.txt"