~ubuntu-branches/ubuntu/trusty/dejagnu/trusty

« back to all changes in this revision

Viewing changes to lib/util-defs.exp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2006-12-11 09:06:59 UTC
  • mfrom: (2.1.6 edgy)
  • Revision ID: james.westby@ubuntu.com-20061211090659-w586kgi3giz84053
Tags: 1.4.4.cvs20060709-3
* Acknowledge previous NMUs.
* Fix permissions on /usr/share/dejagnu when building without fakeroot
  (Closes: #392589, #379809).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2
 
# 2001, 2002, 2003 Free Software Foundation, Inc.
3
 
#
4
 
# This file is part of DejaGnu.
5
 
#
6
 
# DejaGnu is free software; you can redistribute it and/or modify it
7
 
# under the terms of the GNU General Public License as published by
8
 
# the Free Software Foundation; either version 2 of the License, or
9
 
# (at your option) any later version.
10
 
#
11
 
# DejaGnu is distributed in the hope that it will be useful, but
12
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
# General Public License for more details.
15
 
#
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with DejaGnu; if not, write to the Free Software Foundation,
18
 
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
 
 
20
 
# This file was written by Rob Savoye. (rob@welcomehome.org)
21
 
 
22
 
#
23
 
# Run a utility and test the result.
24
 
#
25
 
# Parameters:
26
 
# First one is the command
27
 
# Second one is command arguments
28
 
# Third one is the file name
29
 
# Fourth one is the regexp style pattern to match for a PASS
30
 
#
31
 
# Returns:
32
 
#  1 if the test failed,
33
 
#  0 if the test passes,
34
 
# -1 if there was an internal error.
35
 
#
36
 
 
37
 
proc util_test { args } {
38
 
    global verbose
39
 
    # get the parameters
40
 
    set cmd     [lindex $args 0]
41
 
    verbose     "Utility to execute is $cmd" 2
42
 
    set cmd_arg [lindex $args 1]
43
 
    verbose     "Command line arguments are $cmd_arg" 2
44
 
    set file    [lindex $args 2]
45
 
    verbose     "The file name to use is $file" 2
46
 
    set pattern [lindex $args 3]
47
 
    verbose     "The pattern to match is \"$pattern\"" 2
48
 
 
49
 
    if [info exists file] {
50
 
        if ![string match "" $file] {
51
 
            if ![file exists $file] {
52
 
                perror "$file doesn't exist"
53
 
                return -1
54
 
            }
55
 
        }
56
 
    }
57
 
 
58
 
    # Run the utility to be tested and analyze the results.
59
 
 
60
 
    set comp_output [util_start $cmd $cmd_arg $file]
61
 
 
62
 
    verbose "Output is \"$comp_output\"" 2
63
 
    verbose "Pattern is \"$pattern\"" 2
64
 
 
65
 
    if [regexp "$pattern" $comp_output] {
66
 
        verbose "Pattern matches." 2
67
 
        return 0
68
 
    }
69
 
 
70
 
    verbose "Pattern does not match." 2
71
 
    return 1
72
 
}
73
 
 
74
 
#
75
 
# Run the utility
76
 
#
77
 
# Return NULL or the output.
78
 
#
79
 
 
80
 
proc util_start { args } {
81
 
    global verbose
82
 
    set cmd     [lindex $args 0]
83
 
    set cmd_arg [lindex $args 1]
84
 
    set file    [lindex $args 2]
85
 
 
86
 
    if {[which $cmd] == 0} {
87
 
        perror "Can't find $cmd"
88
 
        return ""
89
 
    }
90
 
 
91
 
    if { $verbose > 0 } {
92
 
        verbose "Spawning \"$cmd $cmd_arg $file\""
93
 
    } else {
94
 
        send_log "Spawning \"$cmd $cmd_arg $file\"\n"
95
 
    }
96
 
    catch "exec $cmd $cmd_arg $file" comp_output
97
 
    if ![string match "" $comp_output] {        
98
 
        send_log "$comp_output\n"
99
 
    }
100
 
    return $comp_output
101
 
}