Update tests in returning1.test to account for [c7896e88].
[sqlite.git] / test / shell4.test
blob4b7e9b8eec91106111a5dbad9f9b6993c880e9c9
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 #***********************************************************************
11 # TESTRUNNER: shell
13 # The focus of this file is testing the CLI shell tool.
14 # These tests are specific to the .stats command.
16 # 2015-03-19:  Added tests for .trace
18 # Test plan:
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
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
33 #----------------------------------------------------------------------------
34 # Test cases shell4-1.*: Tests specific to the "stats" command.
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}
43 do_test shell4-1.1.2 {
44   set res [catchcmd "test.db" ".show"]
45   list [regexp {stats: on} $res]
46 } {0}
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}
54 do_test shell4-1.2.2 {
55   set res [catchcmd "-stats test.db" ".show"]
56   list [regexp {stats: off} $res]
57 } {0}
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?}}
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}
80 do_test shell4-1.4.2 {
81   set res [catchcmd "test.db" {.stats ON
82 .show
84   list [regexp {stats: on} $res]
85 } {1}
87 do_test shell4-1.4.3 {
88   set res [catchcmd "test.db" {.stats OFF
89 .show
91   list [regexp {stats: off} $res]
92 } {1}
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}
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;
107   list [regexp {Memory Used} $res] \
108        [regexp {Heap Usage} $res] \
109        [regexp {Autoindex Inserts} $res]
110 } {1 1 1}
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;}}
137 do_test shell4-3.1 {
138   set fd [open t1.txt wb]
139   puts $fd "SELECT 'squirrel';"
140   close $fd
141   exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
142 } {squirrel}
143 do_test shell4-3.2 {
144   set fd [open t1.txt wb]
145   puts $fd "SELECT 'pound: \302\243';"
146   close $fd
147   exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
148 } {pound: £}
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 {Input nesting limit (25) reached at line 1. Check recursion.}}
157 finish_test