Remove 'timespec' related code from the shell that has no effect and a (now) superflu...
[sqlite.git] / test / shell4.test
blob88e5e69a288fef4393c4b401272d4791a5161004
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
23 set testdir [file dirname $argv0]
24 source $testdir/tester.tcl
25 set CLI [test_find_cli]
26 db close
27 forcedelete test.db test.db-journal test.db-wal
28 sqlite3 db test.db
30 #----------------------------------------------------------------------------
31 # Test cases shell4-1.*: Tests specific to the "stats" command.
34 # should default to off
35 do_test shell4-1.1.1 {
36   set res [catchcmd "test.db" ".show"]
37   list [regexp {stats: off} $res]
38 } {1}
40 do_test shell4-1.1.2 {
41   set res [catchcmd "test.db" ".show"]
42   list [regexp {stats: on} $res]
43 } {0}
45 # -stats should turn it on
46 do_test shell4-1.2.1 {
47   set res [catchcmd "-stats test.db" ".show"]
48   list [regexp {stats: on} $res]
49 } {1}
51 do_test shell4-1.2.2 {
52   set res [catchcmd "-stats test.db" ".show"]
53   list [regexp {stats: off} $res]
54 } {0}
56 # .stats ON|OFF          Turn stats on or off
57 #do_test shell4-1.3.1 {
58 #  catchcmd "test.db" ".stats"
59 #} {1 {Usage: .stats on|off}}
60 do_test shell4-1.3.2 {
61   catchcmd "test.db" ".stats ON"
62 } {0 {}}
63 do_test shell4-1.3.3 {
64   catchcmd "test.db" ".stats OFF"
65 } {0 {}}
66 do_test shell4-1.3.4 {
67   # too many arguments
68   catchcmd "test.db" ".stats OFF BAD"
69 } {1 {Usage: .stats ?on|off?}}
71 # NB. whitespace is important
72 do_test shell4-1.4.1 {
73   set res [catchcmd "test.db" {.show}]
74   list [regexp {stats: off} $res]
75 } {1}
77 do_test shell4-1.4.2 {
78   set res [catchcmd "test.db" {.stats ON
79 .show
81   list [regexp {stats: on} $res]
82 } {1}
84 do_test shell4-1.4.3 {
85   set res [catchcmd "test.db" {.stats OFF
86 .show
88   list [regexp {stats: off} $res]
89 } {1}
91 # make sure stats not present when off
92 do_test shell4-1.5.1 {
93   set res [catchcmd "test.db" {SELECT 1;}]
94   list [regexp {Memory Used} $res] \
95        [regexp {Heap Usage} $res] \
96        [regexp {Autoindex Inserts} $res]
97 } {0 0 0}
99 # make sure stats are present when on
100 do_test shell4-1.5.2 {
101   set res [catchcmd "test.db" {.stats ON
102 SELECT 1;
104   list [regexp {Memory Used} $res] \
105        [regexp {Heap Usage} $res] \
106        [regexp {Autoindex Inserts} $res]
107 } {1 1 1}
109 do_test shell4-2.1 {
110   catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace"
111 } {1 {Usage: .trace FILE|off}}
112 do_test shell4-2.2 {
113   catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
114 } {0 {}}
115 do_test shell4-2.3 {
116   catchcmd ":memory:" ".trace stdout\n.trace\n.trace off\n.dump\n"
117 } {/^1 {PRAGMA.*Usage:.*}$/}
118 ifcapable trace {
119 do_test shell4-2.4 {
120   catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
121 } {0 {CREATE TABLE t1(x);
122 SELECT * FROM t1;}}
123 do_test shell4-2.5 {
124   catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
125 } {0 {SELECT * FROM t1;}}
128 do_test shell4-3.1 {
129   set fd [open t1.txt wb]
130   puts $fd "SELECT 'squirrel';"
131   close $fd
132   exec $::CLI :memory: --interactive ".read t1.txt"
133 } {squirrel}
134 do_test shell4-3.2 {
135   set fd [open t1.txt wb]
136   puts $fd "SELECT 'pound: \302\243';"
137   close $fd
138   exec $::CLI :memory: --interactive ".read t1.txt"
139 } {pound: £}
141 finish_test