X-Git-Url: https://git.grml.org/?p=grml-debootstrap.git;a=blobdiff_plain;f=tests%2Ftest_cmdlineopts.sh;fp=tests%2Ftest_cmdlineopts.sh;h=940b048c67201cbea37312f27e85123245e95033;hp=0000000000000000000000000000000000000000;hb=db9d7568a024f01c9f27116fd478f1d7b6fff602;hpb=a8ad11c4b34c20892e73b76b6a54e5ec106b3d50 diff --git a/tests/test_cmdlineopts.sh b/tests/test_cmdlineopts.sh new file mode 100755 index 0000000..940b048 --- /dev/null +++ b/tests/test_cmdlineopts.sh @@ -0,0 +1,48 @@ +#!/bin/bash + + +test_cmdlineopts() { + . ../cmdlineopts.clp + CMDLINE= + typeset -a VALUES + count=0 + i=0 + + OLDIFS="$IFS" + IFS=, + for CMD in $CMDLINE_OPTS ; do + PARAM="" + if [[ $CMD == *: ]] ; then + PARAM=$RANDOM + fi + VALUES[$count]="${CMD%%:*} $PARAM" + ((count++)) + done + IFS=$OLDIFS + + while [ "$i" -lt "$count" ] ; do + CMDLINE+="--${VALUES[$i]} " + ((i++)) + done + + . ../cmdlineopts.clp $CMDLINE + + + i=0 + while [ "$i" -lt "$count" ] ; do + ENTRY="${VALUES[$i]}" + VARNAME=${ENTRY% *} + RESULT=${ENTRY/* /} + VARNAME='$_opt_'${VARNAME/-/_} + VALUE="$(eval echo $VARNAME)" + if [ -z "$RESULT" ] ; then + assertNotNull "$VARNAME should be not null" "$VALUE" + else + assertEquals "$VARNAME" "$RESULT" "$VALUE" + fi + ((i++)) + done +} + +SHUNIT_PARENT=$0 +. /usr/share/shunit2/shunit2