blob: c289a44e3d2d73479477817469c04560c43c78ea [file] [log] [blame]
drh348784e2000-05-29 20:41:49 +00001# 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#
drhbec2bf42000-05-29 23:48:22 +000026# $Id: tester.tcl,v 1.2 2000/05/29 23:48:23 drh Exp $
drh348784e2000-05-29 20:41:49 +000027
drhbec2bf42000-05-29 23:48:22 +000028# Create a test database
29#
30file delete -force testdb
31file mkdir testdb
32sqlite db testdb
33
34# Abort early if this script has been run before.
35#
36if {[info exists nTest]} return
37
38# Set the test counters to zero
39#
drh348784e2000-05-29 20:41:49 +000040set nErr 0
41set nTest 0
42
43# Invoke the do_test procedure to run a single test
44#
45proc 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#
75proc finish_test {} {
76 global nTest nErr
77 puts "$nErr errors out of $nTest tests"
78 exit $nErr
79}
80
drh348784e2000-05-29 20:41:49 +000081# A procedure to execute SQL
82#
83proc 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}