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# 12# The focus of this file is testing the CLI shell tool. 13# These tests are specific to the .stats command. 14# 15# 2015-03-19: Added tests for .trace 16 17# Test plan: 18# 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# 23set testdir [file dirname $argv0] 24source $testdir/tester.tcl 25set CLI [test_find_cli] 26db close 27forcedelete test.db test.db-journal test.db-wal 28sqlite3 db test.db 29 30#---------------------------------------------------------------------------- 31# Test cases shell4-1.*: Tests specific to the "stats" command. 32# 33 34# should default to off 35do_test shell4-1.1.1 { 36 set res [catchcmd "test.db" ".show"] 37 list [regexp {stats: off} $res] 38} {1} 39 40do_test shell4-1.1.2 { 41 set res [catchcmd "test.db" ".show"] 42 list [regexp {stats: on} $res] 43} {0} 44 45# -stats should turn it on 46do_test shell4-1.2.1 { 47 set res [catchcmd "-stats test.db" ".show"] 48 list [regexp {stats: on} $res] 49} {1} 50 51do_test shell4-1.2.2 { 52 set res [catchcmd "-stats test.db" ".show"] 53 list [regexp {stats: off} $res] 54} {0} 55 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}} 60do_test shell4-1.3.2 { 61 catchcmd "test.db" ".stats ON" 62} {0 {}} 63do_test shell4-1.3.3 { 64 catchcmd "test.db" ".stats OFF" 65} {0 {}} 66do_test shell4-1.3.4 { 67 # too many arguments 68 catchcmd "test.db" ".stats OFF BAD" 69} {1 {Usage: .stats ?on|off?}} 70 71# NB. whitespace is important 72do_test shell4-1.4.1 { 73 set res [catchcmd "test.db" {.show}] 74 list [regexp {stats: off} $res] 75} {1} 76 77do_test shell4-1.4.2 { 78 set res [catchcmd "test.db" {.stats ON 79.show 80}] 81 list [regexp {stats: on} $res] 82} {1} 83 84do_test shell4-1.4.3 { 85 set res [catchcmd "test.db" {.stats OFF 86.show 87}] 88 list [regexp {stats: off} $res] 89} {1} 90 91# make sure stats not present when off 92do_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} 98 99# make sure stats are present when on 100do_test shell4-1.5.2 { 101 set res [catchcmd "test.db" {.stats ON 102SELECT 1; 103}] 104 list [regexp {Memory Used} $res] \ 105 [regexp {Heap Usage} $res] \ 106 [regexp {Autoindex Inserts} $res] 107} {1 1 1} 108 109do_test shell4-2.1 { 110 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace" 111} {1 {Usage: .trace FILE|off}} 112do_test shell4-2.2 { 113 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n" 114} {0 {}} 115do_test shell4-2.3 { 116 catchcmd ":memory:" ".trace stdout\n.trace\n.trace off\n.dump\n" 117} {/^1 {PRAGMA.*Usage:.*}$/} 118ifcapable trace { 119do_test shell4-2.4 { 120 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;" 121} {0 {CREATE TABLE t1(x); 122SELECT * FROM t1;}} 123do_test shell4-2.5 { 124 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;" 125} {0 {SELECT * FROM t1;}} 126} 127 128do_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} 134do_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: £} 140 141finish_test 142