mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-21 18:23:03 +00:00
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.
This commit is contained in:
@@ -15,7 +15,8 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# 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 of the current test.
|
||||||
number=1
|
number=1
|
||||||
@@ -24,31 +25,47 @@ number=1
|
|||||||
exit=true
|
exit=true
|
||||||
|
|
||||||
# The exercised program.
|
# 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 EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
run ()
|
run ()
|
||||||
{
|
{
|
||||||
# Effective and expected exit status.
|
# Expected exit status.
|
||||||
local sta_exp=$1
|
local sta_exp=$1
|
||||||
shift
|
shift
|
||||||
|
# Expected output.
|
||||||
local out_exp=$1
|
local out_exp=$1
|
||||||
shift
|
shift
|
||||||
$prog "$@" - <input >out_eff
|
$prog "$@" - <input >out_eff
|
||||||
|
# Effective exit status.
|
||||||
local sta_eff=$?
|
local sta_eff=$?
|
||||||
|
# Effective output.
|
||||||
local out_eff=`cat out_eff`
|
local out_eff=`cat out_eff`
|
||||||
if test $sta_eff -eq $sta_exp; then
|
if test $sta_eff -eq $sta_exp; then
|
||||||
if test "$out_eff" = "$out_exp"; then
|
if test "$out_eff" = "$out_exp"; then
|
||||||
printf "$me: PASS: %2d\n" $number
|
echo "$me: PASS: $number"
|
||||||
else
|
else
|
||||||
printf "$me: FAIL: %2d (expected output: %s, effective: %s\n" \
|
echo "$me: FAIL: $number (expected output: $out_exp, effective: $out_eff)"
|
||||||
$number "$out_exp" "$out_eff"
|
|
||||||
exit=false
|
exit=false
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
printf "$me: FAIL: %2d (expected status: %d, effective: %d\n" \
|
echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)"
|
||||||
$number $sta_exp $sta_eff
|
|
||||||
exit=false
|
exit=false
|
||||||
fi
|
fi
|
||||||
number=`expr $number + 1`
|
number=`expr $number + 1`
|
||||||
@@ -89,5 +106,4 @@ d := a + b * c
|
|||||||
EOF
|
EOF
|
||||||
run 1 ''
|
run 1 ''
|
||||||
|
|
||||||
rm input out_eff
|
|
||||||
$exit
|
$exit
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# 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 of the current test.
|
||||||
number=1
|
number=1
|
||||||
@@ -24,36 +25,53 @@ number=1
|
|||||||
exit=true
|
exit=true
|
||||||
|
|
||||||
# The exercised program.
|
# 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 EXPECTED-EXIT-STATUS EXPECTED-OUTPUT [PARSER-OPTIONS]
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
run ()
|
run ()
|
||||||
{
|
{
|
||||||
# Effective and expected exit status.
|
# Expected exit status.
|
||||||
local sta_exp=$1
|
local sta_exp=$1
|
||||||
shift
|
shift
|
||||||
|
# Expected output.
|
||||||
local out_exp=$1
|
local out_exp=$1
|
||||||
shift
|
shift
|
||||||
$prog "$@" - < input >out_eff
|
$prog "$@" - <input >out_eff
|
||||||
|
# Effective exit status.
|
||||||
local sta_eff=$?
|
local sta_eff=$?
|
||||||
|
# Effective output.
|
||||||
local out_eff=`cat out_eff`
|
local out_eff=`cat out_eff`
|
||||||
if test $sta_eff -eq $sta_exp; then
|
if test $sta_eff -eq $sta_exp; then
|
||||||
if test "$out_eff" = "$out_exp"; then
|
if test "$out_eff" = "$out_exp"; then
|
||||||
printf "$me: PASS: %2d\n" $number
|
echo "$me: PASS: $number"
|
||||||
else
|
else
|
||||||
printf "$me: FAIL: %2d (expected output: %s, effective: %s\n" \
|
echo "$me: FAIL: $number (expected output: $out_exp, effective: $out_eff)"
|
||||||
$number "$out_exp" "$out_eff"
|
|
||||||
exit=false
|
exit=false
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
printf "$me: FAIL: %2d (expected status: %d, effective: %d\n" \
|
echo "$me: FAIL: $number (expected status: $sta_exp, effective: $sta_eff)"
|
||||||
$number $sta_exp $sta_eff
|
|
||||||
exit=false
|
exit=false
|
||||||
fi
|
fi
|
||||||
number=`expr $number + 1`
|
number=`expr $number + 1`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cat >input <<EOF
|
cat >input <<EOF
|
||||||
1+2*3
|
1+2*3
|
||||||
EOF
|
EOF
|
||||||
@@ -65,6 +83,4 @@ cat >input <<EOF
|
|||||||
EOF
|
EOF
|
||||||
run 0 9
|
run 0 9
|
||||||
|
|
||||||
|
|
||||||
rm input out_eff
|
|
||||||
$exit
|
$exit
|
||||||
|
|||||||
Reference in New Issue
Block a user