CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
shell9.test150 linesDownload Raw Back to test
1# 2024 Jan 82#3# The author disclaims copyright to this source code.  In place of4# 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: shell12#13# The focus of this file is testing the CLI shell tool. Specifically, 14# testing that it is possible to run a ".dump" script that creates15# virtual tables without explicitly disabling defensive mode.16#17# And, that it can process a ".dump" script that contains strings18# delimited using double-quotes in the schema (DQS_DDL setting).19#20 21# Test plan:22#23#   shell1-1.*: Basic command line option handling.24#   shell1-2.*: Basic "dot" command token parsing.25#   shell1-3.*: Basic test that "dot" command can be called.26#   shell1-{4-8}.*: Test various "dot" commands's functionality.27#   shell1-9.*: Basic test that "dot" commands and SQL intermix ok.28#29set testdir [file dirname $argv0]30source $testdir/tester.tcl31set CLI [test_cli_invocation]32 33set ::testprefix shell934 35ifcapable !fts5 {36  finish_test37  return38}39 40#----------------------------------------------------------------------------41# Test cases shell9-1.* verify that scripts output by .dump may be parsed42# by the shell tool without explicitly disabling DEFENSIVE mode, unless43# the shell is in safe mode.44#45do_execsql_test 1.0 {46  CREATE VIRTUAL TABLE t1 USING fts5(a, b, c);47  INSERT INTO t1 VALUES('one', 'two', 'three');48}49db close50 51# Create .dump file in "testdump.txt".52#53set out [open testdump.txt w]54puts $out [lindex [catchcmd test.db .dump] 1]55close $out56 57# Check testdump.txt can be processed if the initial db is empty.58#59do_test 1.1.1 {60  forcedelete test.db61  catchcmd test.db ".read testdump.txt"62} {0 {}}63sqlite3 db test.db64do_execsql_test 1.1.2 {65  SELECT * FROM t1;66} {one two three}67 68# Check testdump.txt cannot be processed if the initial db is not empty.69#70reset_db71do_execsql_test 1.2.1 {72  CREATE TABLE t4(hello);73}74db close75do_test 1.2.2 {76  catchcmd test.db ".read testdump.txt"77} {1 {Parse error near line 5: table sqlite_master may not be modified}}78 79# Check testdump.txt cannot be processed if the db is in safe mode80#81do_test 1.3.1 {82  forcedelete test.db83  catchsafecmd test.db ".read testdump.txt"84} {1 {line 1: cannot run .read in safe mode}}85do_test 1.3.2 {86  set fd [open testdump.txt]87  set script [read $fd]88  close $fd89  forcedelete test.db90  catchsafecmd test.db $script91} {1 {Parse error near line 5: table sqlite_master may not be modified}}92do_test 1.3.3 {93  # Quick check that the above would have worked but for safe mode.94  forcedelete test.db95  catchcmd test.db $script96} {0 {}}97 98#----------------------------------------------------------------------------99# Test cases shell9-2.* verify that a warning is printed at the top of100# .dump scripts that contain virtual tables.101#102proc contains_warning {text} {103  return [string match "*WARNING: Script requires that*" $text]104}105 106reset_db107do_execsql_test 2.0.1 {108  CREATE TABLE t1(x);109  CREATE TABLE t2(y);110  INSERT INTO t1 VALUES('one');111  INSERT INTO t2 VALUES('two');112}113do_test 2.0.2 {114  contains_warning [catchcmd test.db .dump]115} 0116 117do_execsql_test 2.1.1 {118  CREATE virtual TABLE r1 USING fts5(x);119}120do_test 2.1.2 {121  contains_warning [catchcmd test.db .dump]122} 1123 124do_test 2.2.1 {125  contains_warning [catchcmd test.db ".dump t1"]126} 0127do_test 2.2.2 {128  contains_warning [catchcmd test.db ".dump r1"]129} 1130 131#-------------------------------------------------------------------------132reset_db133sqlite3_db_config db DQS_DDL 1134do_execsql_test 3.1.0 {135  CREATE TABLE t4(hello, check( hello IS NOT "xyz") );136}137db close138 139# Create .dump file in "testdump.txt".140#141set out [open testdump.txt w]142puts $out [lindex [catchcmd test.db .dump] 1]143close $out144do_test 3.1.1 {145  forcedelete test.db146  catchcmd test.db ".read testdump.txt"147} {0 {}}148 149finish_test150