[Dbconfig-common-changes] [dbconfig-common] r429 - in trunk: . debian internal test test/data
Sean Finney
seanius at alioth.debian.org
Thu Mar 27 23:05:45 UTC 2008
Author: seanius
Date: 2008-03-27 23:05:45 +0000 (Thu, 27 Mar 2008)
New Revision: 429
Added:
trunk/test/
trunk/test/basic.ts
trunk/test/data/
trunk/test/data/dbc_logline.simple.txt
trunk/test/data/dbc_logline.twolines.txt
trunk/test/data/dbc_logline.twowords.txt
trunk/test/data/dbc_logpart.noeol.txt
trunk/test/dbc.log
trunk/test/runtests.sh
Modified:
trunk/debian/changelog
trunk/internal/common
Log:
zomg unit tests!
Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog 2008-03-27 21:58:01 UTC (rev 428)
+++ trunk/debian/changelog 2008-03-27 23:05:45 UTC (rev 429)
@@ -4,6 +4,11 @@
* more bugs/fixes from Niko Tyni (thanks!)
- fix for malformed log messages (closes: #472993).
* centralize definition of dbc.log location
+ * a test suite! now using shunit2 for unit tests, implemented some
+ basic tests for logging as a proof-of-concept.
+ * first fix from unit tests, use ${param:-} for possibly unset params
+ in dbc_mktemp (others will follow as they're found). fixes like this
+ will allow dbconfig-common to run "set -u" eventually.
-- Sean Finney <seanius at debian.org> Thu, 27 Mar 2008 22:58:26 +0100
Modified: trunk/internal/common
===================================================================
--- trunk/internal/common 2008-03-27 21:58:01 UTC (rev 428)
+++ trunk/internal/common 2008-03-27 23:05:45 UTC (rev 429)
@@ -183,7 +183,7 @@
dbc_mktemp(){
local tfile ttemplate
- if [ "$1" ]; then
+ if [ "${1:-}" ]; then
ttemplate="$1";
else
ttemplate="dbconfig-common.XXXXXX";
Added: trunk/test/basic.ts
===================================================================
--- trunk/test/basic.ts (rev 0)
+++ trunk/test/basic.ts 2008-03-27 23:05:45 UTC (rev 429)
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+oneTimeSetUp(){
+ local curdir basedir
+ curdir="`pwd`"
+ basedir="`dirname $0`"
+ # make sure we're called from the test dir, even if we weren't
+ if [ "$curdir" != "$basedir" ]; then
+ cd "$basedir"
+ exec "./`basename $0`"
+ fi
+ # override the logfile location
+ _dbc_logfile="`pwd`/dbc.log"
+ mkdir -p ./tmp
+ . ../internal/common
+}
+
+assertEqualFiles(){
+ local msg outfile errfile
+ outfile=./tmp/assertEqualFiles.stdout
+ errfile=./tmp/assertEqualFiles.stderr
+ if [ "$#" -eq 3 ]; then
+ msg="$1"
+ shift
+ else
+ msg="Files not equal"
+ fi
+ diff -u "$1" "$2" > $outfile 2>$errfile
+ assertTrue "$msg" "[ $? -eq 0 ]"
+ if [ -s "$errfile" ]; then
+ cat $errfile
+ fi
+ if [ -s "$outfile" ]; then
+ cat $outfile
+ fi
+}
+
+setUp(){
+ find ./tmp -type f -print0 | xargs --no-run-if-empty -0 rm
+ cat /dev/null > $_dbc_logfile
+}
+
+test_dbc_logline(){
+ local output
+
+ # test echoing one line to user and logfile
+ output=`dbc_logline foo 2>&1 >/dev/null`
+ assertEquals foo. "$output"
+ assertEqualFiles $_dbc_logfile ./data/dbc_logline.simple.txt
+
+ # test that a second line is logged appropriately
+ dbc_logline bar >/dev/null 2>&1
+ assertEqualFiles $_dbc_logfile ./data/dbc_logline.twolines.txt
+
+ # test that multiple arguments are logged appropriately
+ cat /dev/null > $_dbc_logfile
+ output=`dbc_logline foo bar 2>&1 >/dev/null`
+ assertEquals "foo bar." "$output"
+ assertEqualFiles $_dbc_logfile ./data/dbc_logline.twowords.txt
+
+ # assure that quoting and escaping are handled properly
+ output=`dbc_logline "\"foobar's\ttab\"" 2>&1 >/dev/null`
+ assertEquals "\"foobar's tab\"." "$output"
+}
+
+test_dbc_logpart(){
+ # make sure it properly logs partial lines
+ dbc_logpart foo >/dev/null 2>&1
+ assertEqualFiles $_dbc_logfile ./data/dbc_logpart.noeol.txt
+
+ # ...and that it completes them with the next logline.
+ dbc_logline bar >/dev/null 2>&1
+ assertEqualFiles $_dbc_logfile ./data/dbc_logline.twowords.txt
+}
+
+test_dbc_debug(){
+ local olddebug
+ if [ "${dbc_debug:-}" ]; then olddebug=$dbc_debug; else olddebug=""; fi
+
+ # make sure it doesn't do anything by default
+ dbc_debug=""
+ _dbc_debug foo bar >/dev/null 2>&1
+ assertEqualFiles $_dbc_logfile /dev/null
+
+ # ...and that it completes them with the next logline.
+ dbc_debug=1
+ _dbc_debug foo bar >/dev/null 2>&1
+ assertEqualFiles $_dbc_logfile ./data/dbc_logline.twowords.txt
+
+ dbc_debug=$olddebug
+}
+
+test_dbc_mktemp(){
+ local t
+ t=`dbc_mktemp`
+ assertTrue "file $t nonexistant/nonempty" "[ -f '$t' ] && [ ! -s '$t' ]"
+ rm -f "$t"
+ t=`dbc_mktemp foo.XXXXXX`
+ assertTrue "file $t nonexistant/nonempty" "[ -f '$t' ] && [ ! -s '$t' ]"
+ rm -f "$t"
+}
+
+. /usr/share/shunit2/shunit2
Property changes on: trunk/test/basic.ts
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/test/data/dbc_logline.simple.txt
===================================================================
--- trunk/test/data/dbc_logline.simple.txt (rev 0)
+++ trunk/test/data/dbc_logline.simple.txt 2008-03-27 23:05:45 UTC (rev 429)
@@ -0,0 +1 @@
+foo.
Added: trunk/test/data/dbc_logline.twolines.txt
===================================================================
--- trunk/test/data/dbc_logline.twolines.txt (rev 0)
+++ trunk/test/data/dbc_logline.twolines.txt 2008-03-27 23:05:45 UTC (rev 429)
@@ -0,0 +1,2 @@
+foo.
+bar.
Added: trunk/test/data/dbc_logline.twowords.txt
===================================================================
--- trunk/test/data/dbc_logline.twowords.txt (rev 0)
+++ trunk/test/data/dbc_logline.twowords.txt 2008-03-27 23:05:45 UTC (rev 429)
@@ -0,0 +1 @@
+foo bar.
Added: trunk/test/data/dbc_logpart.noeol.txt
===================================================================
--- trunk/test/data/dbc_logpart.noeol.txt (rev 0)
+++ trunk/test/data/dbc_logpart.noeol.txt 2008-03-27 23:05:45 UTC (rev 429)
@@ -0,0 +1 @@
+foo
\ No newline at end of file
Added: trunk/test/dbc.log
===================================================================
Added: trunk/test/runtests.sh
===================================================================
--- trunk/test/runtests.sh (rev 0)
+++ trunk/test/runtests.sh 2008-03-27 23:05:45 UTC (rev 429)
@@ -0,0 +1,12 @@
+#! /bin/sh
+
+cd "`dirname $0`"
+for t in basic.ts; do
+ printf "# # #\n# # # Test: $t\n# # #\n"
+ printf "# #\n# # Shell: bash\n# #\n"
+ bash $t
+ printf "\n# #\n# # Shell: dash\n# #\n"
+ dash $t
+ printf "\n# #\n# # Shell: zsh\n# #\n"
+ zsh -y +o function_argzero $t
+done
Property changes on: trunk/test/runtests.sh
___________________________________________________________________
Name: svn:executable
+ *
More information about the Dbconfig-common-changes
mailing list