1
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
2
# 2001, 2002, 2003 Free Software Foundation, Inc.
4
# This file is part of DejaGnu.
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.
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.
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.
20
# This file was written by Rob Savoye. (rob@welcomehome.org)
23
# Run a utility and test the result.
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
32
# 1 if the test failed,
33
# 0 if the test passes,
34
# -1 if there was an internal error.
37
proc util_test { args } {
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
49
if [info exists file] {
50
if ![string match "" $file] {
51
if ![file exists $file] {
52
perror "$file doesn't exist"
58
# Run the utility to be tested and analyze the results.
60
set comp_output [util_start $cmd $cmd_arg $file]
62
verbose "Output is \"$comp_output\"" 2
63
verbose "Pattern is \"$pattern\"" 2
65
if [regexp "$pattern" $comp_output] {
66
verbose "Pattern matches." 2
70
verbose "Pattern does not match." 2
77
# Return NULL or the output.
80
proc util_start { args } {
82
set cmd [lindex $args 0]
83
set cmd_arg [lindex $args 1]
84
set file [lindex $args 2]
86
if {[which $cmd] == 0} {
87
perror "Can't find $cmd"
92
verbose "Spawning \"$cmd $cmd_arg $file\""
94
send_log "Spawning \"$cmd $cmd_arg $file\"\n"
96
catch "exec $cmd $cmd_arg $file" comp_output
97
if ![string match "" $comp_output] {
98
send_log "$comp_output\n"