blob: 193dc8b69b842afdd4f49522014e9b3d361e5f78 [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
larrybrd48e88e2022-01-24 06:36:16 +000022# shell4-4.*: Input redirects cannot recurse too much
shaneh642d8b82010-07-28 16:05:34 +000023#
drh8df91852012-04-24 12:46:05 +000024set testdir [file dirname $argv0]
25source $testdir/tester.tcl
larrybr2f5f6742022-05-09 12:29:47 +000026set CLI [test_cli_invocation]
27set CLI_ONLY [test_find_cli]
drh8df91852012-04-24 12:46:05 +000028db close
29forcedelete test.db test.db-journal test.db-wal
30sqlite3 db test.db
shaneh642d8b82010-07-28 16:05:34 +000031
32#----------------------------------------------------------------------------
33# Test cases shell4-1.*: Tests specific to the "stats" command.
34#
35
36# should default to off
37do_test shell4-1.1.1 {
38 set res [catchcmd "test.db" ".show"]
39 list [regexp {stats: off} $res]
40} {1}
41
42do_test shell4-1.1.2 {
43 set res [catchcmd "test.db" ".show"]
44 list [regexp {stats: on} $res]
45} {0}
46
47# -stats should turn it on
48do_test shell4-1.2.1 {
49 set res [catchcmd "-stats test.db" ".show"]
50 list [regexp {stats: on} $res]
51} {1}
52
53do_test shell4-1.2.2 {
54 set res [catchcmd "-stats test.db" ".show"]
55 list [regexp {stats: off} $res]
56} {0}
57
58# .stats ON|OFF Turn stats on or off
drh34784902016-02-27 17:12:36 +000059#do_test shell4-1.3.1 {
60# catchcmd "test.db" ".stats"
61#} {1 {Usage: .stats on|off}}
shaneh642d8b82010-07-28 16:05:34 +000062do_test shell4-1.3.2 {
63 catchcmd "test.db" ".stats ON"
64} {0 {}}
65do_test shell4-1.3.3 {
66 catchcmd "test.db" ".stats OFF"
67} {0 {}}
68do_test shell4-1.3.4 {
69 # too many arguments
70 catchcmd "test.db" ".stats OFF BAD"
drha6e6cf22021-01-09 19:10:04 +000071} {1 {Usage: .stats ?on|off|stmt|vmstep?}}
shaneh642d8b82010-07-28 16:05:34 +000072
73# NB. whitespace is important
74do_test shell4-1.4.1 {
75 set res [catchcmd "test.db" {.show}]
76 list [regexp {stats: off} $res]
77} {1}
78
79do_test shell4-1.4.2 {
80 set res [catchcmd "test.db" {.stats ON
81.show
82}]
83 list [regexp {stats: on} $res]
84} {1}
85
86do_test shell4-1.4.3 {
87 set res [catchcmd "test.db" {.stats OFF
88.show
89}]
90 list [regexp {stats: off} $res]
91} {1}
92
93# make sure stats not present when off
94do_test shell4-1.5.1 {
95 set res [catchcmd "test.db" {SELECT 1;}]
drhabc97a72010-07-28 17:16:41 +000096 list [regexp {Memory Used} $res] \
shaneh642d8b82010-07-28 16:05:34 +000097 [regexp {Heap Usage} $res] \
98 [regexp {Autoindex Inserts} $res]
99} {0 0 0}
100
101# make sure stats are present when on
102do_test shell4-1.5.2 {
103 set res [catchcmd "test.db" {.stats ON
104SELECT 1;
105}]
drhabc97a72010-07-28 17:16:41 +0000106 list [regexp {Memory Used} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000107 [regexp {Heap Usage} $res] \
108 [regexp {Autoindex Inserts} $res]
109} {1 1 1}
110
danfbf61362019-02-06 13:48:04 +0000111ifcapable trace {
drh657b4a82015-03-19 13:30:41 +0000112do_test shell4-2.1 {
drh707821f2018-12-05 13:39:06 +0000113 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown"
114} {1 {Unknown option "--unknown" on ".trace"}}
drh657b4a82015-03-19 13:30:41 +0000115do_test shell4-2.2 {
116 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
117} {0 {}}
118do_test shell4-2.3 {
drh707821f2018-12-05 13:39:06 +0000119 catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n"
120} {/^0 {PRAGMA.*}$/}
drh657b4a82015-03-19 13:30:41 +0000121do_test shell4-2.4 {
122 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
123} {0 {CREATE TABLE t1(x);
124SELECT * FROM t1;}}
125do_test shell4-2.5 {
126 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
127} {0 {SELECT * FROM t1;}}
larrybrc1ca1832022-11-28 02:28:44 +0000128do_test shell4-2.6 {
129 catchcmd ":memory:" {
130CREATE TABLE t1(x);
131.trace --stmt stdout
132SELECT * FROM t1;}
133} {0 {SELECT * FROM t1;}}
dan998aaa02015-03-21 12:22:51 +0000134}
drh657b4a82015-03-19 13:30:41 +0000135
drhfc8b40f2016-09-07 10:10:18 +0000136do_test shell4-3.1 {
137 set fd [open t1.txt wb]
138 puts $fd "SELECT 'squirrel';"
139 close $fd
larrybr2f5f6742022-05-09 12:29:47 +0000140 exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
drhfc8b40f2016-09-07 10:10:18 +0000141} {squirrel}
142do_test shell4-3.2 {
143 set fd [open t1.txt wb]
144 puts $fd "SELECT 'pound: \302\243';"
145 close $fd
larrybr2f5f6742022-05-09 12:29:47 +0000146 exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
drhfc8b40f2016-09-07 10:10:18 +0000147} {pound: £}
drh657b4a82015-03-19 13:30:41 +0000148
larrybrd48e88e2022-01-24 06:36:16 +0000149do_test shell4-4.1 {
150 set fd [open t1.txt wb]
151 puts $fd ".read t1.txt"
152 close $fd
153 catchcmd ":memory:" ".read t1.txt"
larrybrb5d44732022-01-24 14:01:31 +0000154} {1 {Input nesting limit (25) reached at line 1. Check recursion.}}
larrybrd48e88e2022-01-24 06:36:16 +0000155
drh8df91852012-04-24 12:46:05 +0000156finish_test