2010-07-28 20:05:34 +04:00
|
|
|
# 2010 July 28
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
|
|
|
# The focus of this file is testing the CLI shell tool.
|
2010-08-18 21:16:26 +04:00
|
|
|
# These tests are specific to the .stats command.
|
2010-07-28 20:05:34 +04:00
|
|
|
#
|
2015-03-19 16:30:41 +03:00
|
|
|
# 2015-03-19: Added tests for .trace
|
2010-07-28 20:05:34 +04:00
|
|
|
|
|
|
|
# Test plan:
|
|
|
|
#
|
|
|
|
# shell4-1.*: Basic tests specific to the "stats" command.
|
2015-03-19 16:30:41 +03:00
|
|
|
# shell4-2.*: Basic tests for ".trace"
|
2016-09-07 13:10:18 +03:00
|
|
|
# shell4-3.*: The ".read" command takes the shell out of interactive mode
|
2022-01-24 09:36:16 +03:00
|
|
|
# shell4-4.*: Input redirects cannot recurse too much
|
2010-07-28 20:05:34 +04:00
|
|
|
#
|
2012-04-24 16:46:05 +04:00
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
2022-05-09 15:29:47 +03:00
|
|
|
set CLI [test_cli_invocation]
|
|
|
|
set CLI_ONLY [test_find_cli]
|
2012-04-24 16:46:05 +04:00
|
|
|
db close
|
|
|
|
forcedelete test.db test.db-journal test.db-wal
|
|
|
|
sqlite3 db test.db
|
2010-07-28 20:05:34 +04:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# Test cases shell4-1.*: Tests specific to the "stats" command.
|
|
|
|
#
|
|
|
|
|
|
|
|
# should default to off
|
|
|
|
do_test shell4-1.1.1 {
|
|
|
|
set res [catchcmd "test.db" ".show"]
|
|
|
|
list [regexp {stats: off} $res]
|
|
|
|
} {1}
|
|
|
|
|
|
|
|
do_test shell4-1.1.2 {
|
|
|
|
set res [catchcmd "test.db" ".show"]
|
|
|
|
list [regexp {stats: on} $res]
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
# -stats should turn it on
|
|
|
|
do_test shell4-1.2.1 {
|
|
|
|
set res [catchcmd "-stats test.db" ".show"]
|
|
|
|
list [regexp {stats: on} $res]
|
|
|
|
} {1}
|
|
|
|
|
|
|
|
do_test shell4-1.2.2 {
|
|
|
|
set res [catchcmd "-stats test.db" ".show"]
|
|
|
|
list [regexp {stats: off} $res]
|
|
|
|
} {0}
|
|
|
|
|
|
|
|
# .stats ON|OFF Turn stats on or off
|
2016-02-27 20:12:36 +03:00
|
|
|
#do_test shell4-1.3.1 {
|
|
|
|
# catchcmd "test.db" ".stats"
|
|
|
|
#} {1 {Usage: .stats on|off}}
|
2010-07-28 20:05:34 +04:00
|
|
|
do_test shell4-1.3.2 {
|
|
|
|
catchcmd "test.db" ".stats ON"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell4-1.3.3 {
|
|
|
|
catchcmd "test.db" ".stats OFF"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell4-1.3.4 {
|
|
|
|
# too many arguments
|
|
|
|
catchcmd "test.db" ".stats OFF BAD"
|
2021-01-09 22:10:04 +03:00
|
|
|
} {1 {Usage: .stats ?on|off|stmt|vmstep?}}
|
2010-07-28 20:05:34 +04:00
|
|
|
|
|
|
|
# NB. whitespace is important
|
|
|
|
do_test shell4-1.4.1 {
|
|
|
|
set res [catchcmd "test.db" {.show}]
|
|
|
|
list [regexp {stats: off} $res]
|
|
|
|
} {1}
|
|
|
|
|
|
|
|
do_test shell4-1.4.2 {
|
|
|
|
set res [catchcmd "test.db" {.stats ON
|
|
|
|
.show
|
|
|
|
}]
|
|
|
|
list [regexp {stats: on} $res]
|
|
|
|
} {1}
|
|
|
|
|
|
|
|
do_test shell4-1.4.3 {
|
|
|
|
set res [catchcmd "test.db" {.stats OFF
|
|
|
|
.show
|
|
|
|
}]
|
|
|
|
list [regexp {stats: off} $res]
|
|
|
|
} {1}
|
|
|
|
|
|
|
|
# make sure stats not present when off
|
|
|
|
do_test shell4-1.5.1 {
|
|
|
|
set res [catchcmd "test.db" {SELECT 1;}]
|
2010-07-28 21:16:41 +04:00
|
|
|
list [regexp {Memory Used} $res] \
|
2010-07-28 20:05:34 +04:00
|
|
|
[regexp {Heap Usage} $res] \
|
|
|
|
[regexp {Autoindex Inserts} $res]
|
|
|
|
} {0 0 0}
|
|
|
|
|
|
|
|
# make sure stats are present when on
|
|
|
|
do_test shell4-1.5.2 {
|
|
|
|
set res [catchcmd "test.db" {.stats ON
|
|
|
|
SELECT 1;
|
|
|
|
}]
|
2010-07-28 21:16:41 +04:00
|
|
|
list [regexp {Memory Used} $res] \
|
2010-07-28 20:05:34 +04:00
|
|
|
[regexp {Heap Usage} $res] \
|
|
|
|
[regexp {Autoindex Inserts} $res]
|
|
|
|
} {1 1 1}
|
|
|
|
|
2019-02-06 16:48:04 +03:00
|
|
|
ifcapable trace {
|
2015-03-19 16:30:41 +03:00
|
|
|
do_test shell4-2.1 {
|
2018-12-05 16:39:06 +03:00
|
|
|
catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace --unknown"
|
|
|
|
} {1 {Unknown option "--unknown" on ".trace"}}
|
2015-03-19 16:30:41 +03:00
|
|
|
do_test shell4-2.2 {
|
|
|
|
catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace off\n.trace off\n"
|
|
|
|
} {0 {}}
|
|
|
|
do_test shell4-2.3 {
|
2018-12-05 16:39:06 +03:00
|
|
|
catchcmd ":memory:" ".trace stdout\n.dump\n.trace off\n"
|
|
|
|
} {/^0 {PRAGMA.*}$/}
|
2015-03-19 16:30:41 +03:00
|
|
|
do_test shell4-2.4 {
|
|
|
|
catchcmd ":memory:" ".trace stdout\nCREATE TABLE t1(x);SELECT * FROM t1;"
|
|
|
|
} {0 {CREATE TABLE t1(x);
|
|
|
|
SELECT * FROM t1;}}
|
|
|
|
do_test shell4-2.5 {
|
|
|
|
catchcmd ":memory:" "CREATE TABLE t1(x);\n.trace stdout\nSELECT * FROM t1;"
|
|
|
|
} {0 {SELECT * FROM t1;}}
|
2015-03-21 15:22:51 +03:00
|
|
|
}
|
2015-03-19 16:30:41 +03:00
|
|
|
|
2016-09-07 13:10:18 +03:00
|
|
|
do_test shell4-3.1 {
|
|
|
|
set fd [open t1.txt wb]
|
|
|
|
puts $fd "SELECT 'squirrel';"
|
|
|
|
close $fd
|
2022-05-09 15:29:47 +03:00
|
|
|
exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
|
2016-09-07 13:10:18 +03:00
|
|
|
} {squirrel}
|
|
|
|
do_test shell4-3.2 {
|
|
|
|
set fd [open t1.txt wb]
|
|
|
|
puts $fd "SELECT 'pound: \302\243';"
|
|
|
|
close $fd
|
2022-05-09 15:29:47 +03:00
|
|
|
exec $::CLI_ONLY :memory: --interactive ".read t1.txt"
|
2016-09-07 13:10:18 +03:00
|
|
|
} {pound: £}
|
2015-03-19 16:30:41 +03:00
|
|
|
|
2022-01-24 09:36:16 +03:00
|
|
|
do_test shell4-4.1 {
|
|
|
|
set fd [open t1.txt wb]
|
|
|
|
puts $fd ".read t1.txt"
|
|
|
|
close $fd
|
|
|
|
catchcmd ":memory:" ".read t1.txt"
|
2022-01-24 17:01:31 +03:00
|
|
|
} {1 {Input nesting limit (25) reached at line 1. Check recursion.}}
|
2022-01-24 09:36:16 +03:00
|
|
|
|
2012-04-24 16:46:05 +04:00
|
|
|
finish_test
|