blob: 085c279bb3148dc4ccda9a1c392613b78fc27e0d [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#
15# $Id: shell4.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
16#
17
18# Test plan:
19#
20# shell4-1.*: Basic tests specific to the "stats" command.
21#
22
shaneh642d8b82010-07-28 16:05:34 +000023set CLI "./sqlite3"
24
25proc do_test {name cmd expected} {
26 puts -nonewline "$name ..."
27 set res [uplevel $cmd]
28 if {$res eq $expected} {
29 puts Ok
30 } else {
31 puts Error
32 puts " Got: $res"
33 puts " Expected: $expected"
34 exit
35 }
36}
37
shaneh642d8b82010-07-28 16:05:34 +000038proc catchcmd {db {cmd ""}} {
39 global CLI
40 set out [open cmds.txt w]
41 puts $out $cmd
42 close $out
43 set line "exec $CLI $db < cmds.txt"
44 set rc [catch { eval $line } msg]
45 list $rc $msg
46}
47
48file delete -force test.db test.db.journal
shaneh642d8b82010-07-28 16:05:34 +000049
50#----------------------------------------------------------------------------
51# Test cases shell4-1.*: Tests specific to the "stats" command.
52#
53
54# should default to off
55do_test shell4-1.1.1 {
56 set res [catchcmd "test.db" ".show"]
57 list [regexp {stats: off} $res]
58} {1}
59
60do_test shell4-1.1.2 {
61 set res [catchcmd "test.db" ".show"]
62 list [regexp {stats: on} $res]
63} {0}
64
65# -stats should turn it on
66do_test shell4-1.2.1 {
67 set res [catchcmd "-stats test.db" ".show"]
68 list [regexp {stats: on} $res]
69} {1}
70
71do_test shell4-1.2.2 {
72 set res [catchcmd "-stats test.db" ".show"]
73 list [regexp {stats: off} $res]
74} {0}
75
76# .stats ON|OFF Turn stats on or off
77do_test shell4-1.3.1 {
78 catchcmd "test.db" ".stats"
79} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
80do_test shell4-1.3.2 {
81 catchcmd "test.db" ".stats ON"
82} {0 {}}
83do_test shell4-1.3.3 {
84 catchcmd "test.db" ".stats OFF"
85} {0 {}}
86do_test shell4-1.3.4 {
87 # too many arguments
88 catchcmd "test.db" ".stats OFF BAD"
89} {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
90
91# NB. whitespace is important
92do_test shell4-1.4.1 {
93 set res [catchcmd "test.db" {.show}]
94 list [regexp {stats: off} $res]
95} {1}
96
97do_test shell4-1.4.2 {
98 set res [catchcmd "test.db" {.stats ON
99.show
100}]
101 list [regexp {stats: on} $res]
102} {1}
103
104do_test shell4-1.4.3 {
105 set res [catchcmd "test.db" {.stats OFF
106.show
107}]
108 list [regexp {stats: off} $res]
109} {1}
110
111# make sure stats not present when off
112do_test shell4-1.5.1 {
113 set res [catchcmd "test.db" {SELECT 1;}]
drhabc97a72010-07-28 17:16:41 +0000114 list [regexp {Memory Used} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000115 [regexp {Heap Usage} $res] \
116 [regexp {Autoindex Inserts} $res]
117} {0 0 0}
118
119# make sure stats are present when on
120do_test shell4-1.5.2 {
121 set res [catchcmd "test.db" {.stats ON
122SELECT 1;
123}]
drhabc97a72010-07-28 17:16:41 +0000124 list [regexp {Memory Used} $res] \
shaneh642d8b82010-07-28 16:05:34 +0000125 [regexp {Heap Usage} $res] \
126 [regexp {Autoindex Inserts} $res]
127} {1 1 1}
128
129puts "CLI tests completed successfully"