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