interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / shell9.test

149 lines · 3983 bytes Raw Blame History
1# 2024 Jan 8
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# TESTRUNNER: shell
12#
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 creates
15# virtual tables without explicitly disabling defensive mode.
16#
17# And, that it can process a ".dump" script that contains strings
18# 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.tcl
31set CLI [test_cli_invocation]
32
33set ::testprefix shell9
34
35ifcapable !fts5 {
36 finish_test
37 return
38}
39
40#----------------------------------------------------------------------------
41# Test cases shell9-1.* verify that scripts output by .dump may be parsed
42# by the shell tool without explicitly disabling DEFENSIVE mode, unless
43# 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 close
50
51# Create .dump file in "testdump.txt".
52#
53set out [open testdump.txt w]
54puts $out [lindex [catchcmd test.db .dump] 1]
55close $out
56
57# Check testdump.txt can be processed if the initial db is empty.
58#
59do_test 1.1.1 {
60 forcedelete test.db
61 catchcmd test.db ".read testdump.txt"
62} {0 {}}
63sqlite3 db test.db
64do_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_db
71do_execsql_test 1.2.1 {
72 CREATE TABLE t4(hello);
73}
74db close
75do_test 1.2.2 {
76 catchcmd test.db ".read testdump.txt"
77} {1 {Parse error near line 5 of testdump.txt: table sqlite_master may not be modified}}
78
79# Check testdump.txt cannot be processed if the db is in safe mode
80#
81do_test 1.3.1 {
82 forcedelete test.db
83 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 $fd
89 forcedelete test.db
90 catchsafecmd test.db $script
91} {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.db
95 catchcmd test.db $script
96} {0 {}}
97
98#----------------------------------------------------------------------------
99# Test cases shell9-2.* verify that a warning is printed at the top of
100# .dump scripts that contain virtual tables.
101#
102proc contains_warning {text} {
103 return [string match "*WARNING: Script requires that*" $text]
104}
105
106reset_db
107do_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} 0
116
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} 1
123
124do_test 2.2.1 {
125 contains_warning [catchcmd test.db ".dump t1"]
126} 0
127do_test 2.2.2 {
128 contains_warning [catchcmd test.db ".dump r1"]
129} 1
130
131#-------------------------------------------------------------------------
132reset_db
133sqlite3_db_config db DQS_DDL 1
134do_execsql_test 3.1.0 {
135 CREATE TABLE t4(hello, check( hello IS NOT "xyz") );
136}
137db close
138
139# Create .dump file in "testdump.txt".
140#
141set out [open testdump.txt w]
142puts $out [lindex [catchcmd test.db .dump] 1]
143close $out
144do_test 3.1.1 {
145 forcedelete test.db
146 catchcmd test.db ".read testdump.txt"
147} {0 {}}
148
149finish_test