CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
shell4.test158 linesDownload Raw Back to test
1# 2010 July 282#3# The author disclaims copyright to this source code.  In place of4# 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# TESTRUNNER: shell12#13# The focus of this file is testing the CLI shell tool.14# These tests are specific to the .stats command.15#16# 2015-03-19:  Added tests for .trace17 18# Test plan:19#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 mode23#   shell4-4.*: Input redirects cannot recurse too much24#25set testdir [file dirname $argv0]26source $testdir/tester.tcl27set CLI [test_cli_invocation]28set CLI_ONLY [test_find_cli]29db close30forcedelete test.db test.db-journal test.db-wal31sqlite3 db test.db32 33#----------------------------------------------------------------------------34# Test cases shell4-1.*: Tests specific to the "stats" command.35#36 37# should default to off38do_test shell4-1.1.1 {39  set res [catchcmd "test.db" ".show"]40  list [regexp {stats: off} $res]41} {1}42 43do_test shell4-1.1.2 {44  set res [catchcmd "test.db" ".show"]45  list [regexp {stats: on} $res]46} {0}47 48# -stats should turn it on49do_test shell4-1.2.1 {50  set res [catchcmd "-stats test.db" ".show"]51  list [regexp {stats: on} $res]52} {1}53 54do_test shell4-1.2.2 {55  set res [catchcmd "-stats test.db" ".show"]56  list [regexp {stats: off} $res]57} {0}58 59# .stats ON|OFF          Turn stats on or off60#do_test shell4-1.3.1 {61#  catchcmd "test.db" ".stats"62#} {1 {Usage: .stats on|off}}63do_test shell4-1.3.2 {64  catchcmd "test.db" ".stats ON"65} {0 {}}66do_test shell4-1.3.3 {67  catchcmd "test.db" ".stats OFF"68} {0 {}}69do_test shell4-1.3.4 {70  # too many arguments71  catchcmd "test.db" ".stats OFF BAD"72} {1 {Usage: .stats ?on|off|stmt|vmstep?}}73 74# NB. whitespace is important75do_test shell4-1.4.1 {76  set res [catchcmd "test.db" {.show}]77  list [regexp {stats: off} $res]78} {1}79 80do_test shell4-1.4.2 {81  set res [catchcmd "test.db" {.stats ON82.show83}]84  list [regexp {stats: on} $res]85} {1}86 87do_test shell4-1.4.3 {88  set res [catchcmd "test.db" {.stats OFF89.show90}]91  list [regexp {stats: off} $res]92} {1}93 94# make sure stats not present when off95do_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}101 102# make sure stats are present when on103do_test shell4-1.5.2 {104  set res [catchcmd "test.db" {.stats ON105SELECT 1;106}]107  list [regexp {Memory Used} $res] \108       [regexp {Heap Usage} $res] \109       [regexp {Autoindex Inserts} $res]110} {1 1 1}111 112ifcapable trace {113do_test shell4-2.1 {114  catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown"115} {1 {Unknown option "--unknown" on ".trace"}}116do_test shell4-2.2 {117  catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"118} {0 {}}119do_test shell4-2.3 {120  catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n"121} {/^0 {SELECT.*}$/}122do_test shell4-2.4 {123  catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"124} {0 {CREATE TABLE t1(x);125SELECT * FROM t1;}}126do_test shell4-2.5 {127  catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"128} {0 {SELECT * FROM t1;}}129do_test shell4-2.6 {130  catchcmd ":memory:" {131CREATE TABLE t1(x);132.trace --stmt stdout133SELECT * FROM t1;}134} {0 {SELECT * FROM t1;}}135}136 137do_test shell4-3.1 {138  set fd [open t1.txt wb]139  puts $fd ".mode list\nSELECT 'squirrel';"140  close $fd141  exec $::CLI_ONLY --noinit :memory: --interactive ".read t1.txt"142} {squirrel}143do_test_with_ansi_output shell4-3.2 {144  set fd [open t1.txt wb]145  puts $fd ".mode list\nSELECT 'pound: \302\243';"146  close $fd147  exec $::CLI_ONLY --noinit :memory: --interactive ".read t1.txt"148} {pound: £}149 150do_test shell4-4.1 {151  set fd [open t1.txt wb]152  puts $fd ".read t1.txt"153  close $fd154  catchcmd ":memory:" ".read t1.txt"155} {1 {t1.txt: Input nesting limit (25) reached at line 1. Check recursion.}}156 157finish_test158