Debian Codegraph @

ext/repair/test/test.tcl

raw
1 # Run this script using
2 #
3 # sqlite3_checker --test $thisscript $testscripts
4 #
5 # The $testscripts argument is optional. If omitted, all *.test files
6 # in the same directory as $thisscript are run.
7 #
8 set NTEST 0
9 set NERR 0
10
11
12 # Invoke the do_test procedure to run a single test
13 #
14 # The $expected parameter is the expected result. The result is the return
15 # value from the last TCL command in $cmd.
16 #
17 # Normally, $expected must match exactly. But if $expected is of the form
18 # "/regexp/" then regular expression matching is used. If $expected is
19 # "~/regexp/" then the regular expression must NOT match. If $expected is
20 # of the form "#/value-list/" then each term in value-list must be numeric
21 # and must approximately match the corresponding numeric term in $result.
22 # Values must match within 10%. Or if the $expected term is A..B then the
23 # $result term must be in between A and B.
24 #
25 proc do_test {name cmd expected} {
26 if {[info exists ::testprefix]} {
27 set name "$::testprefix$name"
28 }
29
30 incr ::NTEST
31 puts -nonewline $name...
32 flush stdout
33
34 if {[catch {uplevel #0 "$cmd;\n"} result]} {
35 puts -nonewline $name...
36 puts "\nError: $result"
37 incr ::NERR
38 } else {
39 set ok [expr {[string compare $result $expected]==0}]
40 if {!$ok} {
41 puts "\n! $name expected: \[$expected\]\n! $name got: \[$result\]"
42 incr ::NERR
43 } else {
44 puts " Ok"
45 }
46 }
47 flush stdout
48 }
49
50 #
51 # do_execsql_test TESTNAME SQL RES
52 #
53 proc do_execsql_test {testname sql {result {}}} {
54 uplevel [list do_test $testname [list db eval $sql] [list {*}$result]]
55 }
56
57 if {[llength $argv]==0} {
58 set dir [file dirname $argv0]
59 set argv [glob -nocomplain $dir/*.test]
60 }
61 foreach testfile $argv {
62 file delete -force test.db
63 sqlite3 db test.db
64 source $testfile
65 catch {db close}
66 }
67 puts "$NERR errors out of $NTEST tests"