18df9185cSdrh# 2010 July 28 28df9185cSdrh# 38df9185cSdrh# The author disclaims copyright to this source code. In place of 48df9185cSdrh# a legal notice, here is a blessing: 58df9185cSdrh# 68df9185cSdrh# May you do good and not evil. 78df9185cSdrh# May you find forgiveness for yourself and forgive others. 88df9185cSdrh# May you share freely, never taking more than you give. 98df9185cSdrh# 108df9185cSdrh#*********************************************************************** 118df9185cSdrh# 128df9185cSdrh# The focus of this file is testing the CLI shell tool. 138df9185cSdrh# These tests are specific to the .stats command. 148df9185cSdrh# 15657b4a87Sdrh# 2015-03-19: Added tests for .trace 168df9185cSdrh 178df9185cSdrh# Test plan: 188df9185cSdrh# 198df9185cSdrh# shell4-1.*: Basic tests specific to the "stats" command. 20657b4a87Sdrh# shell4-2.*: Basic tests for ".trace" 21fc8b40f2Sdrh# shell4-3.*: The ".read" command takes the shell out of interactive mode 22d48e88e5Slarrybr# shell4-4.*: Input redirects cannot recurse too much 238df9185cSdrh# 248df9185cSdrhset testdir [file dirname $argv0] 258df9185cSdrhsource $testdir/tester.tcl 26*2f5f6740Slarrybrset CLI [test_cli_invocation] 27*2f5f6740Slarrybrset CLI_ONLY [test_find_cli] 288df9185cSdrhdb close 298df9185cSdrhforcedelete test.db test.db-journal test.db-wal 308df9185cSdrhsqlite3 db test.db 318df9185cSdrh 328df9185cSdrh#---------------------------------------------------------------------------- 338df9185cSdrh# Test cases shell4-1.*: Tests specific to the "stats" command. 348df9185cSdrh# 358df9185cSdrh 368df9185cSdrh# should default to off 378df9185cSdrhdo_test shell4-1.1.1 { 388df9185cSdrh set res [catchcmd "test.db" ".show"] 398df9185cSdrh list [regexp {stats: off} $res] 408df9185cSdrh} {1} 418df9185cSdrh 428df9185cSdrhdo_test shell4-1.1.2 { 438df9185cSdrh set res [catchcmd "test.db" ".show"] 448df9185cSdrh list [regexp {stats: on} $res] 458df9185cSdrh} {0} 468df9185cSdrh 478df9185cSdrh# -stats should turn it on 488df9185cSdrhdo_test shell4-1.2.1 { 498df9185cSdrh set res [catchcmd "-stats test.db" ".show"] 508df9185cSdrh list [regexp {stats: on} $res] 518df9185cSdrh} {1} 528df9185cSdrh 538df9185cSdrhdo_test shell4-1.2.2 { 548df9185cSdrh set res [catchcmd "-stats test.db" ".show"] 558df9185cSdrh list [regexp {stats: off} $res] 568df9185cSdrh} {0} 578df9185cSdrh 588df9185cSdrh# .stats ON|OFF Turn stats on or off 5934784903Sdrh#do_test shell4-1.3.1 { 6034784903Sdrh# catchcmd "test.db" ".stats" 6134784903Sdrh#} {1 {Usage: .stats on|off}} 628df9185cSdrhdo_test shell4-1.3.2 { 638df9185cSdrh catchcmd "test.db" ".stats ON" 648df9185cSdrh} {0 {}} 658df9185cSdrhdo_test shell4-1.3.3 { 668df9185cSdrh catchcmd "test.db" ".stats OFF" 678df9185cSdrh} {0 {}} 688df9185cSdrhdo_test shell4-1.3.4 { 698df9185cSdrh # too many arguments 708df9185cSdrh catchcmd "test.db" ".stats OFF BAD" 71a6e6cf2cSdrh} {1 {Usage: .stats ?on|off|stmt|vmstep?}} 728df9185cSdrh 738df9185cSdrh# NB. whitespace is important 748df9185cSdrhdo_test shell4-1.4.1 { 758df9185cSdrh set res [catchcmd "test.db" {.show}] 768df9185cSdrh list [regexp {stats: off} $res] 778df9185cSdrh} {1} 788df9185cSdrh 798df9185cSdrhdo_test shell4-1.4.2 { 808df9185cSdrh set res [catchcmd "test.db" {.stats ON 818df9185cSdrh.show 828df9185cSdrh}] 838df9185cSdrh list [regexp {stats: on} $res] 848df9185cSdrh} {1} 858df9185cSdrh 868df9185cSdrhdo_test shell4-1.4.3 { 878df9185cSdrh set res [catchcmd "test.db" {.stats OFF 888df9185cSdrh.show 898df9185cSdrh}] 908df9185cSdrh list [regexp {stats: off} $res] 918df9185cSdrh} {1} 928df9185cSdrh 938df9185cSdrh# make sure stats not present when off 948df9185cSdrhdo_test shell4-1.5.1 { 958df9185cSdrh set res [catchcmd "test.db" {SELECT 1;}] 968df9185cSdrh list [regexp {Memory Used} $res] \ 978df9185cSdrh [regexp {Heap Usage} $res] \ 988df9185cSdrh [regexp {Autoindex Inserts} $res] 998df9185cSdrh} {0 0 0} 1008df9185cSdrh 1018df9185cSdrh# make sure stats are present when on 1028df9185cSdrhdo_test shell4-1.5.2 { 1038df9185cSdrh set res [catchcmd "test.db" {.stats ON 1048df9185cSdrhSELECT 1; 1058df9185cSdrh}] 1068df9185cSdrh list [regexp {Memory Used} $res] \ 1078df9185cSdrh [regexp {Heap Usage} $res] \ 1088df9185cSdrh [regexp {Autoindex Inserts} $res] 1098df9185cSdrh} {1 1 1} 1108df9185cSdrh 111fbf6136cSdanifcapable trace { 112657b4a87Sdrhdo_test shell4-2.1 { 113707821ffSdrh catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown" 114707821ffSdrh} {1 {Unknown option "--unknown" on ".trace"}} 115657b4a87Sdrhdo_test shell4-2.2 { 116657b4a87Sdrh catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n" 117657b4a87Sdrh} {0 {}} 118657b4a87Sdrhdo_test shell4-2.3 { 119707821ffSdrh catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n" 120707821ffSdrh} {/^0 {PRAGMA.*}$/} 121657b4a87Sdrhdo_test shell4-2.4 { 122657b4a87Sdrh catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;" 123657b4a87Sdrh} {0 {CREATE TABLE t1(x); 124657b4a87SdrhSELECT * FROM t1;}} 125657b4a87Sdrhdo_test shell4-2.5 { 126657b4a87Sdrh catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;" 127657b4a87Sdrh} {0 {SELECT * FROM t1;}} 128998aaa03Sdan} 129657b4a87Sdrh 130fc8b40f2Sdrhdo_test shell4-3.1 { 131fc8b40f2Sdrh set fd [open t1.txt wb] 132fc8b40f2Sdrh puts $fd "SELECT 'squirrel';" 133fc8b40f2Sdrh close $fd 134*2f5f6740Slarrybr exec $::CLI_ONLY :memory: --interactive ".read t1.txt" 135fc8b40f2Sdrh} {squirrel} 136fc8b40f2Sdrhdo_test shell4-3.2 { 137fc8b40f2Sdrh set fd [open t1.txt wb] 138fc8b40f2Sdrh puts $fd "SELECT 'pound: \302\243';" 139fc8b40f2Sdrh close $fd 140*2f5f6740Slarrybr exec $::CLI_ONLY :memory: --interactive ".read t1.txt" 141fc8b40f2Sdrh} {pound: £} 142657b4a87Sdrh 143d48e88e5Slarrybrdo_test shell4-4.1 { 144d48e88e5Slarrybr set fd [open t1.txt wb] 145d48e88e5Slarrybr puts $fd ".read t1.txt" 146d48e88e5Slarrybr close $fd 147d48e88e5Slarrybr catchcmd ":memory:" ".read t1.txt" 148b5d44732Slarrybr} {1 {Input nesting limit (25) reached at line 1. Check recursion.}} 149d48e88e5Slarrybr 1508df9185cSdrhfinish_test 151