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 | # |
| 26 | # $Id: tester.tcl,v 1.1 2000/05/29 20:41:51 drh Exp $ |
| 27 | |
| 28 | set nErr 0 |
| 29 | set nTest 0 |
| 30 | |
| 31 | # Invoke the do_test procedure to run a single test |
| 32 | # |
| 33 | proc do_test {name cmd expected} { |
| 34 | global argv nErr nTest |
| 35 | if {[llength $argv]==0} { |
| 36 | set go 1 |
| 37 | } else { |
| 38 | set go 0 |
| 39 | foreach pattern $argv { |
| 40 | if {[string match $pattern $name]} { |
| 41 | set go 1 |
| 42 | break |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | if {!$go} return |
| 47 | incr nTest |
| 48 | puts -nonewline $name... |
| 49 | flush stdout |
| 50 | if {[catch {uplevel #0 "$cmd;\n"} result]} { |
| 51 | puts "\nError: $result" |
| 52 | incr nErr |
| 53 | } elseif {[string compare $result $expected]} { |
| 54 | puts "\nExpected: \[$expected\]\n Got: \[$result\]" |
| 55 | incr nErr |
| 56 | } else { |
| 57 | puts " Ok" |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | # Run this routine last |
| 62 | # |
| 63 | proc finish_test {} { |
| 64 | global nTest nErr |
| 65 | puts "$nErr errors out of $nTest tests" |
| 66 | exit $nErr |
| 67 | } |
| 68 | |
| 69 | # Create a test database |
| 70 | # |
| 71 | file delete -force testdb |
| 72 | file mkdir testdb |
| 73 | sqlite db testdb |
| 74 | |
| 75 | # A procedure to execute SQL |
| 76 | # |
| 77 | proc execsql {sql} { |
| 78 | set result {} |
| 79 | db eval $sql data { |
| 80 | foreach f [lsort [array names data]] { |
| 81 | if {$f=="*"} continue |
| 82 | lappend result $data($f) |
| 83 | } |
| 84 | } |
| 85 | return $result |
| 86 | } |