gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/shell4.test (about)

     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  #   shell4-3.*: The ".read" command takes the shell out of interactive mode
    22  #   shell4-4.*: Input redirects cannot recurse too much
    23  #
    24  set testdir [file dirname $argv0]
    25  source $testdir/tester.tcl
    26  set CLI [test_cli_invocation]
    27  set CLI_ONLY [test_find_cli]
    28  db close
    29  forcedelete test.db test.db-journal test.db-wal
    30  sqlite3 db test.db
    31  
    32  #----------------------------------------------------------------------------
    33  # Test cases shell4-1.*: Tests specific to the "stats" command.
    34  #
    35  
    36  # should default to off
    37  do_test shell4-1.1.1 {
    38    set res [catchcmd "test.db" ".show"]
    39    list [regexp {stats: off} $res]
    40  } {1}
    41  
    42  do_test shell4-1.1.2 {
    43    set res [catchcmd "test.db" ".show"]
    44    list [regexp {stats: on} $res]
    45  } {0}
    46  
    47  # -stats should turn it on
    48  do_test shell4-1.2.1 {
    49    set res [catchcmd "-stats test.db" ".show"]
    50    list [regexp {stats: on} $res]
    51  } {1}
    52  
    53  do_test shell4-1.2.2 {
    54    set res [catchcmd "-stats test.db" ".show"]
    55    list [regexp {stats: off} $res]
    56  } {0}
    57  
    58  # .stats ON|OFF          Turn stats on or off
    59  #do_test shell4-1.3.1 {
    60  #  catchcmd "test.db" ".stats"
    61  #} {1 {Usage: .stats on|off}}
    62  do_test shell4-1.3.2 {
    63    catchcmd "test.db" ".stats ON"
    64  } {0 {}}
    65  do_test shell4-1.3.3 {
    66    catchcmd "test.db" ".stats OFF"
    67  } {0 {}}
    68  do_test shell4-1.3.4 {
    69    # too many arguments
    70    catchcmd "test.db" ".stats OFF BAD"
    71  } {1 {Usage: .stats ?on|off|stmt|vmstep?}}
    72  
    73  # NB. whitespace is important
    74  do_test shell4-1.4.1 {
    75    set res [catchcmd "test.db" {.show}]
    76    list [regexp {stats: off} $res]
    77  } {1}
    78  
    79  do_test shell4-1.4.2 {
    80    set res [catchcmd "test.db" {.stats ON
    81  .show
    82  }]
    83    list [regexp {stats: on} $res]
    84  } {1}
    85  
    86  do_test shell4-1.4.3 {
    87    set res [catchcmd "test.db" {.stats OFF
    88  .show
    89  }]
    90    list [regexp {stats: off} $res]
    91  } {1}
    92  
    93  # make sure stats not present when off
    94  do_test shell4-1.5.1 {
    95    set res [catchcmd "test.db" {SELECT 1;}]
    96    list [regexp {Memory Used} $res] \
    97         [regexp {Heap Usage} $res] \
    98         [regexp {Autoindex Inserts} $res]
    99  } {0 0 0}
   100  
   101  # make sure stats are present when on
   102  do_test shell4-1.5.2 {
   103    set res [catchcmd "test.db" {.stats ON
   104  SELECT 1;
   105  }]
   106    list [regexp {Memory Used} $res] \
   107         [regexp {Heap Usage} $res] \
   108         [regexp {Autoindex Inserts} $res]
   109  } {1 1 1}
   110  
   111  ifcapable trace {
   112  do_test shell4-2.1 {
   113    catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown"
   114  } {1 {Unknown option "--unknown" on ".trace"}}
   115  do_test shell4-2.2 {
   116    catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
   117  } {0 {}}
   118  do_test shell4-2.3 {
   119    catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n"
   120  } {/^0 {PRAGMA.*}$/}
   121  do_test shell4-2.4 {
   122    catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
   123  } {0 {CREATE TABLE t1(x);
   124  SELECT * FROM t1;}}
   125  do_test shell4-2.5 {
   126    catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
   127  } {0 {SELECT * FROM t1;}}
   128  }
   129  
   130  do_test shell4-3.1 {
   131    set fd [open t1.txt wb]
   132    puts $fd "SELECT 'squirrel';"
   133    close $fd
   134    exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
   135  } {squirrel}
   136  do_test shell4-3.2 {
   137    set fd [open t1.txt wb]
   138    puts $fd "SELECT 'pound: \302\243';"
   139    close $fd
   140    exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
   141  } {pound: £}
   142  
   143  do_test shell4-4.1 {
   144    set fd [open t1.txt wb]
   145    puts $fd ".read t1.txt"
   146    close $fd
   147    catchcmd ":memory:" ".read t1.txt"
   148  } {1 {Input nesting limit (25) reached at line 1. Check recursion.}}
   149  
   150  finish_test