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