* locate/testsuite/config/unix.exp: clean up tmp after test is
[findutils.git] / locate / testsuite / config / unix.exp
blob6ed5cc9e84597c2ad36310a7f40285b0a5e0fcb6
1 # -*- TCL -*-
2 # Test-specific TCL procedures required by DejaGNU.
3 # Copyright (C) 1994 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 # Modified by David MacKenzie <djm@gnu.ai.mit.edu> from the gcc files
20 # written by Rob Savoye <rob@cygnus.com>.
23 # use the local version of find for updatedb
24 set env(find) ../../find/find
25 # use the local help commands for updatedb
26 set env(LIBEXECDIR) ..
27 global UPDATEDB
28 # look for UPDATEDB
29 if ![info exists UPDATEDB] {
30 set UPDATEDB [findfile $base_dir/../updatedb $base_dir/../updatedb [transform updatedb]]
31 verbose "UPDATEDB defaulting to $UPDATEDB" 2
34 global UPDATEDBFLAGS
35 if ![info exists UPDATEDBFLAGS] then {
36 set UPDATEDBFLAGS ""
39 global LOCATE
40 # look for LOCATE
41 if ![info exists LOCATE] {
42 set LOCATE [findfile $base_dir/../locate $base_dir/../locate [transform locate]]
43 verbose "LOCATE defaulting to $LOCATE" 2
46 global LOCATEFLAGS
47 if ![info exists LOCATEFLAGS] then {
48 set LOCATEFLAGS ""
51 # Called by runtest.
52 # Extract and print the version number of locate.
53 proc locate_version {} {
54 global UPDATEDB
55 global UPDATEDBFLAGS
56 global LOCATE
57 global LOCATEFLAGS
59 if {[which $LOCATE] != 0} then {
60 set tmp [ eval exec $LOCATE $LOCATEFLAGS --version </dev/null ]
61 regexp "version.*$" $tmp version
62 if [info exists version] then {
63 clone_output "[which $LOCATE] $version\n"
64 } else {
65 warning "cannot get version from $tmp."
67 } else {
68 warning "$LOCATE, program does not exist"
72 # Run locate and leave the output in $comp_output.
73 # Called by individual test scripts.
74 proc locate_start { passfail updatedb_options locate_options
75 {updatedb_infile ""} {locate_infile ""}} {
76 global verbose
77 global LOCATE
78 global LOCATEFLAGS
79 global UPDATEDB
80 global UPDATEDBFLAGS
81 global comp_output
83 if {[which $UPDATEDB] == 0} then {
84 error "$UPDATEDB, program does not exist"
85 exit 1
87 if {[which $LOCATE] == 0} then {
88 error "$LOCATE, program does not exist"
89 exit 1
92 set fail_good [string match "f*" $passfail]
94 set scriptname [uplevel {info script}]
95 set testbase [file rootname $scriptname]
96 set testname [file tail $testbase]
98 set outfile "$testbase.xo"
99 if {"$updatedb_infile" != ""} then {
100 set updatedb_infile "[file dirname [file dirname $testbase]]/inputs/$updatedb_infile"
101 } else {
102 set updatedb_infile /dev/null
104 if {"$locate_infile" != ""} then {
105 set locate_infile "[file dirname [file dirname $testbase]]/inputs/$locate_infile"
106 } else {
107 set locate_infile /dev/null
110 catch "exec rm -f locate.out"
112 set updatedb_cmd "$UPDATEDB $UPDATEDBFLAGS $updatedb_options < $updatedb_infile"
113 send_log "$updatedb_cmd\n"
114 if $verbose>1 then {
115 send_user "Spawning \"$updatedb_cmd\"\n"
117 set locate_cmd "$LOCATE $LOCATEFLAGS $locate_options < $locate_infile > locate.out"
118 send_log "$locate_cmd\n"
119 if $verbose>1 then {
120 send_user "Spawning \"$locate_cmd\"\n"
123 catch "exec $updatedb_cmd" comp_output
124 catch "exec $locate_cmd" comp_output
125 if {$comp_output != ""} then {
126 send_log "$comp_output\n"
127 if $verbose>1 then {
128 send_user "$comp_output\n"
130 if $fail_good then {
131 pass "$testname"
132 } else {
133 fail "$testname, $comp_output"
135 return
138 if [file exists $outfile] then {
139 set cmp_cmd "cmp locate.out $outfile"
140 send_log "$cmp_cmd\n"
141 catch "exec $cmp_cmd" cmpout
142 if {$cmpout != ""} then {
143 fail "$testname, $cmpout"
144 return
146 } else {
147 if {[file size locate.out] != 0} then {
148 fail "$testname, output should be empty"
149 return
152 pass "$testname"
153 catch "exec rm -rf tmp"
156 # Called by runtest.
157 # Clean up (remove temporary files) before runtest exits.
158 proc locate_exit {} {
159 catch "exec rm -f locate.out"
162 # Called by runtest.
163 # Extract and print the version number of updatedb.
164 proc updatedb_version {} {
165 global UPDATEDB
166 global UPDATEDBFLAGS
168 if {[which $UPDATEDB] != 0} then {
169 set tmp [ eval exec $UPDATEDB $UPDATEDBFLAGS --version </dev/null ]
170 regexp "version.*$" $tmp version
171 if [info exists version] then {
172 clone_output "[which $UPDATEDB] $version\n"
173 } else {
174 warning "cannot get version from $tmp."
176 } else {
177 warning "$UPDATEDB, program does not exist"