Added unit tests for cmddlineopts.clp
[grml-debootstrap.git] / tests / test_cmdlineopts.sh
1 #!/bin/bash
2
3
4 test_cmdlineopts() {
5     . ../cmdlineopts.clp
6     CMDLINE=
7     typeset -a VALUES
8     count=0
9     i=0
10
11     OLDIFS="$IFS"
12     IFS=,
13     for CMD in $CMDLINE_OPTS ; do
14         PARAM=""
15         if [[ $CMD == *: ]] ; then
16             PARAM=$RANDOM
17         fi
18         VALUES[$count]="${CMD%%:*} $PARAM"
19         ((count++))
20     done
21     IFS=$OLDIFS
22
23     while [ "$i" -lt "$count" ] ; do
24         CMDLINE+="--${VALUES[$i]} "
25         ((i++))
26     done
27
28     . ../cmdlineopts.clp $CMDLINE
29
30
31     i=0
32     while [ "$i" -lt "$count" ] ; do
33         ENTRY="${VALUES[$i]}"
34         VARNAME=${ENTRY% *}
35         RESULT=${ENTRY/* /}
36         VARNAME='$_opt_'${VARNAME/-/_}
37         VALUE="$(eval echo $VARNAME)"
38         if [ -z "$RESULT" ] ; then
39             assertNotNull "$VARNAME should be not null" "$VALUE"
40         else
41             assertEquals "$VARNAME" "$RESULT" "$VALUE"
42         fi
43         ((i++))
44     done
45 }
46
47 SHUNIT_PARENT=$0
48 . /usr/share/shunit2/shunit2