drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 1 | # Copyright (c) 1999, 2000 D. Richard Hipp |
| 2 | # |
| 3 | # This program is free software; you can redistribute it and/or |
| 4 | # modify it under the terms of the GNU General Public |
| 5 | # License as published by the Free Software Foundation; either |
| 6 | # version 2 of the License, or (at your option) any later version. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | # General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public |
| 14 | # License along with this library; if not, write to the |
| 15 | # Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | # Boston, MA 02111-1307, USA. |
| 17 | # |
| 18 | # Author contact information: |
| 19 | # drh@hwaci.com |
| 20 | # http://www.hwaci.com/drh/ |
| 21 | # |
| 22 | #*********************************************************************** |
| 23 | # This file implements some common TCL routines used for regression |
| 24 | # testing the SQLite library |
| 25 | # |
drh | bec2bf4 | 2000-05-29 23:48:22 +0000 | [diff] [blame^] | 26 | # $Id: tester.tcl,v 1.2 2000/05/29 23:48:23 drh Exp $ |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 27 | |
drh | bec2bf4 | 2000-05-29 23:48:22 +0000 | [diff] [blame^] | 28 | # Create a test database |
| 29 | # |
| 30 | file delete -force testdb |
| 31 | file mkdir testdb |
| 32 | sqlite db testdb |
| 33 | |
| 34 | # Abort early if this script has been run before. |
| 35 | # |
| 36 | if {[info exists nTest]} return |
| 37 | |
| 38 | # Set the test counters to zero |
| 39 | # |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 40 | set nErr 0 |
| 41 | set nTest 0 |
| 42 | |
| 43 | # Invoke the do_test procedure to run a single test |
| 44 | # |
| 45 | proc do_test {name cmd expected} { |
| 46 | global argv nErr nTest |
| 47 | if {[llength $argv]==0} { |
| 48 | set go 1 |
| 49 | } else { |
| 50 | set go 0 |
| 51 | foreach pattern $argv { |
| 52 | if {[string match $pattern $name]} { |
| 53 | set go 1 |
| 54 | break |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | if {!$go} return |
| 59 | incr nTest |
| 60 | puts -nonewline $name... |
| 61 | flush stdout |
| 62 | if {[catch {uplevel #0 "$cmd;\n"} result]} { |
| 63 | puts "\nError: $result" |
| 64 | incr nErr |
| 65 | } elseif {[string compare $result $expected]} { |
| 66 | puts "\nExpected: \[$expected\]\n Got: \[$result\]" |
| 67 | incr nErr |
| 68 | } else { |
| 69 | puts " Ok" |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | # Run this routine last |
| 74 | # |
| 75 | proc finish_test {} { |
| 76 | global nTest nErr |
| 77 | puts "$nErr errors out of $nTest tests" |
| 78 | exit $nErr |
| 79 | } |
| 80 | |
drh | 348784e | 2000-05-29 20:41:49 +0000 | [diff] [blame] | 81 | # A procedure to execute SQL |
| 82 | # |
| 83 | proc execsql {sql} { |
| 84 | set result {} |
| 85 | db eval $sql data { |
| 86 | foreach f [lsort [array names data]] { |
| 87 | if {$f=="*"} continue |
| 88 | lappend result $data($f) |
| 89 | } |
| 90 | } |
| 91 | return $result |
| 92 | } |