2 # Test
-specific TCL procedures required by DejaGNU.
3 # Copyright
(C
) 1994,2003,2004,2005,2006,2007 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.
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.
, 51 Franklin Street
, Fifth Floor
, Boston
, MA
02110-1301,
21 # Modified by David MacKenzie
<djm@gnu.org
> from the gcc files
22 # written by Rob Savoye
<rob@cygnus.com
>.
25 # use the local version of find
for updatedb
27 # We normalise
(normalize
for those over the water
) pathnames
28 # because the updatedb
shell script uses
"cd", which means that
29 #
any relative paths no longer point where we thought they did.
30 # Because
"file normalize" requires tcl 8.4, we have a plan B
31 #
for normalising the
name of a directory
, but it is slower.
33 proc normalize_dir
{ dir } {
34 if [ catch
{ file normalize $
dir } result
] then {
35 return [ exec
/bin
/sh
-c
"cd $dir && /bin/pwd" ]
41 set fulldir
[ normalize_dir
"../../find" ]
42 set env
{find
} "$fulldir/find"
44 # use the local help commands
for updatedb
45 set env
(LIBEXECDIR
) [ normalize_dir ..
]
46 # use our local version of find
, too.
48 #
do not ignore
any file systems
for this test
56 set UPDATEDB
[findfile $base_dir
/..
/updatedb $base_dir
/..
/updatedb
[transform updatedb
]]
57 set FRCODE
[findfile $base_dir
/..
/frcode $base_dir
/..
/frcode
[transform frcode
]]
58 set LOCATE
[findfile $base_dir
/..
/locate $base_dir
/..
/locate
[transform locate
]]
59 set FIND
[findfile $base_dir
/..
/..
/find
/find $base_dir
/..
/..
/find
/find
[transform find
]]
60 verbose
"UPDATEDB is $UPDATEDB" 1
61 verbose
"FRCODE is $FRCODE" 1
62 verbose
"LOCATE is $LOCATE" 1
63 verbose
"FIND is $FIND" 1
66 foreach exe
"$UPDATEDB $FRCODE $LOCATE $FIND" {
67 if ![ string match
"/*" $exe ] {
68 error
"Failed to find a binary to test for $exe"
73 if ![info exists UPDATEDBFLAGS
] then {
80 if ![info exists LOCATEFLAGS
] then {
85 # Extract and print the version number of locate.
86 proc locate_version
{} {
92 if {[which $LOCATE
] != 0} then {
93 set tmp
[ eval exec $LOCATE $LOCATEFLAGS
--version
</dev
/null
]
94 regexp
"version.*$" $tmp version
95 if [info exists version
] then {
96 clone_output
"[which $LOCATE] $version\n"
98 warning
"cannot get version from $tmp."
101 warning
"$LOCATE, program does not exist"
106 # Run locate and leave the output in $comp_output.
107 # Called by individual test scripts.
108 proc locate_textonly
{ passfail id intext locateoptions outtext
} {
112 set fail_good
[string match
"f*" $passfail]
114 set scriptname
[uplevel
{info script
}]
115 set testbase
[file rootname $scriptname
]
116 set testname
[file tail $testbase
]
117 set listfile
"updatedb-paths.txt"
118 set dbfile
"locate.db"
119 set outfile "locate.out"
121 # Generate the
"frcode" input.
122 catch
{ file
delete -force $listfle
}
123 set f
[open $listfile w
]
128 exec $FRCODE
< $listfile
> $dbfile
131 set locatecmd
"$LOCATE -d $dbfile $locateoptions"
132 send_log
"Running $locatecmd \n"
133 catch
"exec $locatecmd > $outfile"
136 set f
[open
"$outfile" r]
137 while { [ gets $f line
] >= 0 } {
138 # send_log
"Output fragment is $line\n"
139 append result
"$line\n"
143 # send_log
"Output is $result\n"
145 if {[string equal $result $outtext
]} {
152 send_log
"Output mismatch.\n"
153 send_log
"Expected: $outtext\n"
154 send_log
"Got : $result\n"
160 #
Do a test in which we expect an input
text file to be preserved unchanged.
161 proc locate_roundtrip
{ id intext
} {
162 if ![regexp
"\n$" $intext] {
163 # We like the items to be terminated by newlines.
164 error
"The input text is not terminated by newline"
167 locate_textonly p $id $intext
"-r ." $intext
172 # Run locate and leave the output in $comp_output.
173 # Called by individual test scripts.
174 proc locate_start
{ passfail updatedb_options locate_options
175 {updatedb_infile
""} {locate_infile ""}
185 set fail_good
[string match
"f*" $passfail]
187 set scriptname
[uplevel
{info script
}]
188 set testbase
[file rootname $scriptname
]
189 set testname
[file tail $testbase
]
191 set outfile "$testbase.xo"
192 if {"$updatedb_infile" != ""} then {
193 set updatedb_infile
"[file dirname [file dirname $testbase]]/inputs/$updatedb_infile"
195 set updatedb_infile
/dev
/null
197 if {"$locate_infile" != ""} then {
198 set locate_infile
"[file dirname [file dirname $testbase]]/inputs/$locate_infile"
200 set locate_infile
/dev
/null
203 catch
"exec rm -f locate.out"
205 set updatedb_cmd
"$UPDATEDB $UPDATEDBFLAGS $updatedb_options < $updatedb_infile"
206 send_log
"$updatedb_cmd\n"
208 send_user
"Spawning \"$updatedb_cmd\"\n"
210 catch
"exec $updatedb_cmd" comp_output
212 if {$comp_output
!= ""} then {
213 send_log
"$comp_output\n"
215 send_user
"$comp_output\n"
217 #
If fail_good is
set, that refers to the exit
218 #
status of locate
, not updatedb...
219 fail
"$testname: updatedb is supposed to be silent, $comp_output"
222 send_log
"updatedb: OK.\n"
228 set locate_cmd
"$LOCATE $LOCATEFLAGS $locate_options < $locate_infile > locate.out"
229 send_log
"$locate_cmd\n"
231 send_user
"Spawning \"$locate_cmd\"\n"
234 catch
"exec $locate_cmd" comp_output
235 if {$comp_output
!= ""} then {
236 send_log
"$comp_output\n"
238 send_user
"$comp_output\n"
243 fail
"$testname: locate failed, $comp_output"
248 if [file
exists $
outfile] then {
249 set cmp_cmd
"cmp locate.out $outfile"
250 send_log
"$cmp_cmd\n"
251 catch
"exec $cmp_cmd" cmpout
252 if {$cmpout
!= ""} then {
253 #catch
"exec diff locate.out $outfile" diffout
255 fail
"$testname, $cmpout"
259 if {[file size locate.out
] != 0} then {
260 fail
"$testname, output should be empty"
265 catch
"exec rm -rf tmp"
269 # Clean up
(remove temporary files
) before runtest exits.
270 proc locate_exit
{} {
271 catch
"exec rm -f locate.out updatedb-paths.txt locate.db"
275 # Extract and print the version number of updatedb.
276 proc updatedb_version
{} {
280 if {[which $UPDATEDB
] != 0} then {
281 set tmp
[ eval exec $UPDATEDB $UPDATEDBFLAGS
--version
</dev
/null
]
282 regexp
"version.*$" $tmp version
283 if [info exists version
] then {
284 clone_output
"[which $UPDATEDB] $version\n"
286 warning
"cannot get version from $tmp."
289 warning
"$UPDATEDB, program does not exist"