summaryrefslogtreecommitdiff
path: root/test/shell4.test
blob: c29faf00cfa18c085bdb862caa7d5693c4508cdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# 2010 July 28
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# The focus of this file is testing the CLI shell tool.
# These tests are specific to the .stats command.
#
# $Id: shell4.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $
#

# Test plan:
#
#   shell4-1.*: Basic tests specific to the "stats" command.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
if {$tcl_platform(platform)=="windows"} {
  set CLI "sqlite3.exe"
} else {
  set CLI "./sqlite3"
}
if {![file executable $CLI]} {
  finish_test
  return
}
db close
forcedelete test.db test.db-journal test.db-wal
sqlite3 db test.db

#----------------------------------------------------------------------------
# Test cases shell4-1.*: Tests specific to the "stats" command.
#

# should default to off
do_test shell4-1.1.1 {
  set res [catchcmd "test.db" ".show"]
  list [regexp {stats: off} $res]
} {1}

do_test shell4-1.1.2 {
  set res [catchcmd "test.db" ".show"]
  list [regexp {stats: on} $res]
} {0}

# -stats should turn it on
do_test shell4-1.2.1 {
  set res [catchcmd "-stats test.db" ".show"]
  list [regexp {stats: on} $res]
} {1}

do_test shell4-1.2.2 {
  set res [catchcmd "-stats test.db" ".show"]
  list [regexp {stats: off} $res]
} {0}

# .stats ON|OFF          Turn stats on or off
do_test shell4-1.3.1 {
  catchcmd "test.db" ".stats"
} {1 {Usage: .stats on|off}}
do_test shell4-1.3.2 {
  catchcmd "test.db" ".stats ON"
} {0 {}}
do_test shell4-1.3.3 {
  catchcmd "test.db" ".stats OFF"
} {0 {}}
do_test shell4-1.3.4 {
  # too many arguments
  catchcmd "test.db" ".stats OFF BAD"
} {1 {Usage: .stats on|off}}

# NB. whitespace is important
do_test shell4-1.4.1 {
  set res [catchcmd "test.db" {.show}]
  list [regexp {stats: off} $res]
} {1}

do_test shell4-1.4.2 {
  set res [catchcmd "test.db" {.stats ON
.show
}]
  list [regexp {stats: on} $res]
} {1}

do_test shell4-1.4.3 {
  set res [catchcmd "test.db" {.stats OFF
.show
}]
  list [regexp {stats: off} $res]
} {1}

# make sure stats not present when off
do_test shell4-1.5.1 {
  set res [catchcmd "test.db" {SELECT 1;}]
  list [regexp {Memory Used} $res] \
       [regexp {Heap Usage} $res] \
       [regexp {Autoindex Inserts} $res]
} {0 0 0}

# make sure stats are present when on
do_test shell4-1.5.2 {
  set res [catchcmd "test.db" {.stats ON
SELECT 1;
}]
  list [regexp {Memory Used} $res] \
       [regexp {Heap Usage} $res] \
       [regexp {Autoindex Inserts} $res]
} {1 1 1}

finish_test