1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#!/bin/bash
# Test default error messages and __ERR_MSG__
# Copyright (C) 2007 - 2016 Michael Geng <linux@MichaelGeng.de>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if test "$VERBOSE" = yes; then
set -x
fi
. test-lib.sh
echo "char *quotearg (char *s);" > quotearg.h
echo "#include <stdio.h>
char *quotearg (char *s)
{
static char rval[10];
sprintf (rval, "\"\\\"%s\\\"\"", s);
return (rval);
}" > quotearg.c
types=("long" "ulong" "intmax" "uintmax" "double")
type_names=("long int" "unsigned long int" "intmax_t" "uintmax_t" "double")
for ((i = 0; i < ${#types[*]}; i = i + 1))
do
# test default error messages
echo "a" ${types[$i]} "[1..5] \"Parameter a\"" > x.gp
$GENPARSE --language c --gnulib --outfile parse_cl x.gp >/dev/null || fail=1
gcc $CFLAGS $GNULIB_CPPFLAGS -o parse_cl parse_cl.c $GNULIB_LDFLAGS $srcdir/simple.c || fail=1
# 6 is above upper bound of 5
echo "parameter range error: a must be <= 5
Try \`parse_cl --help' for more information." > exp
parse_cl -a 6 2> out && fail=1
cmp out exp || fail=1
# 0 is below lower bound of 1
echo "parameter range error: a must be >= 1
Try \`parse_cl --help' for more information." > exp
parse_cl -a 0 2> out && fail=1
cmp out exp || fail=1
# "one" is a string, not an integer
echo "parse_cl: could not convert one to" ${type_names[$i]} > exp
parse_cl -a one 2> out && fail=1
cmp out exp || fail=1
# test error message for a range error
echo "a" ${types[$i]} "[1..5] \"Parameter a\"
__ERR_MSG__(\"%s: my error message for parameter a\")" > x.gp
$GENPARSE --language c --gnulib --outfile parse_cl x.gp >/dev/null || fail=1
gcc $CFLAGS $GNULIB_CPPFLAGS -o parse_cl parse_cl.c $GNULIB_LDFLAGS $srcdir/simple.c || fail=1
# 6 is above upper bound of 5
echo "parse_cl: 6: my error message for parameter a" > exp
parse_cl -a 6 2> out && fail=1
cmp out exp || fail=1
# 0 is below lower bound of 1
echo "parse_cl: 0: my error message for parameter a" > exp
parse_cl -a 0 2> out && fail=1
cmp out exp || fail=1
# "one" is a string, not an integer
echo "parse_cl: one: my error message for parameter a" > exp
parse_cl -a one 2> out && fail=1
cmp out exp || fail=1
# test error message with arg passed to a user defined function (quotearg)
echo "#include \"quotearg.h\"
a" ${types[$i]} "[1..5] \"Parameter a\"
__ERR_MSG__(\"%s: my error message for parameter a\", quotearg)" > x.gp
$GENPARSE --language c --gnulib --outfile parse_cl x.gp >/dev/null || fail=1
gcc $CFLAGS $GNULIB_CPPFLAGS -o parse_cl quotearg.c parse_cl.c \
$GNULIB_LDFLAGS $srcdir/simple.c || fail=1
echo "parse_cl: \"one\": my error message for parameter a" > exp
parse_cl -a one 2> out && fail=1
cmp out exp || fail=1
done
rm -f quotearg.h quotearg.c
exit $fail
|