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