sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
| 1 | #!sqlite3 |
| 2 | # |
| 3 | # 2026-01-30 |
| 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 | # Miscellaneous tests for dot-commands |
| 15 | # |
| 16 | # ./sqlite3 test/dotcmd01.sql |
| 17 | # |
| 18 | .open :memory: |
| 19 | .mode -reset quote |
| 20 | .if NOT capable('vtab') |
| 21 | .testcase setup |
| 22 | .check '' |
| 23 | .exit |
| 24 | .endif |
| 25 | |
| 26 | .testcase setup |
| 27 | .open :memory: |
| 28 | .mode tty |
| 29 | .check '' |
| 30 | |
| 31 | # The ".eqp on" setting does not affect the output from .fullschema |
| 32 | # and similar. |
| 33 | # |
| 34 | .testctrl opt -Stat4 |
| 35 | .testcase 100 |
| 36 | CREATE TABLE t1(a,b,c); |
| 37 | WITH RECURSIVE c(n) AS (VALUES(1) UNION ALL SELECT n+1 FROM c WHERE n<300) |
| 38 | INSERT INTO t1(a,b,c) |
| 39 | SELECT n%10, n%30, n%100 FROM c; |
| 40 | CREATE INDEX t1a ON t1(a); |
| 41 | CREATE INDEX t1b ON t1(b); |
| 42 | ANALYZE; |
| 43 | .eqp on |
| 44 | .fullschema |
| 45 | .check <<END |
| 46 | CREATE TABLE t1(a,b,c); |
| 47 | CREATE INDEX t1a ON t1(a); |
| 48 | CREATE INDEX t1b ON t1(b); |
| 49 | ANALYZE sqlite_schema; |
| 50 | INSERT INTO sqlite_stat1 VALUES('t1','t1b','300 10'), |
| 51 | ('t1','t1a','300 30'); |
| 52 | ANALYZE sqlite_schema; |
| 53 | END |
| 54 | |
| 55 | .testcase 110 |
| 56 | .schema |
| 57 | .check <<END |
| 58 | CREATE TABLE t1(a,b,c); |
| 59 | CREATE INDEX t1a ON t1(a); |
| 60 | CREATE INDEX t1b ON t1(b); |
| 61 | CREATE TABLE sqlite_stat1(tbl,idx,stat); |
| 62 | END |
| 63 | |
| 64 | .testcase 120 |
| 65 | .tables |
| 66 | .check --glob "t1" |
| 67 | |
| 68 | .testcase 130 |
| 69 | .indexes |
| 70 | .check --glob t1a*t1b |
| 71 | |
| 72 | # The default comparison for ".check" ignores leading and trailing |
| 73 | # whitespace. Each interior whitespace character compares equal to exactly |
| 74 | # one whitespace character at the same position in the other string. A |
| 75 | # whitespace character never matches a character that is not whitespace. |
| 76 | # |
| 77 | .mode --reset list |
| 78 | .testcase 200 |
| 79 | SELECT 'a'||char(10)||'b'; |
| 80 | .check 'a b' |
| 81 | .testcase 201 |
| 82 | SELECT ' a'||char(9)||'b '||char(10); |
| 83 | .check 'a b' |
| 84 | .testcase 202 |
| 85 | SELECT 'a b'; |
| 86 | .check --not 'a b' |
| 87 | .testcase 203 |
| 88 | SELECT 'a b'; |
| 89 | .check --not 'a b' |
| 90 | .testcase 204 |
| 91 | SELECT 'a b'; |
| 92 | .check --not 'a/b' |
| 93 | .testcase 205 |
| 94 | SELECT 'a/b'; |
| 95 | .check --not 'a b' |
| 96 | .testcase 206 |
| 97 | SELECT 'ab'; |
| 98 | .check --not 'a b' |
| 99 | .testcase 207 |
| 100 | SELECT 'a b'; |
| 101 | .check --not 'ab' |
| 102 | .testcase 208 |
| 103 | SELECT 'a b'; |
| 104 | .check --not 'a b c' |
| 105 | .testcase 209 |
| 106 | SELECT 'a b c'; |
| 107 | .check --not 'a b' |
| 108 | |
| 109 | # The --glob option matches a pattern against any substring of the output. |
| 110 | # Leading and trailing whitespace on the pattern is ignored. |
| 111 | # |
| 112 | .testcase 220 |
| 113 | SELECT 'abcdefghi'; |
| 114 | .check --glob 'cde' --keep |
| 115 | .check --glob 'c?e' --keep |
| 116 | .check --glob 'a*i' --keep |
| 117 | .check --glob '[c]d' --keep |
| 118 | .check --glob ' cde ' --keep |
| 119 | .check --not --glob 'x' --keep |
| 120 | .check --notglob 'ce' |
| 121 | .testcase 221 |
| 122 | SELECT 'a b'||char(10)||'c'; |
| 123 | .check --glob 'a b' --keep |
| 124 | .check --glob 'b c' --keep |
| 125 | .check --not --glob 'a/b' |
| 126 | .testcase 222 |
| 127 | SELECT 'x -12 y'; |
| 128 | .check --glob 'x # y' --keep |
| 129 | .check --glob '# y' --keep |
| 130 | .check --not --glob 'x a y' |
| 131 | |
| 132 | # The --allglob option matches a pattern against the entire output, except |
| 133 | # for leading and trailing whitespace. |
| 134 | # |
| 135 | .testcase 230 |
| 136 | SELECT 'abcdefghi'; |
| 137 | .check --allglob 'a*i' --keep |
| 138 | .check --allglob ' abc* ' --keep |
| 139 | .check --not --allglob 'abcdefg?' --keep |
| 140 | .check --not --allglob '?bcdefgh' --keep |
| 141 | .check --not --allglob 'c*e' |
| 142 | .testcase 230a |
| 143 | SELECT 'abc'; |
| 144 | .check --allglob 'abc' --keep |
| 145 | .check --not --allglob 'ab' --keep |
| 146 | .check --not --allglob 'bc' |
| 147 | .testcase 231 |
| 148 | SELECT ' a b'||char(10)||'c '||char(10); |
| 149 | .check --allglob 'a b c' --keep |
| 150 | .check --allglob 'a b c*' --keep |
| 151 | .check --allglob 'a*c' --keep |
| 152 | .check --not --allglob 'a b' --keep |
| 153 | .check --not --allglob 'a b?' --keep |
| 154 | .check --not --allglob 'b c*' |
| 155 | .testcase 232 |
| 156 | SELECT 'x +12 y'; |
| 157 | .check --allglob 'x # y' --keep |
| 158 | .check --not --allglob 'x # z' |
| 159 | |
| 160 | # A "*" in a GLOB pattern may be followed directly by whitespace or by "#". |
| 161 | # |
| 162 | .testcase 233 |
| 163 | SELECT 'a'||char(9)||'b 12'; |
| 164 | .check --allglob 'a* b #' --keep |
| 165 | .check --allglob 'a*#' --keep |
| 166 | .check --glob 'a*b' --keep |
| 167 | .check --not --allglob 'a*#x' |
| 168 | |
| 169 | # The --nowhere option passes if the pattern is not a substring of the |
| 170 | # output. It is the same as "--not --any". |
| 171 | # |
| 172 | .testcase 240 |
| 173 | SELECT 'abcdefghi'; |
| 174 | .check --nowhere 'x' --keep |
| 175 | .check --nowhere 'ce' --keep |
| 176 | .check --not --nowhere 'cde' --keep |
| 177 | .check --not --any 'x' --keep |
| 178 | .check --any 'cde' |
| 179 | .mode --reset quote |