shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 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. |
shaneh | 1b8f78c | 2010-08-18 17:16:26 +0000 | [diff] [blame] | 13 | # These tests are specific to the .stats command. |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 14 | # |
| 15 | # $Id: shell4.test,v 1.7 2009/07/17 16:54:48 shaneh Exp $ |
| 16 | # |
| 17 | |
| 18 | # Test plan: |
| 19 | # |
| 20 | # shell4-1.*: Basic tests specific to the "stats" command. |
| 21 | # |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 22 | set testdir [file dirname $argv0] |
| 23 | source $testdir/tester.tcl |
| 24 | if {$tcl_platform(platform)=="windows"} { |
| 25 | set CLI "sqlite3.exe" |
| 26 | } else { |
| 27 | set CLI "./sqlite3" |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 28 | } |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 29 | if {![file executable $CLI]} { |
| 30 | finish_test |
| 31 | return |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 32 | } |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 33 | db close |
| 34 | forcedelete test.db test.db-journal test.db-wal |
| 35 | sqlite3 db test.db |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 36 | |
| 37 | #---------------------------------------------------------------------------- |
| 38 | # Test cases shell4-1.*: Tests specific to the "stats" command. |
| 39 | # |
| 40 | |
| 41 | # should default to off |
| 42 | do_test shell4-1.1.1 { |
| 43 | set res [catchcmd "test.db" ".show"] |
| 44 | list [regexp {stats: off} $res] |
| 45 | } {1} |
| 46 | |
| 47 | do_test shell4-1.1.2 { |
| 48 | set res [catchcmd "test.db" ".show"] |
| 49 | list [regexp {stats: on} $res] |
| 50 | } {0} |
| 51 | |
| 52 | # -stats should turn it on |
| 53 | do_test shell4-1.2.1 { |
| 54 | set res [catchcmd "-stats test.db" ".show"] |
| 55 | list [regexp {stats: on} $res] |
| 56 | } {1} |
| 57 | |
| 58 | do_test shell4-1.2.2 { |
| 59 | set res [catchcmd "-stats test.db" ".show"] |
| 60 | list [regexp {stats: off} $res] |
| 61 | } {0} |
| 62 | |
| 63 | # .stats ON|OFF Turn stats on or off |
| 64 | do_test shell4-1.3.1 { |
| 65 | catchcmd "test.db" ".stats" |
| 66 | } {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}} |
| 67 | do_test shell4-1.3.2 { |
| 68 | catchcmd "test.db" ".stats ON" |
| 69 | } {0 {}} |
| 70 | do_test shell4-1.3.3 { |
| 71 | catchcmd "test.db" ".stats OFF" |
| 72 | } {0 {}} |
| 73 | do_test shell4-1.3.4 { |
| 74 | # too many arguments |
| 75 | catchcmd "test.db" ".stats OFF BAD" |
| 76 | } {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}} |
| 77 | |
| 78 | # NB. whitespace is important |
| 79 | do_test shell4-1.4.1 { |
| 80 | set res [catchcmd "test.db" {.show}] |
| 81 | list [regexp {stats: off} $res] |
| 82 | } {1} |
| 83 | |
| 84 | do_test shell4-1.4.2 { |
| 85 | set res [catchcmd "test.db" {.stats ON |
| 86 | .show |
| 87 | }] |
| 88 | list [regexp {stats: on} $res] |
| 89 | } {1} |
| 90 | |
| 91 | do_test shell4-1.4.3 { |
| 92 | set res [catchcmd "test.db" {.stats OFF |
| 93 | .show |
| 94 | }] |
| 95 | list [regexp {stats: off} $res] |
| 96 | } {1} |
| 97 | |
| 98 | # make sure stats not present when off |
| 99 | do_test shell4-1.5.1 { |
| 100 | set res [catchcmd "test.db" {SELECT 1;}] |
drh | abc97a7 | 2010-07-28 17:16:41 +0000 | [diff] [blame] | 101 | list [regexp {Memory Used} $res] \ |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 102 | [regexp {Heap Usage} $res] \ |
| 103 | [regexp {Autoindex Inserts} $res] |
| 104 | } {0 0 0} |
| 105 | |
| 106 | # make sure stats are present when on |
| 107 | do_test shell4-1.5.2 { |
| 108 | set res [catchcmd "test.db" {.stats ON |
| 109 | SELECT 1; |
| 110 | }] |
drh | abc97a7 | 2010-07-28 17:16:41 +0000 | [diff] [blame] | 111 | list [regexp {Memory Used} $res] \ |
shaneh | 642d8b8 | 2010-07-28 16:05:34 +0000 | [diff] [blame] | 112 | [regexp {Heap Usage} $res] \ |
| 113 | [regexp {Autoindex Inserts} $res] |
| 114 | } {1 1 1} |
| 115 | |
drh | 8df9185 | 2012-04-24 12:46:05 +0000 | [diff] [blame] | 116 | finish_test |