Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/test/shell4.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / test / shell4.test` 153 lines · 4041 bytes Raw Blame History 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 # TESTRUNNER: shell 12 # 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 .trace 17 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 mode 23 # shell4-4.*: Input redirects cannot recurse too much 24 # 25 set testdir [file dirname $argv0] 26 source $testdir/tester.tcl 27 set CLI [test_cli_invocation] 28 set CLI_ONLY [test_find_cli] 29 db close 30 forcedelete test.db test.db-journal test.db-wal 31 sqlite3 db test.db 32 33 #---------------------------------------------------------------------------- 34 # Test cases shell4-1.*: Tests specific to the "stats" command. 35 # 36 37 # should default to off 38 do_test shell4-1.1.1 { 39 set res [catchcmd "test.db" ".show"] 40 list [regexp {stats: off} $res] 41 } {1} 42 43 do_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 on 49 do_test shell4-1.2.1 { 50 set res [catchcmd "-stats test.db" ".show"] 51 list [regexp {stats: on} $res] 52 } {1} 53 54 do_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 off 60 #do_test shell4-1.3.1 { 61 # catchcmd "test.db" ".stats" 62 #} {1 {Usage: .stats on|off}} 63 do_test shell4-1.3.2 { 64 catchcmd "test.db" ".stats ON" 65 } {0 {}} 66 do_test shell4-1.3.3 { 67 catchcmd "test.db" ".stats OFF" 68 } {0 {}} 69 70 # NB. whitespace is important 71 do_test shell4-1.4.1 { 72 set res [catchcmd "test.db" {.show}] 73 list [regexp {stats: off} $res] 74 } {1} 75 76 do_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 83 do_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 91 do_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 99 do_test shell4-1.5.2 { 100 set res [catchcmd "test.db" {.stats ON 101 SELECT 1; 102 }] 103 list [regexp {Memory Used} $res] \ 104 [regexp {Heap Usage} $res] \ 105 [regexp {Autoindex Inserts} $res] 106 } {1 1 1} 107 108 ifcapable trace { 109 do_test shell4-2.1 { 110 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown" 111 } {1 {Unknown option "--unknown" on ".trace"}} 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.dump\n.trace off\n" 117 } {/^0 {SELECT.*}$/} 118 do_test shell4-2.4 { 119 catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;" 120 } {0 {CREATE TABLE t1(x); 121 SELECT * FROM t1;}} 122 do_test shell4-2.5 { 123 catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;" 124 } {0 {SELECT * FROM t1;}} 125 do_test shell4-2.6 { 126 catchcmd ":memory:" { 127 CREATE TABLE t1(x); 128 .trace --stmt stdout 129 SELECT * FROM t1;} 130 } {0 {SELECT * FROM t1;}} 131 } 132 133 do_test shell4-3.1 { 134 set fd [open t1.txt wb] 135 puts $fd ".mode list\nSELECT 'squirrel';" 136 close $fd 137 exec $::CLI_ONLY --noinit :memory: --interactive ".read t1.txt" 138 } {squirrel} 139 do_test_with_ansi_output shell4-3.2 { 140 set fd [open t1.txt wb] 141 puts $fd ".mode list\nSELECT 'pound: \302\243';" 142 close $fd 143 exec $::CLI_ONLY --noinit :memory: --interactive ".read t1.txt" 144 } {pound: £} 145 146 do_test shell4-4.1 { 147 set fd [open t1.txt wb] 148 puts $fd ".read t1.txt" 149 close $fd 150 catchcmd ":memory:" ".read t1.txt" 151 } {1 {t1.txt: Input nesting limit (25) reached at line 1. Check recursion.}} 152 153 finish_test