From db9d7568a024f01c9f27116fd478f1d7b6fff602 Mon Sep 17 00:00:00 2001 From: Ulrich Dangel Date: Tue, 29 Dec 2009 18:44:31 +0100 Subject: [PATCH] Added unit tests for cmddlineopts.clp --- cmdlineopts.clp | 6 ++++-- debian/control | 2 +- debian/rules | 1 + tests/run_tests.sh | 29 ++++++++++++++++++++++++++++ tests/test_cmdlineopts.sh | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100755 tests/run_tests.sh create mode 100755 tests/test_cmdlineopts.sh diff --git a/cmdlineopts.clp b/cmdlineopts.clp index 5d259a5..dd88afb 100644 --- a/cmdlineopts.clp +++ b/cmdlineopts.clp @@ -12,9 +12,11 @@ # 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 diff --git a/debian/control b/debian/control index dc0829e..b26a1b1 100644 --- a/debian/control +++ b/debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: Michael Prokop Uploaders: Alexander Wirt 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 diff --git a/debian/rules b/debian/rules index 9db7fb9..e9aada2 100755 --- a/debian/rules +++ b/debian/rules @@ -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 index 0000000..46c4645 --- /dev/null +++ b/tests/run_tests.sh @@ -0,0 +1,29 @@ +#!/bin/zsh +# Filename: run_tests +# Purpose: run unit tests for grml-autoconfig +# Authors: grml-team (grml.org), (c) Ulrich Dangel +# 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 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 -- 2.1.4