~ubuntu-branches/ubuntu/raring/findutils/raring

« back to all changes in this revision

Viewing changes to locate/testsuite/config/unix.exp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-05-06 11:32:24 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: james.westby@ubuntu.com-20080506113224-gy4ecmxu48tnvva4
Tags: upstream-4.4.0
ImportĀ upstreamĀ versionĀ 4.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- TCL -*-
2
2
# Test-specific TCL procedures required by DejaGNU.
3
 
# Copyright (C) 1994, 2000, 2003, 2004, 2005, 2006 
4
 
#               Free Software Foundation, Inc.
5
 
 
 
3
# Copyright (C) 1994,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
 
4
#
6
5
# This program is free software: you can redistribute it and/or modify
7
6
# it under the terms of the GNU General Public License as published by
8
7
# the Free Software Foundation, either version 3 of the License, or
9
8
# (at your option) any later version.
10
 
#
 
9
11
10
# This program is distributed in the hope that it will be useful,
12
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
13
# GNU General Public License for more details.
15
 
#
 
14
16
15
# You should have received a copy of the GNU General Public License
17
16
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
17
 
 
18
 
19
19
# Modified by David MacKenzie <djm@gnu.org> from the gcc files
20
20
# written by Rob Savoye <rob@cygnus.com>.
21
 
# Modified by James Youngman <jay@gnu.org>.
22
21
 
23
22
 
24
 
# We used to use "file normalize" here but that is not available in 
25
 
# Tcl version 8.3 (it was introduced in 8.4).   The DejaGnu utility funciton 
26
 
# 'absolute' will canonicalise directory names but not the names of 
27
 
# vanilla files. 
28
 
proc normalize { path } {
29
 
    set dir [absolute [file dirname $path] ]
30
 
    set base [file tail $path]
31
 
    return [ file join $dir $base ]
32
 
}
33
 
 
34
 
 
35
23
# use the local version of find for updatedb
36
24
#
37
25
# We normalise (normalize for those over the water) pathnames 
38
26
# because the updatedb shell script uses "cd", which means that 
39
27
# any relative paths no longer point where we thought they did.
40
 
set env(find) [normalize "../../find/find"]
 
28
# Because "file normalize" requires tcl 8.4, we have a plan B
 
29
# for normalising the name of a directory, but it is slower.
 
30
 
 
31
proc normalize_dir { dir } {
 
32
    if [ catch { file normalize $dir } result ] then {
 
33
        return [ exec /bin/sh -c "cd $dir && /bin/pwd" ]
 
34
    } else {
 
35
        return $result;
 
36
    }
 
37
}
 
38
 
 
39
set fulldir [ normalize_dir "../../find" ]
 
40
set env{find} "$fulldir/find"
41
41
 
42
42
# use the local help commands for updatedb
43
 
set env(LIBEXECDIR) [normalize .. ]
44
 
verbose "LIBEXECDIR environment variable has been set to $env(LIBEXECDIR)" 2
 
43
set env(LIBEXECDIR) [ normalize_dir .. ] 
 
44
# use our local version of find, too.
45
45
 
46
46
# do not ignore any file systems for this test
47
47
set env(PRUNEFS) ""
48
48
global UPDATEDB
49
 
# look for UPDATEDB
50
 
if ![info exists UPDATEDB] {
51
 
    set UPDATEDB [findfile $base_dir/../updatedb $base_dir/../updatedb [transform updatedb]]
52
 
    verbose "UPDATEDB defaulting to $UPDATEDB" 2
53
 
}
54
 
 
55
49
global FRCODE
56
 
# look for FRCODE
57
 
if ![info exists FRCODE] {
58
 
    set FRCODE [findfile $base_dir/../frcode $base_dir/../frcode [transform frcode]]
59
 
    verbose "FRCODE defaulting to $FRCODE" 2
60
 
}
61
 
 
62
 
# look for bigram and code
63
 
global BIGRAM
64
 
if ![info exists BIGRAM] {
65
 
    set BIGRAM [findfile $base_dir/../bigram $base_dir/../bigram [transform bigram]]
66
 
    verbose "BIGRAM defaulting to $BIGRAM" 2
67
 
}
68
 
global CODE
69
 
if ![info exists CODE] {
70
 
    set CODE [findfile $base_dir/../code $base_dir/../code [transform code]]
71
 
    verbose "CODE defaulting to $CODE" 2
 
50
global LOCATE
 
51
global FIND
 
52
 
 
53
# look for binaries
 
54
set UPDATEDB [findfile $base_dir/../updatedb     $base_dir/../updatedb     [transform updatedb]]
 
55
set FRCODE   [findfile $base_dir/../frcode       $base_dir/../frcode       [transform frcode  ]]
 
56
set LOCATE   [findfile $base_dir/../locate       $base_dir/../locate       [transform locate  ]]
 
57
set FIND     [findfile $base_dir/../../find/find $base_dir/../../find/find [transform find    ]]
 
58
verbose "UPDATEDB is $UPDATEDB" 1
 
59
verbose "FRCODE   is $FRCODE" 1
 
60
verbose "LOCATE   is $LOCATE" 1
 
61
verbose "FIND     is $FIND" 1
 
62
 
 
63
 
 
64
foreach exe "$UPDATEDB $FRCODE $LOCATE $FIND" {
 
65
    if ![ string match "/*" $exe ] {
 
66
        error "Failed to find a binary to test for $exe"
 
67
    }
72
68
}
73
69
 
74
70
global UPDATEDBFLAGS
76
72
    set UPDATEDBFLAGS ""
77
73
}
78
74
 
79
 
global LOCATE
80
 
# look for LOCATE
81
 
if ![info exists LOCATE] {
82
 
    set LOCATE [findfile $base_dir/../locate $base_dir/../locate [transform locate]]
83
 
    verbose "LOCATE defaulting to $LOCATE" 2
84
 
}
 
75
set env(find) "$FIND"
85
76
 
86
77
global LOCATEFLAGS
87
78
if ![info exists LOCATEFLAGS] then {
97
88
    global LOCATEFLAGS
98
89
 
99
90
    if {[which $LOCATE] != 0} then {
100
 
        set tmp [ eval exec $LOCATE $LOCATEFLAGS --version </dev/null ]
101
 
        regexp "version.*$" $tmp version
102
 
        if [info exists version] then {
103
 
            clone_output "[which $LOCATE] $version\n"
104
 
        } else {
105
 
            warning "cannot get version from $tmp."
106
 
        }
 
91
        set tmp [ eval exec $LOCATE $LOCATEFLAGS --version </dev/null | sed 1q]
 
92
        clone_output $tmp
107
93
    } else {
108
94
        warning "$LOCATE, program does not exist"
109
95
    }
110
96
}
111
97
 
 
98
 
 
99
# Run locate and leave the output in $comp_output.
 
100
# Called by individual test scripts.
112
101
proc locate_textonly { passfail id intext locateoptions outtext } {
113
102
    global LOCATE
114
103
    global FRCODE
115
104
 
116
 
    if {[which $LOCATE] == 0} then {
117
 
        error "$LOCATE, program does not exist"
118
 
        exit 1
119
 
    }
120
 
 
121
 
    if {[which $FRCODE] == 0} then {
122
 
        error "$FRCODE, program does not exist"
123
 
        exit 1
124
 
    }
125
 
 
126
105
    set fail_good [string match "f*" $passfail]
127
106
 
128
107
    set scriptname [uplevel {info script}]
196
175
    global UPDATEDBFLAGS
197
176
    global comp_output
198
177
 
199
 
    if {[which $UPDATEDB] == 0} then {
200
 
        error "$UPDATEDB, program does not exist"
201
 
        exit 1
202
 
    }
203
 
    if {[which $LOCATE] == 0} then {
204
 
        error "$LOCATE, program does not exist"
205
 
        exit 1
206
 
    }
207
 
 
208
178
    set fail_good [string match "f*" $passfail]
209
179
 
210
180
    set scriptname [uplevel {info script}]
230
200
    if $verbose>1 then {
231
201
        send_user "Spawning \"$updatedb_cmd\"\n"
232
202
    }
233
 
    set locate_cmd "$LOCATE $LOCATEFLAGS $locate_options < $locate_infile > locate.out"
234
 
    send_log "$locate_cmd\n"
235
 
    if $verbose>1 then {
236
 
        send_user "Spawning \"$locate_cmd\"\n"
237
 
    }
238
 
 
239
203
    catch "exec $updatedb_cmd" comp_output
 
204
 
 
205
    if {$comp_output != ""} then {
 
206
        send_log "$comp_output\n"
 
207
        if $verbose>1 then {
 
208
            send_user "$comp_output\n"
 
209
        }
 
210
        # If fail_good is set, that refers to the exit 
 
211
        # status of locate, not updatedb...
 
212
        fail "$testname: updatedb is supposed to be silent, $comp_output"
 
213
        return
 
214
    } else {
 
215
        send_log "updatedb: OK.\n"
 
216
    }
 
217
 
 
218
 
240
219
    eval $between_hook
 
220
    
 
221
    set locate_cmd "$LOCATE $LOCATEFLAGS $locate_options < $locate_infile > locate.out"
 
222
    send_log "$locate_cmd\n"
 
223
    if $verbose>1 then {
 
224
        send_user "Spawning \"$locate_cmd\"\n"
 
225
    }
 
226
 
241
227
    catch "exec $locate_cmd" comp_output
242
228
    if {$comp_output != ""} then {
243
229
        send_log "$comp_output\n"
247
233
        if $fail_good then {
248
234
            pass "$testname"
249
235
        } else {
250
 
            fail "$testname, $comp_output"
 
236
            fail "$testname: locate failed, $comp_output"
251
237
        }
252
238
        return
253
239
    }
272
258
    catch "exec rm -rf tmp"
273
259
}
274
260
 
 
261
 
 
262
 
 
263
proc locate_from_db { passfail locate_options locate_database } {
 
264
    global LOCATE
 
265
    global LOCATEFLAGS
 
266
    global verbose
 
267
 
 
268
    set fail_good [string match "f*" $passfail]
 
269
    set scriptname [uplevel {info script}]
 
270
    set testbase [file rootname $scriptname]
 
271
    set testname [file tail $testbase]
 
272
    set testdir  [file dirname $scriptname]
 
273
 
 
274
    set dbpath "$testdir/$locate_database"
 
275
    set outfile "$testbase.xo"
 
276
 
 
277
    set locate_cmd "$LOCATE $LOCATEFLAGS -d $dbpath $locate_options > locate.out"
 
278
    send_log "$locate_cmd\n"
 
279
    if $verbose>1 then {
 
280
        send_user "Spawning \"$locate_cmd\"\n"
 
281
    }
 
282
 
 
283
    catch "exec $locate_cmd 2>/dev/null" comp_output
 
284
    if {$comp_output != ""} then {
 
285
        send_log "$comp_output\n"
 
286
        if $verbose>1 then {
 
287
            send_user "$comp_output\n"
 
288
        }
 
289
        if $fail_good then {
 
290
            # XXX: in general may want to compare output, too.
 
291
            pass "$testname"
 
292
        } else {
 
293
            fail "$testname: locate unfortunately failed, $comp_output"
 
294
        }
 
295
        return
 
296
    }
 
297
 
 
298
 
 
299
    if [file exists $outfile] then {
 
300
        set cmp_cmd "cmp locate.out $outfile"
 
301
        send_log "$cmp_cmd\n"
 
302
        catch "exec $cmp_cmd" cmpout
 
303
        if {$cmpout != ""} then {
 
304
            #catch "exec diff locate.out $outfile" diffout
 
305
            #puts $diffout
 
306
            fail "$testname, $cmpout"
 
307
            return
 
308
        }
 
309
    } else {
 
310
        if {[file size locate.out] != 0} then {
 
311
            fail "$testname, output should be empty"
 
312
            return
 
313
        }
 
314
    }
 
315
    pass "$testname"
 
316
}
 
317
 
 
318
 
 
319
 
 
320
 
 
321
 
275
322
# Called by runtest.
276
323
# Clean up (remove temporary files) before runtest exits.
277
324
proc locate_exit {} {
285
332
    global UPDATEDBFLAGS
286
333
 
287
334
    if {[which $UPDATEDB] != 0} then {
288
 
        set tmp [ eval exec $UPDATEDB $UPDATEDBFLAGS --version </dev/null ]
289
 
        regexp "version.*$" $tmp version
290
 
        if [info exists version] then {
291
 
            clone_output "[which $UPDATEDB] $version\n"
292
 
        } else {
293
 
            warning "cannot get version from $tmp."
294
 
        }
 
335
        set tmp [eval exec $UPDATEDB $UPDATEDBFLAGS --version </dev/null|sed 1q]
 
336
        clone_output $tmp
295
337
    } else {
296
338
        warning "$UPDATEDB, program does not exist"
297
339
    }