summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <demaille@gostai.com>2012-02-17 10:12:06 +0100
committerAkim Demaille <demaille@gostai.com>2012-02-17 10:20:03 +0100
commitc3a2e0e6dd060143cbd2854b61e435552883a6b7 (patch)
treebb6d3117bf501a817b9fcb638deca1c591b12eee
parentdfd31acea72eecf978f04c7e7d5f8a5e2b0110f4 (diff)
downloadbison-c3a2e0e6dd060143cbd2854b61e435552883a6b7.tar.gz
examples: fix the test suites.
* examples/calc++/test, examples/mfcalc/test (me): Be more meaningfull: include the example name. (prog): Factor. (run): Avoid printf, use echo. Add missing parens. (cleanup): New. Call it on trap. Remove the previous "rm" that did the cleanup. Move into a private directory to avoid concurrency issues. Reported by Jim Meyering.
-rwxr-xr-xexamples/calc++/test34
-rwxr-xr-xexamples/mfcalc/test38
2 files changed, 52 insertions, 20 deletions
diff --git a/examples/calc++/test b/examples/calc++/test
index 0dfe3685..7930dc21 100755
--- a/examples/calc++/test
+++ b/examples/calc++/test
@@ -15,7 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-me=`basename $0`
+me=`dirname $0`
+me=`basename $me`
# Number of the current test.
number=1
@@ -24,31 +25,47 @@ number=1
exit=true
# The exercised program.
-prog=./examples/calc++/calc++
+prog=../examples/$me/$me
+
+# cleanup
+# -------
+cleanup ()
+{
+ local status=$?
+ if test -z "$DEBUG"; then
+ cd ..
+ rm -rf $$.dir
+ fi
+ exit $status
+}
+trap cleanup 0 1 2 13 15
+mkdir $$.dir
+cd $$.dir
# run EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
# ---------------------------------------------------------
run ()
{
- # Effective and expected exit status.
+ # Expected exit status.
local sta_exp=$1
shift
+ # Expected output.
local out_exp=$1
shift
$prog "$@" - <input >out_eff
+ # Effective exit status.
local sta_eff=$?
+ # Effective output.
local out_eff=`cat out_eff`
if test $sta_eff -eq $sta_exp; then
if test "$out_eff" = "$out_exp"; then
- printf "$me: PASS: %2d\n" $number
+ echo "$me: PASS: $number"
else
- printf "$me: FAIL: %2d (expected output: %s, effective: %s\n" \
- $number "$out_exp" "$out_eff"
+ echo "$me: FAIL: $number (expected output: $out_exp, effective: $out_eff)"
exit=false
fi
else
- printf "$me: FAIL: %2d (expected status: %d, effective: %d\n" \
- $number $sta_exp $sta_eff
+ echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)"
exit=false
fi
number=`expr $number + 1`
@@ -89,5 +106,4 @@ d := a + b * c
EOF
run 1 ''
-rm input out_eff
$exit
diff --git a/examples/mfcalc/test b/examples/mfcalc/test
index edcbc14a..f848bbda 100755
--- a/examples/mfcalc/test
+++ b/examples/mfcalc/test
@@ -15,7 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-me=`basename $0`
+me=`dirname $0`
+me=`basename $me`
# Number of the current test.
number=1
@@ -24,36 +25,53 @@ number=1
exit=true
# The exercised program.
-prog=./examples/mfcalc/mfcalc
+prog=../examples/$me/$me
+
+# cleanup
+# -------
+cleanup ()
+{
+ local status=$?
+ if test -z "$DEBUG"; then
+ cd ..
+ rm -rf $$.dir
+ fi
+ exit $status
+}
+trap cleanup 0 1 2 13 15
+mkdir $$.dir
+cd $$.dir
# run EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
# ---------------------------------------------------------
run ()
{
- # Effective and expected exit status.
+ # Expected exit status.
local sta_exp=$1
shift
+ # Expected output.
local out_exp=$1
shift
- $prog "$@" - < input >out_eff
+ $prog "$@" - <input >out_eff
+ # Effective exit status.
local sta_eff=$?
+ # Effective output.
local out_eff=`cat out_eff`
if test $sta_eff -eq $sta_exp; then
if test "$out_eff" = "$out_exp"; then
- printf "$me: PASS: %2d\n" $number
+ echo "$me: PASS: $number"
else
- printf "$me: FAIL: %2d (expected output: %s, effective: %s\n" \
- $number "$out_exp" "$out_eff"
+ echo "$me: FAIL: $number (expected output: $out_exp, effective: $out_eff)"
exit=false
fi
else
- printf "$me: FAIL: %2d (expected status: %d, effective: %d\n" \
- $number $sta_exp $sta_eff
+ echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)"
exit=false
fi
number=`expr $number + 1`
}
+
cat >input <<EOF
1+2*3
EOF
@@ -65,6 +83,4 @@ cat >input <<EOF
EOF
run 0 9
-
-rm input out_eff
$exit