Blob


1 #!/bin/sh
3 diff_prog="../diff/diff"
5 # At present, test015 only passes with GNU patch.
6 # Larry's patch has a bug with empty files in combination with -R...
7 if which gpatch > /dev/null; then
8 patch_prog="gpatch"
9 else
10 patch_prog="patch"
11 fi
13 diff_type=unidiff
15 rm errors
17 verify_diff_script() {
18 orig_left="$1"
19 orig_right="$2"
20 the_diff="$3"
21 expected_diff="$4"
22 diff_opts="$5"
24 if echo -- $diff_opts | grep -q -- 'w'; then
25 ignore_whitespace="true"
26 else
27 ignore_whitespace=""
28 fi
29 verify_left="verify.$orig_left"
30 verify_right="verify.$orig_right"
32 if [ -e "$expected_diff" ]; then
33 echo cmp "$got_diff" "$expected_diff"
34 if ! cmp "$got_diff" "$expected_diff" ; then
35 echo "FAIL: $got_diff != $expected_diff" | tee -a errors
36 return 1
37 fi
38 fi
39 if [ -z "$ignore_whitespace" -a "x$diff_type" = "xunidiff" ]; then
40 cp "$orig_left" "$verify_right"
41 $patch_prog --quiet -u "$verify_right" "$the_diff"
42 if ! cmp "$orig_right" "$verify_right" ; then
43 echo "FAIL: $orig_right != $verify_right" | tee -a errors
44 return 1
45 fi
47 cp "$orig_right" "$verify_left"
48 $patch_prog --quiet -u -R "$verify_left" "$the_diff"
49 if ! cmp "$orig_left" "$verify_left" ; then
50 echo "FAIL: $orig_left != $verify_left" | tee -a errors
51 return 1
52 fi
53 elif [ -z "$ignore_whitespace" ]; then
54 tail -n +3 "$the_diff" | grep -v "^+" | sed 's/^.//' > "$verify_left"
55 tail -n +3 "$the_diff" | grep -v "^-" | sed 's/^.//' > "$verify_right"
57 if ! cmp "$orig_left" "$verify_left" ; then
58 echo "FAIL: $orig_left != $verify_left" | tee -a errors
59 return 1
60 fi
61 if ! cmp "$orig_right" "$verify_right" ; then
62 echo "FAIL: $orig_right != $verify_right" | tee -a errors
63 return 1
64 fi
65 fi
66 echo "OK: $diff_prog $orig_left $orig_right"
67 return 0
68 }
70 for left in test*.left* ; do
71 right="$(echo "$left" | sed 's/\.left/\.right/')"
72 diff_opts="$(echo "$left" | sed 's/test[0-9]*\.left\([-a-zA-Z0-9]*\).txt/\1/')"
73 expected_diff="$(echo "$left" | sed 's/test\([-0-9a-zA-Z]*\)\..*/expect\1.diff/')"
74 got_diff="verify.$expected_diff"
76 "$diff_prog" $diff_opts "$left" "$right" > "$got_diff"
78 verify_diff_script "$left" "$right" "$got_diff" "$expected_diff" "$diff_opts"
79 done
81 # XXX required to keep GNU make completely silent during 'make regress'
82 if make -h 2>/dev/null | grep -q no-print-directory; then
83 make_opts="--no-print-directory"
84 fi
85 for ctest in *_test.c ; do
86 prog="$(echo "$ctest" | sed 's/.c//')"
87 expect_output="expect.${prog}"
88 prog_output="verify.$expect_output"
89 make $make_opts -s -C "$prog" regress > "$prog_output"
90 if ! cmp "$prog_output" "$expect_output" ; then
91 echo "FAIL: $prog_output != $expect_output" | tee -a errors
92 else
93 echo "OK: $prog"
94 fi
95 done
97 echo
98 if [ -f errors ]; then
99 echo "Tests failed:"
100 cat errors
101 exit 1
102 else
103 echo "All tests OK"
104 echo
105 fi