poldek: poldek/tests/sh/lib/repo-setup (NEW), poldek/tests/sh/lib/...

mis mis at pld-linux.org
Sat Jun 23 17:25:26 CEST 2007


Author: mis                          Date: Sat Jun 23 15:25:26 2007 GMT
Module: poldek                        Tag: HEAD
---- Log message:
- shunit impl

---- Files affected:
poldek/poldek/tests/sh/lib:
   repo-setup (NONE -> 1.1)  (NEW), setup (NONE -> 1.1)  (NEW), shunit2 (NONE -> 1.1)  (NEW), vftest-fetch.conf (NONE -> 1.1)  (NEW), vftest.sh (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: poldek/poldek/tests/sh/lib/repo-setup
diff -u /dev/null poldek/poldek/tests/sh/lib/repo-setup:1.1
--- /dev/null	Sat Jun 23 17:25:26 2007
+++ poldek/poldek/tests/sh/lib/repo-setup	Sat Jun 23 17:25:21 2007
@@ -0,0 +1,99 @@
+
+tearDown() {
+    [ -n "$REPO" ] && rm -rf $REPO/packages.*
+    [ -n "$TMPDIR" ] && rm -rf $TMPDIR/*.*
+}
+
+setUp() {
+    tearDown
+}
+
+oneTimeSetUp() {
+    [ ! -d "$PWD/sh/lib" ] && fail "$PWD is not a tests directory (missing sh/lib)"
+    POLDEK="$PWD/../cli/poldek $QUIET"
+    POLDEK_NOCONF="$POLDEK --noconf -Ovfile_retries=1"
+
+    [ ! -d "repo" ] && fail "repo: no such directory"
+    SOURCE_REPO="${PWD}/repo"
+
+    [ -z "$TMP" ] && TMP="${TMPDIR}"
+    [ -z "$TMP" ] && TMP="${PWD}"
+    TMP="${TMP}/poldekTests"
+    TMPDIR="$TMP"
+
+    rm -rf $TMPDIR
+    mkdir -p $TMPDIR
+
+    [ ! -d $TMPDIR ] && fail "$TMPDIR: no such directory"
+
+    REPO="$TMPDIR/repo"
+    REPOURL="test://$TMPDIR/repo/"
+
+    mkdir -p $REPO
+    [ ! -d $REPO ] && fail "mkdir $REPO failed?"
+
+    PATH="$PATH:$PWD/sh/lib/"
+    POLDEK_UP="$POLDEK --conf ./sh/lib/vftest-fetch.conf --cachedir $TMPDIR"
+    cp $SOURCE_REPO/*.rpm $REPO || fail
+    tearDown
+}
+
+oneTimeTearDown() {
+   if echo $TMPDIR | grep -q poldekTest; then rm -rf $TMPDIR; fi
+}
+
+die_if_invalid_index() {
+    anindex=$1
+
+    [ -f $anindex ] || fail "$anindex not created"
+    if echo $anindex | grep -q "diff.toc"; then
+       expected_lines=$2
+
+       lines=$(zcat $anindex | wc -l)
+       if [ "$lines" != "$expected_lines" ]; then
+          fail "$anindex contains $lines lines, expected $expected_lines"
+       fi
+       return
+    fi
+
+    anindex_type="pdir"
+    if echo $anindex | grep -q \.ndir\.; then anindex_type="pndir"; fi
+
+    anindex_real_type="pdir"
+    if zgrep -q '^tndb[0-9]\.[0-9]' $anindex; then
+       anindex_real_type="pndir"
+    fi
+    
+    if [ "$anindex_real_type" != "$anindex_type" ]; then
+        fail "invalid $anindex type $anindex_type, real is $anindex_real_type"
+    fi
+
+    if zgrep -q 'Contains 0 packages' $anindex; then
+        expected_packages=$2
+        if [ "$expected_packages" != "0" ]; then
+            fail "empty $anindex"
+        fi
+    fi
+}
+
+
+add_package_to_repo() {
+    for p in $(ls $SOURCE_REPO/*.rpm); do 
+        [ ! -f $p ] && fail "no packages in $SOURCE_REPO?"
+        package=$(basename $p)
+
+        if [ ! -f "$REPO/$package" ]; then
+            cp $p $REPO
+            msg "Added $package"
+            return 0
+        fi
+    done
+}
+
+
+remove_package_from_repo() {
+    package=$(find $REPO -name \*.rpm | head -1)
+    rm -f $package
+    msg "Removed $(basename $package)"
+}
+

================================================================
Index: poldek/poldek/tests/sh/lib/setup
diff -u /dev/null poldek/poldek/tests/sh/lib/setup:1.1
--- /dev/null	Sat Jun 23 17:25:26 2007
+++ poldek/poldek/tests/sh/lib/setup	Sat Jun 23 17:25:21 2007
@@ -0,0 +1,12 @@
+# 
+# 
+
+[ -z "$QUIET" ] && QUIET="-q"
+
+msg() {
+    [ "$QUIET" != "-q" ] && echo -e $@
+}
+
+msgn() {
+    msg "\n## $@"
+}

================================================================
Index: poldek/poldek/tests/sh/lib/shunit2
diff -u /dev/null poldek/poldek/tests/sh/lib/shunit2:1.1
--- /dev/null	Sat Jun 23 17:25:26 2007
+++ poldek/poldek/tests/sh/lib/shunit2	Sat Jun 23 17:25:21 2007
@@ -0,0 +1,884 @@
+# $Id$
+# vim:syntax=sh:sts=2
+# vim:foldmethod=marker:foldmarker=/**,*/
+#
+#/**
+# <?xml version="1.0" encoding="UTF-8"?>
+# <s:shelldoc xmlns:s="http://www.forestent.com/projects/shelldoc/xsl/2005.0">
+# <s:header>
+# shUnit 2.1.0
+# Shell Unit Test Framework
+#
+# http://shunit2.sourceforge.net/
+#
+# written by Kate Ward &lt;kate.ward at forestent.com&gt;
+# released under the LGPL
+#
+# this module implements a xUnit based unit test framework similar to JUnit
+# </s:header>
+#*/
+
+# shell flags for shunit:
+# u - treat unset variables as an error when performing parameter expansion
+__SHUNIT_SHELL_FLAGS='u'
+
+# save the current set of shell flags, and then set some for ourselves
+__shunit_oldShellFlags="$-"
+for _shunit_shellFlag in `echo "${__SHUNIT_SHELL_FLAGS}" |sed 's/\(.\)/\1 /g'`
+do
+  set -${_shunit_shellFlag}
+done
+
+# constants
+
+__SHUNIT_VERSION='2.1.1pre'
+
+SHUNIT_TRUE=0
+SHUNIT_FALSE=1
+
+__SHUNIT_ASSERT_MSG_PREFIX='ASSERT:'
+
+for _su_const in `set |grep "^__SHUNIT_" |cut -d= -f1`; do
+  readonly ${_su_const}
+done
+unset _su_const
+
+# variables
+__shunit_skip=${SHUNIT_FALSE}
+__shunit_suite=''
+
+__shunit_testsPassed=0
+__shunit_testsFailed=0
+__shunit_testsSkipped=0
+__shunit_testsTotal=0
+
+#-----------------------------------------------------------------------------
+# assert functions
+#
+
+#/**
+# <s:function group="asserts">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>assertEquals</function></funcdef>
+#       <paramdef>string <parameter>[message]</parameter></paramdef>
+#       <paramdef>string <parameter>expected</parameter></paramdef>
+#       <paramdef>string <parameter>actual</parameter></paramdef>
+#     </funcprototype>
+#   </funcsynopsis>
+#   <para>Asserts that <emphasis>expected</emphasis> and
+#   <emphasis>actual</emphasis> are equal to one another. The message is
+#   optional.</para>
+# </entry>
+# </s:function>
+#*/
+assertEquals()
+{
+  _shunit_shouldSkip && return ${SHUNIT_TRUE}
+
+  _su_message=''
+  if [ $# -eq 3 ]; then
+    _su_message=$1
+    shift
+  fi
+  _su_expected=$1
+  _su_actual=$2
+
+  if [ "${_su_expected}" = "${_su_actual}" ]; then
+    _shunit_testPassed
+    return ${SHUNIT_TRUE}
+  else
+    _shunit_testFailed "${_su_message}"
+    return ${SHUNIT_FALSE}
+  fi
+
+  unset _su_message _su_expected _su_actual
+}
+
+#/**
+# <s:function group="asserts">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>assertNull</function></funcdef>
+#       <paramdef>string <parameter>[message]</parameter></paramdef>
+#       <paramdef>string <parameter>value</parameter></paramdef>
+#     </funcprototype>
+#   </funcsynopsis>
+#   <para>Asserts that <emphasis>value</emphasis> is <literal>null</literal>,
+#   or in shell terms a zero-length string. The message is optional.</para>
+# </entry>
+# </s:function>
+#*/
+assertNull()
+{
+  _shunit_shouldSkip && return ${SHUNIT_TRUE}
+
+  _su_message=''
+  if [ $# -eq 2 ]; then
+    _su_message=$1
+    shift
+  fi
+  _su_value=$1
+
+  _su_value2=`eval echo "${_su_value}"`
+  if [ -z "${_su_value2}" ]; then
+    _shunit_testPassed
+    return ${SHUNIT_TRUE}
+  else
+    _shunit_testFailed "${_su_message}"
+    return ${SHUNIT_FALSE}
+  fi
+
+  unset _su_message _su_value _su_value2
+}
+
+#/**
+# <s:function group="asserts">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>assertNotNull</function></funcdef>
+#       <paramdef>string <parameter>[message]</parameter></paramdef>
+#       <paramdef>string <parameter>value</parameter></paramdef>
+#     </funcprototype>
+#   </funcsynopsis>
+#   <para>Asserts that <emphasis>value</emphasis> is <emphasis
+#   role="strong">not</emphasis> <literal>null</literal>, or in shell terms not
+#   a zero-length string. The message is optional.</para>
+# </entry>
+# </s:function>
+#*/
+assertNotNull()
+{
+  _shunit_shouldSkip && return ${SHUNIT_TRUE}
+
+  _su_message=''
+  if [ $# -eq 2 ]; then
+    _su_message=$1
+    shift
+  fi
+  _su_value=$1
+
+  _su_value2=`eval echo "${_su_value}"`
+  if [ -n "${_su_value2}" ]; then
+    _shunit_testPassed
+    return ${SHUNIT_TRUE}
+  else
+    _shunit_testFailed "${_su_message}"
+    return ${SHUNIT_FALSE}
+  fi
+
+  unset _su_message _su_value _su_value2
+}
+
+#/**
+# <s:function group="asserts">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>assertSame</function></funcdef>
+#       <paramdef>string <parameter>[message]</parameter></paramdef>
+#       <paramdef>string <parameter>expected</parameter></paramdef>
+#       <paramdef>string <parameter>actual</parameter></paramdef>
+#     </funcprototype>
+#   </funcsynopsis>
+#   <para>This function is functionally equivalent to
+#   <function>assertEquals</function>.</para>
+# </entry>
+# </s:function>
+#*/
+assertSame()
+{
+  assertEquals "$@"
+}
+
+#/**
+# <s:function group="asserts">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>assertNotSame</function></funcdef>
+#       <paramdef>string <parameter>[message]</parameter></paramdef>
+#       <paramdef>string <parameter>expected</parameter></paramdef>
+#       <paramdef>string <parameter>actual</parameter></paramdef>
+#     </funcprototype>
+#   </funcsynopsis>
+#   <para>Asserts that <emphasis>expected</emphasis> and
+#   <emphasis>actual</emphasis> are <emphasis role="strong">not</emphasis> equal to one another. The message is optional.</para>
+# </entry>
+# </s:function>
+#*/
+assertNotSame()
+{
+  _shunit_shouldSkip && return ${SHUNIT_TRUE}
+
+  _su_message=''
+  if [ $# -eq 3 ]; then
+    _su_message=$1
+    shift
+  fi
+  _su_expected=$1
+  _su_actual=$2
+
+  if [ "${_su_expected}" != "${_su_actual}" ]; then
+    _shunit_testPassed
+    return ${SHUNIT_TRUE}
+  else
+    _shunit_testFailed "${_su_message}"
+    return ${SHUNIT_FALSE}
+  fi
+
+  unset _su_message _su_expected _su_actual
+}
+
+#/**
+# <s:function group="asserts">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>assertTrue</function></funcdef>
+#       <paramdef>string <parameter>[message]</parameter></paramdef>
+#       <paramdef>string <parameter>condition</parameter></paramdef>
+#     </funcprototype>
+#   </funcsynopsis>
+#   <para>Asserts that a given shell test condition is true. The message is
+#   optional.</para>
+#   <para>Testing whether something is true or false is easy enough by using
+#   the assertEquals/assertNotSame functions. Shell supports much more
+#   complicated tests though, and a means to support them was needed. As such,
+#   this function tests that conditions are true or false through evaluation
+#   rather than just looking for a true or false.</para>
+#   <funcsynopsis>
+#     The following test will succeed: <funcsynopsisinfo>assertTrue "[ 34 -gt 23 ]"</funcsynopsisinfo>
+#     The folloing test will fail with a message: <funcsynopsisinfo>assertTrue "test failed" "[ -r '/non/existant/file' ]"</funcsynopsisinfo>
+#   </funcsynopsis>
+# </entry>
+# </s:function>
+#*/
+assertTrue()
+{
+  _shunit_shouldSkip && return ${SHUNIT_TRUE}
+
+  _su_message=''
+  if [ $# -eq 2 ]; then
+    _su_message=$1
+    shift
+  fi
+  _su_condition=$1
+
+  ( eval ${_su_condition} ) >/dev/null 2>&1
+  if [ $? -eq ${SHUNIT_TRUE} ]; then
+    _shunit_testPassed
+    return ${SHUNIT_TRUE}
+  else
+    _shunit_testFailed "${_su_message}"
+    return ${SHUNIT_FALSE}
+  fi
+
+  unset _su_message _su_condition
+}
+
+#/**
+# <s:function group="asserts">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>assertFalse</function></funcdef>
+#       <paramdef>string <parameter>[message]</parameter></paramdef>
+#       <paramdef>string <parameter>condition</parameter></paramdef>
+#     </funcprototype>
+#   </funcsynopsis>
+#   <para>Asserts that a given shell test condition is false. The message is
+#   optional.</para>
+#   <para>Testing whether something is true or false is easy enough by using
+#   the assertEquals/assertNotSame functions. Shell supports much more
+#   complicated tests though, and a means to support them was needed. As such,
+#   this function tests that conditions are true or false through evaluation
+#   rather than just looking for a true or false.</para>
+#   <funcsynopsis>
+#     The following test will succeed: <funcsynopsisinfo>assertFalse "[ 'apples' = 'oranges' ]"</funcsynopsisinfo>
+#     The folloing test will fail with a message: <funcsynopsisinfo>assertFalse "test failed" "[ 1 -eq 1 -a 2 -eq 2 ]"</funcsynopsisinfo>
+#   </funcsynopsis>
+# </entry>
+# </s:function>
+#*/
+assertFalse()
+{
+  _shunit_shouldSkip && return ${SHUNIT_TRUE}
+
+  _su_message=''
+  if [ $# -eq 2 ]; then
+    _su_message=$1
+    shift
+  fi
+  _su_condition=$1
+
+  ( eval ${_su_condition} ) >/dev/null 2>&1
+  if [ $? -ne ${SHUNIT_TRUE} ]; then
+    _shunit_testPassed
+    return ${SHUNIT_TRUE}
+  else
+    _shunit_testFailed "${_su_message}"
+    return ${SHUNIT_FALSE}
+  fi
+
+  unset _su_message _su_condition
+}
+
+#-----------------------------------------------------------------------------
+# failure functions
+#
+
+#/**
+# <s:function group="failures">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>fail</function></funcdef>
+#       <paramdef>string <parameter>[message]</parameter></paramdef>
+#     </funcprototype>
+#   </funcsynopsis>
+#   <para>Fails the test immediately, with the optional message.</para>
+# </entry>
+# </s:function>
+#*/
+fail()
+{
+  _shunit_shouldSkip && return ${SHUNIT_TRUE}
+
+  _shunit_testFailed "${@:-}"
+}
+
+#/**
+# <s:function group="failures">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>failNotEquals</function></funcdef>
+#       <paramdef>string <parameter>[message]</parameter></paramdef>
+#       <paramdef>string <parameter>expected</parameter></paramdef>
+#       <paramdef>string <parameter>actual</parameter></paramdef>
+#     </funcprototype>
+#   </funcsynopsis>
+#   <para>Fails the test if <emphasis>expected</emphasis> and
+#   <emphasis>actual</emphasis> are <emphasis role="strong">not</emphasis>
+#   equal to one another. The message is optional.</para>
+# </entry>
+# </s:function>
+#*/
+failNotEquals()
+{
+  assertEquals "$@"
+}
+
+#/**
+# <s:function group="failures">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>failSame</function></funcdef>
+#       <paramdef>string <parameter>[message]</parameter></paramdef>
+#       <paramdef>string <parameter>expected</parameter></paramdef>
+#       <paramdef>string <parameter>actual</parameter></paramdef>
+#     </funcprototype>
+#   </funcsynopsis>
+#   <para>Fails the test if <emphasis>expected</emphasis> and
+#   <emphasis>actual</emphasis> are equal to one another. The message is
+#   optional.</para>
+# </entry>
+# </s:function>
+#*/
+failSame()
+{
+  assertNotSame "$@"
+}
+
+#/**
+# <s:function group="failures">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>failNotSame</function></funcdef>
+#       <paramdef>string <parameter>[message]</parameter></paramdef>
+#       <paramdef>string <parameter>expected</parameter></paramdef>
+#       <paramdef>string <parameter>actual</parameter></paramdef>
+#     </funcprototype>
+#   </funcsynopsis>
+#   <para>Fails the test if <emphasis>expected</emphasis> and
+#   <emphasis>actual</emphasis> are equal to one another. The message is
+#   optional.</para>
+# </entry>
+# </s:function>
+#*/
+failNotSame()
+{
+  assertEquals "$@"
+}
+
+#-----------------------------------------------------------------------------
+# skipping functions
+#
+
+#/**
+# <s:function group="skipping">
+# <entry align="right">
+#   <emphasis>void</emphasis>
+# </entry>
+# <entry>
+#   <funcsynopsis>
+#     <funcprototype>
+#       <funcdef><function>startSkipping</function></funcdef>
+#       <paramdef />
+#     </funcprototype>
+#   </funcsynopsis>
<<Diff was trimmed, longer than 597 lines>>


More information about the pld-cvs-commit mailing list