bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

examples: check the errors


From: Akim Demaille
Subject: examples: check the errors
Date: Fri, 26 Oct 2018 07:42:44 +0200

commit f3110c9b9aeb58f111d977a6a6b49148efcc69af
Author: Akim Demaille <address@hidden>
Date:   Fri Oct 26 07:36:51 2018 +0200

    examples: check the errors
    
    * examples/test (run): Check stderr, unless -noerr is passed.
    * examples/calc++/calc++.test, examples/mfcalc/mfcalc.test: Check
    errors.

diff --git a/examples/calc++/calc++.test b/examples/calc++/calc++.test
index 53663846..2df28950 100755
--- a/examples/calc++/calc++.test
+++ b/examples/calc++/calc++.test
@@ -19,7 +19,8 @@ cat >input <<EOF
 toto := 1
 toto
 EOF
-run 0 1 -s
+run 0 1
+run -noerr 0 1 -s
 
 
 cat >input <<EOF
@@ -30,7 +31,7 @@ d := a + b * c
 d
 EOF
 run 0 7
-run 0 7 -p
+run -noerr 0 7 -p
 
 
 cat >input <<EOF
@@ -47,4 +48,11 @@ cat >input <<EOF
 a := 1
 d := a + b * c
 EOF
-run 1 ''
+run 1 'err: -:3.1: syntax error, unexpected end of file, expecting ( or 
identifier or number'
+
+
+cat >input <<EOF
+a := 072101108108111044032119111114108100033
+a
+EOF
+run 1 'err: -:1.6-44: integer is out of range: 
072101108108111044032119111114108100033'
diff --git a/examples/mfcalc/mfcalc.test b/examples/mfcalc/mfcalc.test
index 5dd98e71..cece94a0 100755
--- a/examples/mfcalc/mfcalc.test
+++ b/examples/mfcalc/mfcalc.test
@@ -24,4 +24,4 @@ cat >input <<EOF
 (1+2) * 3
 EOF
 run 0 9
-run 0 9 -p
+run -noerr 0 9 -p
diff --git a/examples/test b/examples/test
index e9db3d61..251307b0 100755
--- a/examples/test
+++ b/examples/test
@@ -25,7 +25,7 @@ number=1
 exit=true
 
 # top_builddir.
-cwd=`pwd`
+cwd=$(pwd)
 
 # The exercised program.
 for p in "$cwd/examples/$medir/$me" "$cwd/examples/$me"
@@ -56,10 +56,16 @@ trap cleanup 0 1 2 13 15
 mkdir $$.dir
 cd $$.dir
 
-# run EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
-# ---------------------------------------------------------
+# run [-noerr] EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
+# ------------------------------------------------------------------
+# -noerr: ignore stderr, otherwise merge it into effective output.
 run ()
 {
+  local noerr=false
+  case $1 in
+    (-noerr) noerr=true; shift;;
+  esac
+
   # Expected exit status.
   local sta_exp="$1"
   shift
@@ -68,9 +74,9 @@ run ()
   shift
   # Effective exit status.
   local sta_eff=0
-  $prog "$@" - <input >out_eff || sta_eff=$?
-  # Effective output.
-  local out_eff="`cat out_eff`"
+  $prog "$@" - <input >out_eff 2>err_eff || sta_eff=$?
+  # Combine effective output and error streams.
+  local out_eff="$(cat out_eff && $noerr || sed -e 's/^/err: /g' err_eff)"
   if test $sta_eff -eq $sta_exp; then
     if test "$out_eff" = "$out_exp"; then
       echo "$me: PASS: $number"
@@ -82,7 +88,7 @@ run ()
     echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)"
     exit=false
   fi
-  number=`expr $number + 1`
+  number=$(expr $number + 1)
 }
 
 # We have cd'd one level deeper.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]