Debian Codegraph @

test/shell4.test

raw
1 # 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 # TESTRUNNER: shell
12 #
13 # The focus of this file is testing the CLI shell tool.
14 # These tests are specific to the .stats command.
15 #
16 # 2015-03-19: Added tests for .trace
17
18 # Test plan:
19 #
20 # shell4-1.*: Basic tests specific to the "stats" command.
21 # shell4-2.*: Basic tests for ".trace"
22 # shell4-3.*: The ".read" command takes the shell out of interactive mode
23 # shell4-4.*: Input redirects cannot recurse too much
24 #
25 set testdir [file dirname $argv0]
26 source $testdir/tester.tcl
27 set CLI [test_cli_invocation]
28 set CLI_ONLY [test_find_cli]
29 db close
30 forcedelete test.db test.db-journal test.db-wal
31 sqlite3 db test.db
32
33 #----------------------------------------------------------------------------
34 # Test cases shell4-1.*: Tests specific to the "stats" command.
35 #
36
37 # should default to off
38 do_test shell4-1.1.1 {
39 set res [catchcmd "test.db" ".show"]
40 list [regexp {stats: off} $res]
41 } {1}
42
43 do_test shell4-1.1.2 {
44 set res [catchcmd "test.db" ".show"]
45 list [regexp {stats: on} $res]
46 } {0}
47
48 # -stats should turn it on
49 do_test shell4-1.2.1 {
50 set res [catchcmd "-stats test.db" ".show"]
51 list [regexp {stats: on} $res]
52 } {1}
53
54 do_test shell4-1.2.2 {
55 set res [catchcmd "-stats test.db" ".show"]
56 list [regexp {stats: off} $res]
57 } {0}
58
59 # .stats ON|OFF Turn stats on or off
60 #do_test shell4-1.3.1 {
61 # catchcmd "test.db" ".stats"
62 #} {1 {Usage: .stats on|off}}
63 do_test shell4-1.3.2 {
64 catchcmd "test.db" ".stats ON"
65 } {0 {}}
66 do_test shell4-1.3.3 {
67 catchcmd "test.db" ".stats OFF"
68 } {0 {}}
69 do_test shell4-1.3.4 {
70 # too many arguments
71 catchcmd "test.db" ".stats OFF BAD"
72 } {1 {Usage: .stats ?on|off|stmt|vmstep?}}
73
74 # NB. whitespace is important
75 do_test shell4-1.4.1 {
76 set res [catchcmd "test.db" {.show}]
77 list [regexp {stats: off} $res]
78 } {1}
79
80 do_test shell4-1.4.2 {
81 set res [catchcmd "test.db" {.stats ON
82 .show
83 }]
84 list [regexp {stats: on} $res]
85 } {1}
86
87 do_test shell4-1.4.3 {
88 set res [catchcmd "test.db" {.stats OFF
89 .show
90 }]
91 list [regexp {stats: off} $res]
92 } {1}
93
94 # make sure stats not present when off
95 do_test shell4-1.5.1 {
96 set res [catchcmd "test.db" {SELECT 1;}]
97 list [regexp {Memory Used} $res] \
98 [regexp {Heap Usage} $res] \
99 [regexp {Autoindex Inserts} $res]
100 } {0 0 0}
101
102 # make sure stats are present when on
103 do_test shell4-1.5.2 {
104 set res [catchcmd "test.db" {.stats ON
105 SELECT 1;
106 }]
107 list [regexp {Memory Used} $res] \
108 [regexp {Heap Usage} $res] \
109 [regexp {Autoindex Inserts} $res]
110 } {1 1 1}
111
112 ifcapable trace {
113 do_test shell4-2.1 {
114 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown"
115 } {1 {Unknown option "--unknown" on ".trace"}}
116 do_test shell4-2.2 {
117 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
118 } {0 {}}
119 do_test shell4-2.3 {
120 catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n"
121 } {/^0 {SELECT.*}$/}
122 do_test shell4-2.4 {
123 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
124 } {0 {CREATE TABLE t1(x);
125 SELECT * FROM t1;}}
126 do_test shell4-2.5 {
127 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
128 } {0 {SELECT * FROM t1;}}
129 do_test shell4-2.6 {
130 catchcmd ":memory:" {
131 CREATE TABLE t1(x);
132 .trace --stmt stdout
133 SELECT * FROM t1;}
134 } {0 {SELECT * FROM t1;}}
135 }
136
137 do_test shell4-3.1 {
138 set fd [open t1.txt wb]
139 puts $fd ".mode list\nSELECT 'squirrel';"
140 close $fd
141 exec $::CLI_ONLY --noinit :memory: --interactive ".read t1.txt"
142 } {squirrel}
143 do_test_with_ansi_output shell4-3.2 {
144 set fd [open t1.txt wb]
145 puts $fd ".mode list\nSELECT 'pound: \302\243';"
146 close $fd
147 exec $::CLI_ONLY --noinit :memory: --interactive ".read t1.txt"
148 } {pound: £}
149
150 do_test shell4-4.1 {
151 set fd [open t1.txt wb]
152 puts $fd ".read t1.txt"
153 close $fd
154 catchcmd ":memory:" ".read t1.txt"
155 } {1 {t1.txt: Input nesting limit (25) reached at line 1. Check recursion.}}
156
157 finish_test