3 # Copyright (C) 2000-2005 The 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, or (at your option)
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.
16 # This program is intended to take a check.log file generated by a failed run of
17 # sanity.sh as input and run expr line by line on it. It seems a much easier
18 # way of spotting a single failed line in a 100 line test result.
22 # Contributed by Derek R. Price <derek.price@openavenue.com>
30 usage: $0 [-afh] [file...]
32 -a process alternate pattern
33 -f process first pattern (default)
36 file files to process (default = check.log)"
39 # Do a line by line match with expr
43 # $2 = pattern file name
48 # We are assuming a newline at the end of the file. The way sanity.sh
49 # uses echo to create the log message guarantees this newline and since
50 # expr ignores the last newline when the anchor is present anyhow, no
51 # information is being lost in the transition
52 while test $dcl_line -lt `wc -l <$1` -a $dcl_line -lt `wc -l <$2`; do
53 dcl_line
=`expr $dcl_line + 1`
54 if test `sed -ne${dcl_line}p <$1 |wc -c` -eq 1 \
55 -a `sed -ne${dcl_line}p <$2 |wc -c` -eq 1; then
56 # This is a workaround for what I am calling a bug in GNU
57 # expr - it won't match the empty string to the empty
58 # string. In this case the assumption is that a single
59 # character is always a newline. Since we already checked
60 # for the end of the file, we know sed will echo the
63 elif expr "`sed -ne${dcl_line}p <$1`" : \
64 "`sed -ne${dcl_line}p <$2`\$" >/dev
/null
; then
67 echo "$dcl_line: `sed -ne${dcl_line}p <$1`"
68 echo "$dcl_line: `sed -ne${dcl_line}p <$2`\$"
69 dcl_wrong
="$dcl_wrong $dcl_line"
72 if test `wc -l <$1` -ne `wc -l <$2`; then
73 echo "output & pattern contain differing number of lines"
74 elif test -z "$dcl_wrong"; then
75 echo "no mismatched lines"
77 echo "mismatched lines: $dcl_wrong"
81 # Process a single check.log file
87 # abort if we can't find any expressions
88 if grep '^\*\* got: $' <$1 >/dev
/null
; then
91 echo "WARNING: No expressions in file: $1" >&2
92 echo " Either not a check.log or sanity.sh exited for some other reason," >&2
93 echo " like bad exit status. Try tail." >&2
98 if grep '^\*\* or: $' <$1 >/dev
/null
; then
99 # file contains a second regex
100 if test $dcl_dofirst -eq 1; then
101 # get the first pattern
102 sed -ne '/^\*\* expected: $/,/^\*\* or: $/p' <$1 >/tmp
/dcle$$
103 dcl_exprfiles
="$dcl_exprfiles /tmp/dcle$$"
105 if test $dcl_doalternate -eq 1; then
106 # get the alternate pattern
107 sed -ne '/^\*\* or: $/,/^\*\* got: $/p' <$1 >/tmp
/dclo$$
108 dcl_exprfiles
="$dcl_exprfiles /tmp/dclo$$"
110 echo "WARNING: Ignoring alternate pattern in file: $1" >&2
113 # file doesn't contain a second regex
114 if test $dcl_dofirst = 1; then
115 # get the only pattern
116 sed -ne '/^\*\* expected: $/,/^\*\* got: $/p' <$1 >/tmp
/dcle$$
117 dcl_exprfiles
="$dcl_exprfiles /tmp/dcle$$"
119 if test $dcl_doalternate -eq 1; then
120 echo "WARNING: No alternate pattern in file: $1" >&2
124 # and get the actual output
125 sed -ne '/^\*\* got: $/,$p' <$1 >/tmp
/dclg$$
128 p' </tmp
/dclg$$
>/tmp
/dclh$$
129 mv /tmp
/dclh$$
/tmp
/dclg$$
131 # compare the output against each pattern requested
132 for dcl_f
in $dcl_exprfiles; do
135 p' <$dcl_f >/tmp
/dclp$$
136 mv /tmp
/dclp$$
$dcl_f
140 echo "********** $1 : Primary **********"
143 echo "********** $1 : Alternate **********"
147 expr_line_by_line
/tmp
/dclg$$
$dcl_f
164 while getopts afh arg
; do
179 # dispose of processed args
180 shift `expr $OPTIND - 1`
183 # set the default mode
184 if test $dcl_doalternate -eq 0; then
189 if test $# -eq 0; then
190 if test -f src
/check.log
&& test -r src
/check.log
; then
198 process_check_log
$file;