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 # $Id: shell4.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
20 # shell4-1.*: Basic tests specific to the "stats" command.
25 proc do_test {name cmd expected} {
26 puts -nonewline "$name ..."
27 set res [uplevel $cmd]
28 if {$res eq $expected} {
33 puts " Expected: $expected"
38 proc catchcmd {db {cmd ""}} {
40 set out [open cmds.txt w]
43 set line "exec $CLI $db < cmds.txt"
44 set rc [catch { eval $line } msg]
48 file delete -force test.db test.db.journal
50 #----------------------------------------------------------------------------
51 # Test cases shell4-1.*: Tests specific to the "stats" command.
54 # should default to off
55 do_test shell4-1.1.1 {
56 set res [catchcmd "test.db" ".show"]
57 list [regexp {stats: off} $res]
60 do_test shell4-1.1.2 {
61 set res [catchcmd "test.db" ".show"]
62 list [regexp {stats: on} $res]
65 # -stats should turn it on
66 do_test shell4-1.2.1 {
67 set res [catchcmd "-stats test.db" ".show"]
68 list [regexp {stats: on} $res]
71 do_test shell4-1.2.2 {
72 set res [catchcmd "-stats test.db" ".show"]
73 list [regexp {stats: off} $res]
76 # .stats ON|OFF Turn stats on or off
77 do_test shell4-1.3.1 {
78 catchcmd "test.db" ".stats"
79 } {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
80 do_test shell4-1.3.2 {
81 catchcmd "test.db" ".stats ON"
83 do_test shell4-1.3.3 {
84 catchcmd "test.db" ".stats OFF"
86 do_test shell4-1.3.4 {
88 catchcmd "test.db" ".stats OFF BAD"
89 } {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
91 # NB. whitespace is important
92 do_test shell4-1.4.1 {
93 set res [catchcmd "test.db" {.show}]
94 list [regexp {stats: off} $res]
97 do_test shell4-1.4.2 {
98 set res [catchcmd "test.db" {.stats ON
101 list [regexp {stats: on} $res]
104 do_test shell4-1.4.3 {
105 set res [catchcmd "test.db" {.stats OFF
108 list [regexp {stats: off} $res]
111 # make sure stats not present when off
112 do_test shell4-1.5.1 {
113 set res [catchcmd "test.db" {SELECT 1;}]
114 list [regexp {Memory Used} $res] \
115 [regexp {Heap Usage} $res] \
116 [regexp {Autoindex Inserts} $res]
119 # make sure stats are present when on
120 do_test shell4-1.5.2 {
121 set res [catchcmd "test.db" {.stats ON
124 list [regexp {Memory Used} $res] \
125 [regexp {Heap Usage} $res] \
126 [regexp {Autoindex Inserts} $res]
129 puts "CLI tests completed successfully"