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 | # 2025-11-12 |
| 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 | # Test cases for the command-line shell using the newly renovated |
| 14 | # ".testcase" and ".check" commands. |
| 15 | # |
| 16 | |
| 17 | set testdir [file dirname $argv0] |
| 18 | source $testdir/tester.tcl |
| 19 | set CLI [test_cli_invocation] |
| 20 | |
| 21 | # Run an instance of the CLI on the file $name. |
| 22 | # Capture the number of test cases and the number of |
| 23 | # errors and increment the counts. |
| 24 | # |
| 25 | proc do_clitest {name args} { |
| 26 | set mapping [list <NAME> $::testdir/$name <CLI> $::CLI <ARGS> $args] |
| 27 | set script [string map $mapping { |
| 28 | catch {exec <CLI> <ARGS> :memory: <NAME> 2>@stdout} res |
| 29 | set ntest 0 |
| 30 | set nerr 999 |
| 31 | regexp {(\d+) tests? run with (\d+) errors?} $res all ntest nerr |
| 32 | set_test_counter count [expr {[set_test_counter count]+$ntest-1}] |
| 33 | set_test_counter errors [expr {[set_test_counter errors]+$nerr}] |
| 34 | if {$nerr==0} {set res "error count: 0"} |
| 35 | set res |
| 36 | }] |
| 37 | # puts $script |
| 38 | do_test shellB-$name $script {error count: 0} |
| 39 | } |
| 40 | |
| 41 | # Attempt to build a loadable extension named $ext from source |
| 42 | # file $srcfile. Return true on success. |
| 43 | # |
| 44 | proc build_loadable {ext srcfile} { |
| 45 | if {$::tcl_platform(os) eq "Windows NT"} { |
| 46 | set ext [file root $ext].dll |
| 47 | set cmd [list exec gcc -shared -fPIC -I. -I.. -o $ext $srcfile] |
| 48 | } elseif {$::tcl_platform(os) eq "Darwin"} { |
| 49 | set ext [file root $ext].dylib |
| 50 | set cmd [list exec clang -dynamiclib -I. -I.. -o $ext $srcfile] |
| 51 | } else { |
| 52 | set ext [file root $ext].so |
| 53 | set cmd [list exec gcc -shared -fPIC -I. -I.. -o $ext $srcfile] |
| 54 | } |
| 55 | if {[catch $cmd msg]} { |
| 56 | # puts "Unable to build $ext, $msg" |
| 57 | return 0 |
| 58 | } else { |
| 59 | return 1 |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | # These tests are now handled by testrunner.tcl |
| 64 | # |
| 65 | if {0} { |
| 66 | do_clitest if.sql |
| 67 | do_clitest modeA.sql |
| 68 | do_clitest dblwidth-a.sql |
| 69 | do_clitest vt100-a.sql |
| 70 | do_clitest regexp1.sql |
| 71 | do_clitest imposter1.sql |
| 72 | do_clitest sha1.sql |
| 73 | do_clitest complete_sql.sql |
| 74 | do_clitest clierrors.sql |
| 75 | do_clitest overflow1.sql |
| 76 | do_clitest fkey08.sql |
| 77 | do_clitest fkey09.sql |
| 78 | do_clitest dump.sql |
| 79 | do_clitest misc01.sql |
| 80 | do_clitest dotcmd01.sql |
| 81 | do_clitest import01.sql |
| 82 | do_clitest intck01.sql |
| 83 | do_clitest fptest01.sql |
| 84 | } |
| 85 | |
| 86 | set probe $testdir/probe.txt |
| 87 | forcedelete $probe |
| 88 | set f [open $probe wb] |
| 89 | puts -nonewline $f xyzzy |
| 90 | close $f |
| 91 | do_clitest safemode.clitest --safe |
| 92 | do_clitest shell-parse.clitest --test-parse |
| 93 | unset -nocomplain ::env(SQLITE_PS1) |
| 94 | unset -nocomplain ::env(SQLITE_PS2) |
| 95 | do_clitest shell-prompt.clitest |
| 96 | ifcapable vtab&load_ext { |
| 97 | set srcfile [file dir $testdir]/ext/misc/fossildelta.c |
| 98 | if {[build_loadable fossildelta $srcfile]} { |
| 99 | do_clitest fossildelta.clitest |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | finish_test |