114 lines
3.6 KiB
Bash
Executable file
114 lines
3.6 KiB
Bash
Executable file
#! /bin/sh
|
|
# check script for Arg_parser - POSIX/GNU command-line argument parser.
|
|
# Copyright (C) 2011-2026 Antonio Diaz Diaz.
|
|
#
|
|
# This script is free software: you have unlimited permission
|
|
# to copy, distribute, and modify it.
|
|
|
|
LC_ALL=C
|
|
export LC_ALL
|
|
objdir=`pwd`
|
|
testdir=`cd "$1" ; pwd`
|
|
PARSER="${objdir}"/arg_parser
|
|
CPARSER="${objdir}"/carg_parser
|
|
framework_failure() { echo "failure in testing framework" ; exit 1 ; }
|
|
|
|
if [ ! -f "${PARSER}" ] || [ ! -x "${PARSER}" ] ; then
|
|
echo "${PARSER}: cannot execute"
|
|
exit 1
|
|
fi
|
|
if [ ! -f "${CPARSER}" ] || [ ! -x "${CPARSER}" ] ; then
|
|
echo "${CPARSER}: cannot execute"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -d tmp ] ; then rm -rf tmp ; fi
|
|
mkdir tmp
|
|
cd "${objdir}"/tmp || framework_failure
|
|
|
|
fail=0
|
|
test_failed() { fail=1 ; printf "\n$1" ; [ -z "$2" ] || printf "($2)" ; }
|
|
|
|
printf "testing arg_parser-%s..." "$2"
|
|
|
|
for i in "${PARSER}" "${CPARSER}" ; do
|
|
"$i" -h > /dev/null || test_failed $LINENO "$i"
|
|
"$i" --help > /dev/null || test_failed $LINENO "$i"
|
|
"$i" -V > /dev/null || test_failed $LINENO "$i"
|
|
"$i" --version > /dev/null || test_failed $LINENO "$i"
|
|
"$i" -h -v > /dev/null || test_failed $LINENO "$i"
|
|
"$i" -v -h > /dev/null || test_failed $LINENO "$i"
|
|
|
|
"$i" --append -a -b 5 --block 10 -c -carg --casual= --casual=arg -e "" -1 \
|
|
-earg --empty= --empty=arg -H -o file --l -v --verbose -.5 -3.14 -inf \
|
|
-Inf -INF file1 file2 > out || test_failed $LINENO "$i"
|
|
cmp "${testdir}"/test1.txt out || test_failed $LINENO "$i"
|
|
|
|
"$i" -1 -.5 file1 -3.14 -inf file2 --appen -ab5 --bloc=10 -c -carg --casu \
|
|
--casu=arg -e "" -earg --empt="" --empt=arg -H -ofile --long-o -v \
|
|
--verbos -Inf -INF > out || test_failed $LINENO "$i"
|
|
cmp "${testdir}"/test2.txt out || test_failed $LINENO "$i"
|
|
|
|
"$i" --appe -1 -.5 -a file1 -b 5 --blo 10 -c -carg --casua --casua=arg \
|
|
-e "" -e arg -3.14 --emp "" --emp arg -inf -H -o file file2 \
|
|
--lon -Inf -v -INF --verbo > out || test_failed $LINENO "$i"
|
|
cmp "${testdir}"/test3.txt out || test_failed $LINENO "$i"
|
|
|
|
"$i" --app -a -b5 -1 --bl=10 -c -.5 -carg --cas= --cas=arg -e "" \
|
|
file1 -e arg --em "" -3.14 --em arg -H -ofile -inf --long-only -v \
|
|
--verb file2 -Inf -INF > out || test_failed $LINENO "$i"
|
|
cmp "${testdir}"/test4.txt out || test_failed $LINENO "$i"
|
|
done
|
|
|
|
"${PARSER}" --int-min --int-max > out || test_failed $LINENO
|
|
"${CPARSER}" --int-min --int-max > cout || test_failed $LINENO
|
|
cmp out cout || test_failed $LINENO
|
|
|
|
printf "\ntesting bad input..."
|
|
|
|
for i in "${PARSER}" "${CPARSER}" ; do
|
|
cp cout out || framework_failure
|
|
"$i" --v 2> cout # ambiguous option
|
|
[ $? = 1 ] || test_failed $LINENO "$i"
|
|
|
|
"$i" --ve 2>> cout
|
|
[ $? = 1 ] || test_failed $LINENO "$i"
|
|
|
|
"$i" --ver 2>> cout
|
|
[ $? = 1 ] || test_failed $LINENO "$i"
|
|
|
|
"$i" --unrecognized 2>> cout # unrecognized option
|
|
[ $? = 1 ] || test_failed $LINENO "$i"
|
|
|
|
"$i" -x 2>> cout # invalid option
|
|
[ $? = 1 ] || test_failed $LINENO "$i"
|
|
|
|
"$i" -aARG 2>> cout # argument not allowed
|
|
[ $? = 1 ] || test_failed $LINENO "$i"
|
|
|
|
"$i" -b 2>> cout # argument required
|
|
[ $? = 1 ] || test_failed $LINENO "$i"
|
|
|
|
"$i" --block 2>> cout
|
|
[ $? = 1 ] || test_failed $LINENO "$i"
|
|
|
|
"$i" --block= 2>> cout
|
|
[ $? = 1 ] || test_failed $LINENO "$i"
|
|
|
|
"$i" -e"" 2>> cout
|
|
[ $? = 1 ] || test_failed $LINENO "$i"
|
|
|
|
"$i" -u 2>> cout # uncaught option
|
|
[ $? = 3 ] || test_failed $LINENO "$i"
|
|
done
|
|
sed -e 's/carg_parser/arg_parser/' cout > out2 || framework_failure
|
|
diff -u out out2 || test_failed $LINENO
|
|
|
|
echo
|
|
if [ ${fail} = 0 ] ; then
|
|
echo "tests completed successfully."
|
|
cd "${objdir}" && rm -r tmp
|
|
else
|
|
echo "tests failed."
|
|
fi
|
|
exit ${fail}
|