Annotation of embedaddon/sqlite3/tool/shell4.test, revision 1.1.1.1

1.1       misho       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: # $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: #
                     22: 
                     23: set CLI "./sqlite3"
                     24: 
                     25: proc do_test {name cmd expected} {
                     26:   puts -nonewline "$name ..."
                     27:   set res [uplevel $cmd]
                     28:   if {$res eq $expected} {
                     29:     puts Ok
                     30:   } else {
                     31:     puts Error
                     32:     puts "  Got: $res"
                     33:     puts "  Expected: $expected"
                     34:     exit
                     35:   }
                     36: }
                     37: 
                     38: proc catchcmd {db {cmd ""}} {
                     39:   global CLI
                     40:   set out [open cmds.txt w]
                     41:   puts $out $cmd
                     42:   close $out
                     43:   set line "exec $CLI $db < cmds.txt"
                     44:   set rc [catch { eval $line } msg]
                     45:   list $rc $msg
                     46: }
                     47: 
                     48: file delete -force test.db test.db.journal
                     49: 
                     50: #----------------------------------------------------------------------------
                     51: # Test cases shell4-1.*: Tests specific to the "stats" command.
                     52: #
                     53: 
                     54: # should default to off
                     55: do_test shell4-1.1.1 {
                     56:   set res [catchcmd "test.db" ".show"]
                     57:   list [regexp {stats: off} $res]
                     58: } {1}
                     59: 
                     60: do_test shell4-1.1.2 {
                     61:   set res [catchcmd "test.db" ".show"]
                     62:   list [regexp {stats: on} $res]
                     63: } {0}
                     64: 
                     65: # -stats should turn it on
                     66: do_test shell4-1.2.1 {
                     67:   set res [catchcmd "-stats test.db" ".show"]
                     68:   list [regexp {stats: on} $res]
                     69: } {1}
                     70: 
                     71: do_test shell4-1.2.2 {
                     72:   set res [catchcmd "-stats test.db" ".show"]
                     73:   list [regexp {stats: off} $res]
                     74: } {0}
                     75: 
                     76: # .stats ON|OFF          Turn stats on or off
                     77: do_test shell4-1.3.1 {
                     78:   catchcmd "test.db" ".stats"
                     79: } {1 {Error: unknown command or invalid arguments:  "stats". Enter ".help" for help}}
                     80: do_test shell4-1.3.2 {
                     81:   catchcmd "test.db" ".stats ON"
                     82: } {0 {}}
                     83: do_test shell4-1.3.3 {
                     84:   catchcmd "test.db" ".stats OFF"
                     85: } {0 {}}
                     86: do_test shell4-1.3.4 {
                     87:   # too many arguments
                     88:   catchcmd "test.db" ".stats OFF BAD"
                     89: } {1 {Error: unknown command or invalid arguments:  "stats". Enter ".help" for help}}
                     90: 
                     91: # NB. whitespace is important
                     92: do_test shell4-1.4.1 {
                     93:   set res [catchcmd "test.db" {.show}]
                     94:   list [regexp {stats: off} $res]
                     95: } {1}
                     96: 
                     97: do_test shell4-1.4.2 {
                     98:   set res [catchcmd "test.db" {.stats ON
                     99: .show
                    100: }]
                    101:   list [regexp {stats: on} $res]
                    102: } {1}
                    103: 
                    104: do_test shell4-1.4.3 {
                    105:   set res [catchcmd "test.db" {.stats OFF
                    106: .show
                    107: }]
                    108:   list [regexp {stats: off} $res]
                    109: } {1}
                    110: 
                    111: # make sure stats not present when off
                    112: do_test shell4-1.5.1 {
                    113:   set res [catchcmd "test.db" {SELECT 1;}]
                    114:   list [regexp {Memory Used} $res] \
                    115:        [regexp {Heap Usage} $res] \
                    116:        [regexp {Autoindex Inserts} $res]
                    117: } {0 0 0}
                    118: 
                    119: # make sure stats are present when on
                    120: do_test shell4-1.5.2 {
                    121:   set res [catchcmd "test.db" {.stats ON
                    122: SELECT 1;
                    123: }]
                    124:   list [regexp {Memory Used} $res] \
                    125:        [regexp {Heap Usage} $res] \
                    126:        [regexp {Autoindex Inserts} $res]
                    127: } {1 1 1}
                    128: 
                    129: puts "CLI tests completed successfully"

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>