Release new version 0.79
[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         DELIM=" "
16         # check if CMD is optional
17         if [[ $CMD == *:: ]] ; then
18             DELIM="="
19         fi
20         # CMD expects addional parameter
21         if [[ $CMD == *: ]] ; then
22             PARAM=$RANDOM
23         fi
24         VALUES[$count]="${CMD%%:*}$DELIM$PARAM"
25         ((count++))
26     done
27     IFS=$OLDIFS
28
29     # build the commandline
30     while [ "$i" -lt "$count" ] ; do
31         CMDLINE+="--${VALUES[$i]} "
32         ((i++))
33     done
34
35     . ../cmdlineopts.clp $CMDLINE
36
37
38     i=0
39     # check the result against input
40     while [ "$i" -lt "$count" ] ; do
41         ENTRY="${VALUES[$i]}"
42         VARNAME=${ENTRY% *}
43         VARNAME=${VARNAME%=*}
44         RESULT=${ENTRY/* /}
45         RESULT=${RESULT/*=/}
46         VARNAME='$_opt_'${VARNAME/-/_}
47         VALUE="$(eval echo $VARNAME)"
48         if [ -z "$RESULT" ] ; then
49             assertNotNull "$VARNAME should be not null" "$VALUE"
50         else
51             assertEquals "$VARNAME" "$RESULT" "$VALUE"
52         fi
53         ((i++))
54     done
55 }
56
57 SHUNIT_PARENT=$0
58 . /usr/share/shunit2/shunit2