blob: 386e51f6c70215724d300f11dccb1f5081150ef8 [file] [log] [blame]
shaneh642d8b82010-07-28 16:05:34 +00001# 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.
shaneh1b8f78c2010-08-18 17:16:26 +000013# These tests are specific to the .stats command.
shaneh642d8b82010-07-28 16:05:34 +000014#
drh657b4a82015-03-19 13:30:41 +000015# 2015-03-19: Added tests for .trace
shaneh642d8b82010-07-28 16:05:34 +000016
17# Test plan:
18#
19# shell4-1.*: Basic tests specific to the "stats" command.
drh657b4a82015-03-19 13:30:41 +000020# shell4-2.*: Basic tests for ".trace"
drhfc8b40f2016-09-07 10:10:18 +000021# shell4-3.*: The ".read" command takes the shell out of interactive mode
shaneh642d8b82010-07-28 16:05:34 +000022#
drh8df91852012-04-24 12:46:05 +000023set testdir [file dirname $argv0]
24source $testdir/tester.tcl
dan089555c2016-03-15 09:55:44 +000025set CLI [test_find_cli]
drh8df91852012-04-24 12:46:05 +000026db close
27forcedelete test.db test.db-journal test.db-wal
28sqlite3 db test.db
shaneh642d8b82010-07-28 16:05:34 +000029
30#----------------------------------------------------------------------------
31# Test cases shell4-1.*: Tests specific to the "stats" command.
32#
33
34# should default to off
35do_test shell4-1.1.1 {
36 set res [catchcmd "test.db" ".show"]
37 list [regexp {stats: off} $res]
38} {1}
39
40do_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
46do_test shell4-1.2.1 {
47 set res [catchcmd "-stats test.db" ".show"]
48 list [regexp {stats: on} $res]
49} {1}
50
51do_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
drh34784902016-02-27 17:12:36 +000057#do_test shell4-1.3.1 {
58# catchcmd "test.db" ".stats"
59#} {1 {Usage: .stats on|off}}
shaneh642d8b82010-07-28 16:05:34 +000060do_test shell4-1.3.2 {
61 catchcmd "test.db" ".stats ON"
62} {0 {}}
63do_test shell4-1.3.3 {
64 catchcmd "test.db" ".stats OFF"
65} {0 {}}
66do_test shell4-1.3.4 {
67 # too many arguments
68 catchcmd "test.db" ".stats OFF BAD"
drh34784902016-02-27 17:12:36 +000069} {1 {Usage: .stats ?on|off?}}
shaneh642d8b82010-07-28 16:05:34 +000070
71# NB. whitespace is important
72do_test shell4-1.4.1 {
73 set res [catchcmd "test.db" {.show}]
74 list [regexp {stats: off} $res]
75} {1}
76
77do_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
84do_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
92do_test shell4-1.5.1 {
93 set res [catchcmd "test.db" {SELECT 1;}]
drhabc97a72010-07-28 17:16:41 +000094 list [regexp {Memory Used} $res] \
shaneh642d8b82010-07-28 16:05:34 +000095 [regexp {Heap Usage} $res] \
96 [regexp {Autoindex Inserts} $res]
97} {0 0 0}
98
99# make sure stats are present when on
100do_test shell4-1.5.2 {
101 set res [catchcmd "test.db" {.stats ON
102SELECT 1;
103}]
drhabc97a72010-07-28 17:16:41 +0000104 list [regexp {Memory Used} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000105 [regexp {Heap Usage} $res] \
106 [regexp {Autoindex Inserts} $res]
107} {1 1 1}
108
danfbf61362019-02-06 13:48:04 +0000109ifcapable trace {
drh657b4a82015-03-19 13:30:41 +0000110do_test shell4-2.1 {
drh707821f2018-12-05 13:39:06 +0000111 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown"
112} {1 {Unknown option "--unknown" on ".trace"}}
drh657b4a82015-03-19 13:30:41 +0000113do_test shell4-2.2 {
114 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
115} {0 {}}
116do_test shell4-2.3 {
drh707821f2018-12-05 13:39:06 +0000117 catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n"
118} {/^0 {PRAGMA.*}$/}
drh657b4a82015-03-19 13:30:41 +0000119do_test shell4-2.4 {
120 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
121} {0 {CREATE TABLE t1(x);
122SELECT * FROM t1;}}
123do_test shell4-2.5 {
124 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
125} {0 {SELECT * FROM t1;}}
dan998aaa02015-03-21 12:22:51 +0000126}
drh657b4a82015-03-19 13:30:41 +0000127
drhfc8b40f2016-09-07 10:10:18 +0000128do_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}
134do_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: £}
drh657b4a82015-03-19 13:30:41 +0000140
drh8df91852012-04-24 12:46:05 +0000141finish_test