Added unit tests for cmddlineopts.clp
authorUlrich Dangel <uli@spamt.net>
Tue, 29 Dec 2009 17:44:31 +0000 (18:44 +0100)
committerUlrich Dangel <uli@spamt.net>
Tue, 29 Dec 2009 17:44:31 +0000 (18:44 +0100)
cmdlineopts.clp
debian/control
debian/rules
tests/run_tests.sh [new file with mode: 0755]
tests/test_cmdlineopts.sh [new file with mode: 0755]

index 5d259a5..dd88afb 100644 (file)
 # should be handled in the main script, where it belongs.
 ################################################################################
 
+CMDLINE_OPTS=mirror:,iso:,release:,target:,mntpoint:,debopt:,interactive,nodebootstrap,config:,confdir:,packages:,chroot-scripts:,scripts:,pre-scripts:,debconf:,keep_src_list,hostname:,password:,bootappend:,grub:,arch:,insecure,verbose,help,version
+
 _opt_temp=`getopt --name grml-debootstrap -o +m:i:r:t:p:c:d:vhV --long \
-    mirror:,iso:,release:,target:,mntpoint:,debopt:,interactive,nodebootstrap,config:,confdir:,packages:,chroot-scripts:,scripts:,pre-scripts:,debconf:,keep_src_list,hostname:,password:,bootappend:,grub:,arch:,insecure,verbose,help,version \
-  -- "$@"`
+    $CMDLINE_OPTS -- "$@"`
+
 if [ $? != 0 ]; then
   eerror "Try 'grml-debootstrap --help' for more information."; eend 1; exit 1
 fi
index dc0829e..b26a1b1 100644 (file)
@@ -4,7 +4,7 @@ Priority: optional
 Maintainer: Michael Prokop <mika@grml.org>
 Uploaders: Alexander Wirt <formorer@grml.org>
 Build-Depends: debhelper (>= 5)
-Build-Depends-Indep: asciidoc, docbook-xsl, xsltproc
+Build-Depends-Indep: asciidoc, docbook-xsl, xsltproc, shunit2
 Standards-Version: 3.8.3
 Homepage: http://grml.org/grml-debootstrap/
 Vcs-git: git://git.grml.org/grml-debootstrap.git
index 9db7fb9..e9aada2 100755 (executable)
@@ -13,6 +13,7 @@ build: build-stamp
 
 build-stamp:
        dh_testdir
+       (cd tests && ./run_tests.sh)
        make
        touch $@
 
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
new file mode 100755 (executable)
index 0000000..46c4645
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/zsh
+# Filename:      run_tests
+# Purpose:       run unit tests for grml-autoconfig
+# Authors:       grml-team (grml.org), (c) Ulrich Dangel <mru@grml.org>
+# Bug-Reports:   see http://grml.org/bugs/
+# License:       This file is licensed under the GPL v2.
+################################################################################
+
+
+GLOBRETVAL=0
+
+for FILE in test_*.sh ; do
+  if [ -x ${FILE} ] ; then
+     pretty_name="${FILE##test_}"
+     pretty_name="${pretty_name/.sh/}"
+
+     echo "Running test for: ${pretty_name}"
+
+     ./${FILE}
+     RETVAL=$?
+
+     [ "$RETVAL" -ne 0 ] && GLOBRETVAL=$RETVAL
+  fi
+done
+
+exit $GLOBRETVAL
+
+## END OF FILE #################################################################
+# vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3
diff --git a/tests/test_cmdlineopts.sh b/tests/test_cmdlineopts.sh
new file mode 100755 (executable)
index 0000000..940b048
--- /dev/null
@@ -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