blob: fcb0b2b715042bfe2f4984a01b208afc3b1545b6 [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"
shaneh642d8b82010-07-28 16:05:34 +000021#
drh8df91852012-04-24 12:46:05 +000022set testdir [file dirname $argv0]
23source $testdir/tester.tcl
24if {$tcl_platform(platform)=="windows"} {
25 set CLI "sqlite3.exe"
26} else {
27 set CLI "./sqlite3"
shaneh642d8b82010-07-28 16:05:34 +000028}
drh8df91852012-04-24 12:46:05 +000029if {![file executable $CLI]} {
30 finish_test
31 return
shaneh642d8b82010-07-28 16:05:34 +000032}
drh8df91852012-04-24 12:46:05 +000033db close
34forcedelete test.db test.db-journal test.db-wal
35sqlite3 db test.db
shaneh642d8b82010-07-28 16:05:34 +000036
37#----------------------------------------------------------------------------
38# Test cases shell4-1.*: Tests specific to the "stats" command.
39#
40
41# should default to off
42do_test shell4-1.1.1 {
43 set res [catchcmd "test.db" ".show"]
44 list [regexp {stats: off} $res]
45} {1}
46
47do_test shell4-1.1.2 {
48 set res [catchcmd "test.db" ".show"]
49 list [regexp {stats: on} $res]
50} {0}
51
52# -stats should turn it on
53do_test shell4-1.2.1 {
54 set res [catchcmd "-stats test.db" ".show"]
55 list [regexp {stats: on} $res]
56} {1}
57
58do_test shell4-1.2.2 {
59 set res [catchcmd "-stats test.db" ".show"]
60 list [regexp {stats: off} $res]
61} {0}
62
63# .stats ON|OFF Turn stats on or off
64do_test shell4-1.3.1 {
65 catchcmd "test.db" ".stats"
drhc2ce0be2014-05-29 12:36:14 +000066} {1 {Usage: .stats on|off}}
shaneh642d8b82010-07-28 16:05:34 +000067do_test shell4-1.3.2 {
68 catchcmd "test.db" ".stats ON"
69} {0 {}}
70do_test shell4-1.3.3 {
71 catchcmd "test.db" ".stats OFF"
72} {0 {}}
73do_test shell4-1.3.4 {
74 # too many arguments
75 catchcmd "test.db" ".stats OFF BAD"
drhc2ce0be2014-05-29 12:36:14 +000076} {1 {Usage: .stats on|off}}
shaneh642d8b82010-07-28 16:05:34 +000077
78# NB. whitespace is important
79do_test shell4-1.4.1 {
80 set res [catchcmd "test.db" {.show}]
81 list [regexp {stats: off} $res]
82} {1}
83
84do_test shell4-1.4.2 {
85 set res [catchcmd "test.db" {.stats ON
86.show
87}]
88 list [regexp {stats: on} $res]
89} {1}
90
91do_test shell4-1.4.3 {
92 set res [catchcmd "test.db" {.stats OFF
93.show
94}]
95 list [regexp {stats: off} $res]
96} {1}
97
98# make sure stats not present when off
99do_test shell4-1.5.1 {
100 set res [catchcmd "test.db" {SELECT 1;}]
drhabc97a72010-07-28 17:16:41 +0000101 list [regexp {Memory Used} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000102 [regexp {Heap Usage} $res] \
103 [regexp {Autoindex Inserts} $res]
104} {0 0 0}
105
106# make sure stats are present when on
107do_test shell4-1.5.2 {
108 set res [catchcmd "test.db" {.stats ON
109SELECT 1;
110}]
drhabc97a72010-07-28 17:16:41 +0000111 list [regexp {Memory Used} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000112 [regexp {Heap Usage} $res] \
113 [regexp {Autoindex Inserts} $res]
114} {1 1 1}
115
drh657b4a82015-03-19 13:30:41 +0000116do_test shell4-2.1 {
117 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace"
118} {1 {Usage: .trace FILE|off}}
119do_test shell4-2.2 {
120 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
121} {0 {}}
122do_test shell4-2.3 {
123 catchcmd ":memory:" ".trace stdout\n.trace\n.trace off\n.dump\n"
124} {/^1 {PRAGMA.*Usage:.*}$/}
dan998aaa02015-03-21 12:22:51 +0000125ifcapable trace {
drh657b4a82015-03-19 13:30:41 +0000126do_test shell4-2.4 {
127 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
128} {0 {CREATE TABLE t1(x);
129SELECT * FROM t1;}}
130do_test shell4-2.5 {
131 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
132} {0 {SELECT * FROM t1;}}
dan998aaa02015-03-21 12:22:51 +0000133}
drh657b4a82015-03-19 13:30:41 +0000134
135
drh8df91852012-04-24 12:46:05 +0000136finish_test