sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / test / shell-prompt.clitest
| 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 |
| 32 | Main prompt: '*/A*/f*-> ' |
| 33 | Continuation: '/B*/C*-> ' |
| 34 | END |
| 35 | .testcase 111 |
| 36 | .prompt 'abc> ' '123> ' -show |
| 37 | .check <<END |
| 38 | Main prompt: 'abc> ' |
| 39 | Continuation: '123> ' |
| 40 | END |
| 41 | .testcase 112 |
| 42 | .prompt -- --first --second |
| 43 | .prompt --show |
| 44 | .check <<END |
| 45 | Main prompt: '--first' |
| 46 | Continuation: '--second' |
| 47 | END |
| 48 | .testcase 113 |
| 49 | .prompt --reset --show |
| 50 | .check --glob <<END |
| 51 | Main prompt: '*/A*/f*> ' |
| 52 | Continuation: '/B*/C*> ' |
| 53 | END |
| 54 | |
| 55 | .testcase 120 --error-prefix ERROR: |
| 56 | .prompt show |
| 57 | .check <<END |
| 58 | ERROR: .prompt show |
| 59 | ERROR: ^--- use quotes around the prompt string |
| 60 | END |
| 61 | |
| 62 | .testcase 121 |
| 63 | .prompt 'show' |
| 64 | .check '' |
| 65 | .testcase 122 |
| 66 | .prompt --show |
| 67 | .check --glob <<END |
| 68 | Main prompt: 'show' |
| 69 | Continuation: '/B*/C*> ' |
| 70 | END |
| 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 |
| 82 | END |
| 83 | |
| 84 | .testcase 140 --error-prefix ERROR: |
| 85 | .prompt --xyz |
| 86 | .check <<END |
| 87 | ERROR: .prompt --xyz |
| 88 | ERROR: ^--- unknown option |
| 89 | END |
| 90 | |
| 91 | |
| 92 | .testcase 1000 |
| 93 | SELECT shell_prompt_test(NULL); |
| 94 | .check --glob '*SQLite-3*test.db*-> '; |
| 95 | .testcase 1001 |
| 96 | SELECT shell_prompt_test(NULL,'SELECT'); |
| 97 | .check --glob ' *;*-> '; |
| 98 | .testcase 1002 |
| 99 | SELECT shell_prompt_test(NULL,'SELECT ((("',null,2); |
| 100 | .check --glob ' *[ m]")));*-> '; |
| 101 | .testcase 1003 |
| 102 | SELECT shell_prompt_test(NULL,'SELECT ((()[',null,2); |
| 103 | .check --glob ' *[ m]]));*-> '; |
| 104 | .testcase 1004 |
| 105 | SELECT shell_prompt_test(NULL,'SELECT ''',null,2); |
| 106 | .check --glob " *[ m]';*-> "; |
| 107 | .testcase 1005 |
| 108 | SELECT shell_prompt_test(NULL,'CREATE TRIGGER t1 BEGIN',null,2); |
| 109 | .check --glob " *[ m];END;*-> "; |
| 110 | .testcase 1006 |
| 111 | SELECT shell_prompt_test(NULL,'CREATE TRIGGER t1 BEGIN SELECT ((([',null,2); |
| 112 | .check --glob " *[ m]])));END;*-> "; |
| 113 | .testcase 1007 |
| 114 | SELECT shell_prompt_test(NULL,'CREATE TRIGGER t1 BEGIN SELECT ((/*a(((''bc', |
| 115 | null,2); |
| 116 | .check --glob " *[ m][*]/));END;*-> "; |
| 117 | .testcase 1008 |
| 118 | SELECT 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$/:>/; ' |
| 123 | SELECT shell_prompt_test(NULL); |
| 124 | .check 'SQLite> '; |
| 125 | .testcase 2001 |
| 126 | BEGIN; |
| 127 | SELECT shell_prompt_test(NULL); |
| 128 | .check 'SQLite-txn$ '; |
| 129 | .testcase 2002 |
| 130 | ROLLBACK; |
| 131 | SELECT shell_prompt_test(NULL); |
| 132 | .check 'SQLite> '; |
| 133 | .testcase 2003 |
| 134 | .prompt -- '--show ' |
| 135 | SELECT shell_prompt_test(NULL); |
| 136 | .check '--show '; |
| 137 | .testcase 2004 |
| 138 | .prompt --reset |
| 139 | SELECT shell_prompt_test(NULL); |
| 140 | .check --glob '*SQLite-3.# *test.db*-> '; |
| 141 | |
| 142 | .testcase 3000 |
| 143 | SELECT shell_prompt_test('(/A-/V)'); |
| 144 | .check --glob '(SQLite-3.#.#)' |
| 145 | .testcase 3001 |
| 146 | SELECT shell_prompt_test('(/A-/v)'); |
| 147 | .check --glob '(SQLite-3.#)' |
| 148 | .testcase 3002 |
| 149 | SELECT 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 |
| 154 | SELECT shell_prompt_test('</myes/:no/;>',NULL,':memory:'); |
| 155 | .check <yes> |
| 156 | .testcase 4001 |
| 157 | .mode list -rowsep '' -escape ascii |
| 158 | SELECT shell_prompt_test('</myes/:no/;>',NULL,'t1.db'); |
| 159 | .check <no> |
| 160 | |
| 161 | .testcase 5000 |
| 162 | SELECT shell_prompt_test('abc/e[0mxyz',NULL,NULL,1); |
| 163 | .check abc^A^[[0m^Bxyz |
| 164 | .testcase 5001 |
| 165 | SELECT shell_prompt_test('abc/e[0mxyz',NULL,NULL,2); |
| 166 | .check abc^[[0mxyz |
| 167 | .testcase 5002 |
| 168 | SELECT shell_prompt_test('/e[0mxyz',NULL,NULL,1); |
| 169 | .check ^A^[[0m^Bxyz |
| 170 | .testcase 5003 |
| 171 | SELECT shell_prompt_test('abc/e[0m',NULL,NULL,1); |
| 172 | .check abc^A^[[0m^B |
| 173 | .testcase 5004 |
| 174 | SELECT 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 |
| 177 | SELECT 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 |
| 183 | SELECT shell_prompt_test('/7'); |
| 184 | .check ^G |
| 185 | .testcase 6001 |
| 186 | SELECT shell_prompt_test('/78'); |
| 187 | .check ^G8 |
| 188 | .testcase 6002 |
| 189 | SELECT shell_prompt_test('/7//'); |
| 190 | .check ^G/ |
| 191 | .testcase 6003 |
| 192 | SELECT shell_prompt_test('/7/'); |
| 193 | .check ^G |
| 194 | .testcase 6004 |
| 195 | SELECT shell_prompt_test('/57'); |
| 196 | .check / |
| 197 | .testcase 6005 |
| 198 | SELECT shell_prompt_test('/578'); |
| 199 | .check /8 |
| 200 | .testcase 6006 |
| 201 | SELECT shell_prompt_test('/57//'); |
| 202 | .check // |
| 203 | .testcase 6007 |
| 204 | SELECT shell_prompt_test('/57/'); |
| 205 | .check / |
| 206 | .testcase 6008 |
| 207 | SELECT shell_prompt_test('/10'); |
| 208 | .check ^H |
| 209 | .testcase 6009 |
| 210 | SELECT shell_prompt_test('/101'); |
| 211 | .check A |
| 212 | .testcase 6010 |
| 213 | SELECT shell_prompt_test('/1011'); |
| 214 | .check A1 |
| 215 | .testcase 6011 |
| 216 | SELECT 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 |
| 222 | SELECT 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 |
| 230 | SELECT 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 |
| 235 | SELECT 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 |
| 240 | SELECT shell_prompt_test('a-/eX-z',null,null,1); |
| 241 | .check a-^[X-z |
| 242 | .testcase 7003 |
| 243 | SELECT shell_prompt_test('a-/eX/e[m-z',null,null,1); |
| 244 | .check a-^[X^A^[[m^B-z |
| 245 | .testcase 7004 |
| 246 | SELECT shell_prompt_test('a-/e[m/eX-z',null,null,1); |
| 247 | .check a-^A^[[m^B^[X-z |