"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #! /bin/sh
2 # runtests - Testing script for replace command
3 # (C) Richard K. Lloyd 2004
4 # Pass "1" to as a parameter to switch on verbose mode
5
6 set +u
7 passed=0
8 failed=0
9 skipped=0
10 verbose=$1
11 syntax="Zero-terminate" # String unique to -z line of replace -h
12
13 srcdir=..
14 replace=$srcdir/replace
15 if [ ! -x $replace ]
16 then
17 echo "Replace binary not detected in source tree - rebuilding..."
18 curpwd=`pwd`
19 cd $srcdir; gmake
20 cd $curpwd
21 fi
22
23 echo "Running test suite for replace"
24 if [ "$verbose" != "1" ]
25 then
26 echo
27 fi
28
29 for diff in test*.replace
30 do
31 core=./`basename $diff .replace`
32 old=$core.old
33 new=$core.new
34 tmp=$core.failed
35
36 case "$core" in
37 *004) cp $replace $old ; bintest=1 ; chmod u+x $old ;;
38 *) bintest=0 ;;
39 esac
40
41 if [ -s $new -a -s $diff ]
42 then
43 donequals=0
44 quals="" ; params=""
45 while read line
46 do
47
48 if [ $donequals -eq 0 ]
49 then
50 quals="$line" ; donequals=1
51 if [ "$verbose" = "1" ]
52 then
53 if [ "$quals" = "" ]
54 then
55 quals="-"
56 fi
57 quals="${quals}vv"
58 fi
59 else
60 oldstr="`echo \"$line\" | cut -d, -f1`"
61 newstr="`echo \"$line\" | cut -d, -f2`"
62 if [ "$params" = "" ]
63 then
64 params="'$oldstr' '$newstr'"
65 else
66 params="$params -a '$oldstr' '$newstr'"
67 fi
68 fi
69 done <$diff
70
71 if [ "$verbose" = "1" ]
72 then
73 echo
74 if [ $bintest -eq 1 ]
75 then
76 echo "Output of unchanged binary 'replace -h 2>&1 | grep $syntax' is:"
77 $old -h 2>&1 | grep $syntax 2>&1
78 else
79 echo "$core original file:"
80 cat $old
81 fi
82
83 echo
84 echo "$core replace command:"
85 echo "$replace $quals $params"
86 fi
87
88 /bin/sh -c "$replace $quals $params <$old >$tmp"
89
90 if [ $bintest -eq 1 ]
91 then
92 # 4th test actually runs a modified
93 # binary, gets its help output and
94 # saves the -z syntax line
95 chmod u+x $tmp
96 $tmp -h 2>&1 | grep "$syntax" >$tmp.new
97 mv -f $tmp.new $tmp
98 rm -f $old
99 fi
100
101 if [ "$verbose" = "1" ]
102 then
103 echo
104 if [ $bintest -eq 1 ]
105 then
106 echo "Output of modified binary 'replace -h 2>&1 | grep $syntax' is:"
107 else
108 echo "$core new file after replacements:"
109 fi
110 cat $tmp
111
112 echo
113 echo "$core pre-prepared comparison file:"
114 cat $new
115 echo
116 fi
117
118 cmp $tmp $new >/dev/null 2>&1
119 if [ $? -eq 0 ]
120 then
121 echo "$core test...PASSED"
122 let passed=$passed+1
123 rm -f $tmp
124 else
125 echo "$core test...FAILED (failed output in $tmp)"
126 let failed=$failed+1
127 fi
128 else
129 if [ "$verbose" = "1" ]
130 then
131 echo
132 fi
133 echo "$core...SKIPPED (missing files)"
134 let skipped=$skipped+1
135 fi
136 if [ "$verbose" = "1" ]
137 then
138 echo
139 fi
140 done
141
142 if [ "$verbose" != "1" ]
143 then
144 echo
145 fi
146 echo "Summary - PASSED: $passed, FAILED: $failed, SKIPPED: $skipped"
147 if [ $failed -eq 0 -a "$verbose" = "1" ]
148 then
149 echo
150 echo "replace program is confirmed to be OK and"
151 echo "can now be installed (e.g. gmake install)"
152 fi
153 exit 0