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 / shell-prompt.clitest

247 lines · 5955 bytes Raw Blame History
1#!sqlite3
2#
3# 2026-04-11
4#
5# The author disclaims copyright to this source code. In place of
6# a legal notice, here is a blessing:
7#
8# May you do good and not evil.
9# May you find forgiveness for yourself and forgive others.
10# May you share freely, never taking more than you give.
11#
12#***********************************************************************
13#
14# Tests for the .prompt command and prompt rendering.
15#
16# ./sqlite3 test/shell-prompt.sql
17#
18
19.testcase setup
20.open -new test.db
21.mode list -quote off -escape ascii
22.prompt --hard-reset
23.check ''
24
25.testcase 100
26.prompt
27.check ''
28
29.testcase 110
30.prompt --show
31.check --glob <<END
32Main prompt: '*/A*/f*-> '
33Continuation: '/B*/C*-> '
34END
35.testcase 111
36.prompt 'abc> ' '123> ' -show
37.check <<END
38Main prompt: 'abc> '
39Continuation: '123> '
40END
41.testcase 112
42.prompt -- --first --second
43.prompt --show
44.check <<END
45Main prompt: '--first'
46Continuation: '--second'
47END
48.testcase 113
49.prompt --reset --show
50.check --glob <<END
51Main prompt: '*/A*/f*> '
52Continuation: '/B*/C*> '
53END
54
55.testcase 120 --error-prefix ERROR:
56.prompt show
57.check <<END
58ERROR: .prompt show
59ERROR: ^--- use quotes around the prompt string
60END
61
62.testcase 121
63.prompt 'show'
64.check ''
65.testcase 122
66.prompt --show
67.check --glob <<END
68Main prompt: 'show'
69Continuation: '/B*/C*> '
70END
71
72.testcase 130
73.prompt --reset
74.help prompt
75.check <<END
76.prompt MAIN CONTINUE Replace the standard prompts
77 --hard-reset Unset SQLITE_PS1/2 and then --reset
78 --no-color Disable color prompts. Use --color to re-enable
79 --reset Revert to default prompts
80 --show Show the current prompt strings
81 -- No more options. Subsequent args are prompts
82END
83
84.testcase 140 --error-prefix ERROR:
85.prompt --xyz
86.check <<END
87ERROR: .prompt --xyz
88ERROR: ^--- unknown option
89END
90
91
92.testcase 1000
93SELECT shell_prompt_test(NULL);
94.check --glob '*SQLite-3*test.db*-> ';
95.testcase 1001
96SELECT shell_prompt_test(NULL,'SELECT');
97.check --glob ' *;*-> ';
98.testcase 1002
99SELECT shell_prompt_test(NULL,'SELECT ((("',null,2);
100.check --glob ' *[ m]")));*-> ';
101.testcase 1003
102SELECT shell_prompt_test(NULL,'SELECT ((()[',null,2);
103.check --glob ' *[ m]]));*-> ';
104.testcase 1004
105SELECT shell_prompt_test(NULL,'SELECT ''',null,2);
106.check --glob " *[ m]';*-> ";
107.testcase 1005
108SELECT shell_prompt_test(NULL,'CREATE TRIGGER t1 BEGIN',null,2);
109.check --glob " *[ m];END;*-> ";
110.testcase 1006
111SELECT shell_prompt_test(NULL,'CREATE TRIGGER t1 BEGIN SELECT ((([',null,2);
112.check --glob " *[ m]])));END;*-> ";
113.testcase 1007
114SELECT shell_prompt_test(NULL,'CREATE TRIGGER t1 BEGIN SELECT ((/*a(((''bc',
115 null,2);
116.check --glob " *[ m][*]/));END;*-> ";
117.testcase 1008
118SELECT shell_prompt_test(NULL,'CREATE TRIGGER t1 BEGIN SELECT 1;',null,2);
119.check --glob " *[ m]END;*-> ";
120
121.testcase 2000
122.prompt 'SQLite/x-txn$/:>/; '
123SELECT shell_prompt_test(NULL);
124.check 'SQLite> ';
125.testcase 2001
126BEGIN;
127SELECT shell_prompt_test(NULL);
128.check 'SQLite-txn$ ';
129.testcase 2002
130ROLLBACK;
131SELECT shell_prompt_test(NULL);
132.check 'SQLite> ';
133.testcase 2003
134.prompt -- '--show '
135SELECT shell_prompt_test(NULL);
136.check '--show ';
137.testcase 2004
138.prompt --reset
139SELECT shell_prompt_test(NULL);
140.check --glob '*SQLite-3.# *test.db*-> ';
141
142.testcase 3000
143SELECT shell_prompt_test('(/A-/V)');
144.check --glob '(SQLite-3.#.#)'
145.testcase 3001
146SELECT shell_prompt_test('(/A-/v)');
147.check --glob '(SQLite-3.#)'
148.testcase 3002
149SELECT shell_prompt_test('(/A-/D%Y-%m-%dT%H:%M:%S/D)');
150.check --glob '(SQLite-20#-#-#T#:#:#)'
151
152.testcase 4000
153.mode list -rowsep '' -escape ascii
154SELECT shell_prompt_test('</myes/:no/;>',NULL,':memory:');
155.check <yes>
156.testcase 4001
157.mode list -rowsep '' -escape ascii
158SELECT shell_prompt_test('</myes/:no/;>',NULL,'t1.db');
159.check <no>
160
161.testcase 5000
162SELECT shell_prompt_test('abc/e[0mxyz',NULL,NULL,1);
163.check abc^A^[[0m^Bxyz
164.testcase 5001
165SELECT shell_prompt_test('abc/e[0mxyz',NULL,NULL,2);
166.check abc^[[0mxyz
167.testcase 5002
168SELECT shell_prompt_test('/e[0mxyz',NULL,NULL,1);
169.check ^A^[[0m^Bxyz
170.testcase 5003
171SELECT shell_prompt_test('abc/e[0m',NULL,NULL,1);
172.check abc^A^[[0m^B
173.testcase 5004
174SELECT shell_prompt_test('abc/e[1;32m/e[0m/e[/exyz',NULL,NULL,1);
175.check abc^A^[[1;32m^[[0m^B^[[^[xyz
176.testcase 5005
177SELECT shell_prompt_test('abc/e[1,32m/e[0m/e[/exyz',NULL,NULL,1);
178.check abc^[[1,32m^A^[[0m^B^[[^[xyz
179
180# Additional tests for octal escapes
181#
182.testcase 6000
183SELECT shell_prompt_test('/7');
184.check ^G
185.testcase 6001
186SELECT shell_prompt_test('/78');
187.check ^G8
188.testcase 6002
189SELECT shell_prompt_test('/7//');
190.check ^G/
191.testcase 6003
192SELECT shell_prompt_test('/7/');
193.check ^G
194.testcase 6004
195SELECT shell_prompt_test('/57');
196.check /
197.testcase 6005
198SELECT shell_prompt_test('/578');
199.check /8
200.testcase 6006
201SELECT shell_prompt_test('/57//');
202.check //
203.testcase 6007
204SELECT shell_prompt_test('/57/');
205.check /
206.testcase 6008
207SELECT shell_prompt_test('/10');
208.check ^H
209.testcase 6009
210SELECT shell_prompt_test('/101');
211.check A
212.testcase 6010
213SELECT shell_prompt_test('/1011');
214.check A1
215.testcase 6011
216SELECT shell_prompt_test('/33[0');
217.check ^[[0
218
219# The UNKNOWN() error is shown regardless of whether or not the
220# escape is part of an active branch.
221.testcase 6012
222SELECT shell_prompt_test('/x/z/:/y/;');
223.check 'UNKNOWN("/z")UNKNOWN("/y")'
224
225# Additional tests of \001..\002 escapes
226#
227# Two or more disconneted ANSI escapes
228#
229.testcase 7000
230SELECT shell_prompt_test('a-/e[1m-/e[0m-z',null,null,1);
231.check a-^A^[[1m^B-^A^[[0m^B-z
232
233# Empty parameter
234.testcase 7001
235SELECT shell_prompt_test('a-/e[m-z',null,null,1);
236.check a-^A^[[m^B-z
237
238# /e followed by non-[
239.testcase 7002
240SELECT shell_prompt_test('a-/eX-z',null,null,1);
241.check a-^[X-z
242.testcase 7003
243SELECT shell_prompt_test('a-/eX/e[m-z',null,null,1);
244.check a-^[X^A^[[m^B-z
245.testcase 7004
246SELECT shell_prompt_test('a-/e[m/eX-z',null,null,1);
247.check a-^A^[[m^B^[X-z