nmh-workers
[Top] [All Lists]

[PATCH] Make test-mhical pass with BSD yacc.

2020-09-20 03:53:52
The easiest way to match the output of either Bison or yacc is with
grep, so introduce a new test helper, check_grep, to facilitate.
---
 test/common.sh.in       | 30 ++++++++++++++++++++++++++++++
 test/mhical/test-mhical |  6 +-----
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/test/common.sh.in b/test/common.sh.in
index d3875a39..62747e36 100644
--- a/test/common.sh.in
+++ b/test/common.sh.in
@@ -239,6 +239,36 @@ check() {
     fi
 }
 
+#### check_grep() requires two arguments: first, a regular expression; second,
+#### a file to apply the regular expression against with `grep -q $1 $2`.
+#### If the file matches, the file is removed.  If different,
+#### global variable "failed" is incremented.
+#### Optional arguments:
+####   ':' <test name> -- will print '<test name>' in the failure message,
+####        to make it easier to tell which of multiple tests has failed.
+check_grep() {
+    regex="$1"; shift
+    file="$1"; shift
+    label=test
+    while [ $# -gt 0 ]; do
+        case $1 in
+           ':') shift; label=\'"$*"\'; break ;;
+            *) echo "$0: invalid check_grep() argument \"$1\" in test suite" 
&2 ;;
+        esac
+        shift
+    done
+
+    if grep -q "$regex" "$file"; then
+        rm -f "$file"
+    else
+        echo
+        echo "$0: $label failed, unmatched output in $file."
+        failed=`expr ${failed:-0} + 1`
+        #### Set return status of the function.
+        [ $failed -eq 0 ]
+    fi
+}
+
 
 #### Shortcut to enable use of valgrind:  set NMH_VALGRIND environment
 #### variable (to anything) so run_* will use valgrind.
diff --git a/test/mhical/test-mhical b/test/mhical/test-mhical
index 76813520..cad31135 100755
--- a/test/mhical/test-mhical
+++ b/test/mhical/test-mhical
@@ -955,10 +955,6 @@ At: Sun, 14 May 2017 13:00 +0000
 To: Sun, 14 May 2017 14:00
 EOF
 
-cat >"$expected_err" <<'EOF'
-mhical: syntax error, unexpected ICAL_COMMA, expecting ICAL_COLON after " this 
line is not folded"
-EOF
-
 set +e
 printf %s \
 "BEGIN:VCALENDAR
@@ -975,7 +971,7 @@ END:VEVENT
 END:VCALENDAR" | TZ=UTC mhical >"$actual" 2>"$actual_err"
 set -e
 check "$expected" "$actual"
-check "$expected_err" "$actual_err"
+check_grep 'mhical: syntax error.* " this line is not folded"' "$actual_err"
 
 
 # check null input
-- 
2.28.0



<Prev in Thread] Current Thread [Next in Thread>