singe/singe/thirdparty/arg_parser/testsuite/check.sh
2020-02-04 19:44:15 -06:00

101 lines
2.8 KiB
Bash
Executable file

#! /bin/sh
# check script for Arg_parser - POSIX/GNU command line argument parser.
# Copyright (C) 2011-2019 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
in="${testdir}"/test.txt
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" -a -b 5 -c -carg -o file --orphan --verbose file1 file2 > out ||
test_failed $LINENO "$i"
cmp ${in} out || test_failed $LINENO "$i"
"$i" -ab5 -c -carg -ofile file1 --orphan file2 --verbos > out ||
test_failed $LINENO "$i"
cmp ${in} out || test_failed $LINENO "$i"
"$i" --append file1 --block 5 --casual file2 --casual=arg -o file --orphan --verbo > out ||
test_failed $LINENO "$i"
cmp ${in} out || test_failed $LINENO "$i"
"$i" --append --block=5 --casual= file1 --casual=arg -ofile --orphan --verb file2 > out ||
test_failed $LINENO "$i"
cmp ${in} out || test_failed $LINENO "$i"
done
printf "\ntesting bad input..."
for i in "${PARSER}" "${CPARSER}" ; do
"$i" --v 2> /dev/null # ambiguous option
[ $? = 1 ] || test_failed $LINENO "$i"
"$i" --ve 2> /dev/null
[ $? = 1 ] || test_failed $LINENO "$i"
"$i" --ver 2> /dev/null
[ $? = 1 ] || test_failed $LINENO "$i"
"$i" --unrecognized 2> /dev/null # unrecognized option
[ $? = 1 ] || test_failed $LINENO "$i"
"$i" -x 2> /dev/null # invalid option
[ $? = 1 ] || test_failed $LINENO "$i"
"$i" -aARG 2> /dev/null # argument not allowed
[ $? = 1 ] || test_failed $LINENO "$i"
"$i" -b 2> /dev/null # argument required
[ $? = 1 ] || test_failed $LINENO "$i"
"$i" --block 2> /dev/null
[ $? = 1 ] || test_failed $LINENO "$i"
"$i" --block= 2> /dev/null
[ $? = 1 ] || test_failed $LINENO "$i"
"$i" -u 2> /dev/null # uncaught option
[ $? = 3 ] || test_failed $LINENO "$i"
done
echo
if [ ${fail} = 0 ] ; then
echo "tests completed successfully."
cd "${objdir}" && rm -r tmp
else
echo "tests failed."
fi
exit ${fail}