aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-08-05 22:49:45 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-08-05 22:49:45 +0000
commitfa795299a47ba9a18fe64f8658bd385bcbf89673 (patch)
treeb54d66a7f77f75dcde9f85ba32f208ec9a816a4e
parent89f01d416743eefebe4a20c8f850818c0db42116 (diff)
downloadpaludis-fa795299a47ba9a18fe64f8658bd385bcbf89673.tar.gz
paludis-fa795299a47ba9a18fe64f8658bd385bcbf89673.tar.xz
Test some of our hooks
-rw-r--r--hooks/Makefile.am.m433
-rwxr-xr-xhooks/eselect_env_update_TEST30
-rwxr-xr-xhooks/eselect_env_update_TEST_cleanup.sh9
-rwxr-xr-xhooks/eselect_env_update_TEST_setup.sh14
-rwxr-xr-xhooks/news_TEST42
-rwxr-xr-xhooks/news_TEST_cleanup.sh9
-rwxr-xr-xhooks/news_TEST_setup.sh53
-rwxr-xr-xhooks/run_test.bash63
8 files changed, 244 insertions, 9 deletions
diff --git a/hooks/Makefile.am.m4 b/hooks/Makefile.am.m4
index 9d70a1f..a97ffe0 100644
--- a/hooks/Makefile.am.m4
+++ b/hooks/Makefile.am.m4
@@ -32,21 +32,22 @@ installhookinstallpost_SCRIPTS = \
installvarlibpaludisnews_DATA = \
.keep
-TESTS_ENVIRONMENT = env \
- PALUDIS_EBUILD_DIR="$(srcdir)/ebuild/" \
- TEST_SCRIPT_DIR="$(srcdir)/" \
- bash $(top_srcdir)/ebuild/run_test.bash
+TESTS = \
+ eselect_env_update_TEST \
+ news_TEST
+
+check_SCRIPTS = $(TESTS) run_test.bash \
+ eselect_env_update_TEST_setup.sh eselect_env_update_TEST_cleanup.sh \
+ news_TEST_setup.sh news_TEST_cleanup.sh
+
+check_PROGRAMS =
-TESTS =
EXTRA_DIST = \
Makefile.am.m4 \
$(installhookcommonprog_SCRIPTS) \
$(installhookinstallallpost_SCRIPTS) \
$(installhookinstallpost_SCRIPTS) \
- $(TESTS)
-
-check_SCRIPTS = $(TESTS)
-check_PROGRAMS =
+ $(check_SCRIPTS)
.keep :
touch $@
@@ -269,4 +270,18 @@ changequote(`<', `>')
built-sources : $(BUILT_SOURCES)
for s in `echo $(SUBDIRS) | tr -d .` ; do $(MAKE) -C $$s built-sources || exit 1 ; done
+TESTS_ENVIRONMENT = env \
+ TEST_SCRIPT_DIR="$(srcdir)/" \
+ PATH="${PATH}:/sbin:/usr/sbin" \
+ PALUDIS_COMMAND="$(top_builddir)/src/clients/paludis/paludis" \
+ PALUDIS_HOOKER_DIR="$(top_srcdir)/paludis/" \
+ PALUDIS_OUTPUTWRAPPER_DIR="`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/util/`" \
+ PALUDIS_EBUILD_DIR="$(top_srcdir)/paludis/repositories/e/ebuild/" \
+ PALUDIS_EAPIS_DIR="$(top_srcdir)/paludis/repositories/e/eapis/" \
+ PALUDIS_DISTRIBUTIONS_DIR="$(top_srcdir)/paludis/distributions/" \
+ PALUDIS_DISTRIBUTION="gentoo" \
+ PALUDIS_SKIP_CONFIG="yes" \
+ PALUDIS_REPOSITORY_SO_DIR="$(top_builddir)/paludis/repositories" \
+ PALUDIS_ENVIRONMENT_SO_DIR="`$(top_srcdir)/paludis/repositories/e/ebuild/utils/canonicalise $(top_builddir)/paludis/environments`" \
+ bash $(top_srcdir)/hooks/run_test.bash
diff --git a/hooks/eselect_env_update_TEST b/hooks/eselect_env_update_TEST
new file mode 100755
index 0000000..8a03f7f
--- /dev/null
+++ b/hooks/eselect_env_update_TEST
@@ -0,0 +1,30 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+# Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+#
+# This file is part of the Paludis package manager. Paludis is free software;
+# you can redistribute it and/or modify it under the terms of the GNU General
+# Public License version 2, as published by the Free Software Foundation.
+#
+# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+
+eselect_env_update_TEST()
+{
+ export ROOT=`pwd`/eselect_env_update_TEST_dir
+ export PALUDIS_LIVE_DESTINATION=
+ mkdir -p eselect_env_update_TEST_dir/{etc,lib}
+ touch eselect_env_update_TEST_dir/etc/ld.so.conf
+
+ ./eselect_env_update.bash >/dev/null ; test_return_code
+
+ [[ -f eselect_env_update_TEST_dir/etc/ld.so.cache ]] ; test_return_code
+}
+
diff --git a/hooks/eselect_env_update_TEST_cleanup.sh b/hooks/eselect_env_update_TEST_cleanup.sh
new file mode 100755
index 0000000..7b558f8
--- /dev/null
+++ b/hooks/eselect_env_update_TEST_cleanup.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d eselect_env_update_TEST_dir ] ; then
+ rm -fr eselect_env_update_TEST_dir
+else
+ true
+fi
+
diff --git a/hooks/eselect_env_update_TEST_setup.sh b/hooks/eselect_env_update_TEST_setup.sh
new file mode 100755
index 0000000..b47f142
--- /dev/null
+++ b/hooks/eselect_env_update_TEST_setup.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir -p eselect_env_update_TEST_dir || exit 1
+cd eselect_env_update_TEST_dir || exit 1
+
+mkdir -p {etc/env.d,lib,tmp}
+touch etc/ld.so.conf
+cat <<END > etc/env.d/00basic
+LDPATH="/lib"
+END
+
+cd ..
+
diff --git a/hooks/news_TEST b/hooks/news_TEST
new file mode 100755
index 0000000..02b39cf
--- /dev/null
+++ b/hooks/news_TEST
@@ -0,0 +1,42 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+# Copyright (c) 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
+#
+# This file is part of the Paludis package manager. Paludis is free software;
+# you can redistribute it and/or modify it under the terms of the GNU General
+# Public License version 2, as published by the Free Software Foundation.
+#
+# Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place, Suite 330, Boston, MA 02111-1307 USA
+
+news_none_TEST()
+{
+ export ROOT=`pwd`/news_TEST_dir
+ export PALUDIS_LIVE_DESTINATION=
+ export HOOK=sync_all_post
+ export PALUDIS_HOME=`pwd`/news_TEST_dir/one
+
+ bash ${PALUDIS_HOOKER_DIR}/hooker.bash ./news.hook hook_run_sync_all_post >/dev/null ; test_return_code
+ bash ${PALUDIS_HOOKER_DIR}/hooker.bash ./news.hook hook_run_sync_all_post \
+ | grep "No unread news items found" >/dev/null ; test_return_code
+}
+
+news_one_TEST()
+{
+ export ROOT=`pwd`/news_TEST_dir
+ export PALUDIS_LIVE_DESTINATION=
+ export HOOK=sync_all_post
+ export PALUDIS_HOME=`pwd`/news_TEST_dir/two
+
+ bash ${PALUDIS_HOOKER_DIR}/hooker.bash ./news.hook hook_run_sync_all_post >/dev/null ; test_return_code
+ bash ${PALUDIS_HOOKER_DIR}/hooker.bash ./news.hook hook_run_sync_all_post \
+ | grep "You have 1 unread news item" >/dev/null ; test_return_code
+}
+
diff --git a/hooks/news_TEST_cleanup.sh b/hooks/news_TEST_cleanup.sh
new file mode 100755
index 0000000..78aa2cc
--- /dev/null
+++ b/hooks/news_TEST_cleanup.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+if [ -d news_TEST_dir ] ; then
+ rm -fr news_TEST_dir
+else
+ true
+fi
+
diff --git a/hooks/news_TEST_setup.sh b/hooks/news_TEST_setup.sh
new file mode 100755
index 0000000..ceccb99
--- /dev/null
+++ b/hooks/news_TEST_setup.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+# vim: set ft=sh sw=4 sts=4 et :
+
+mkdir -p news_TEST_dir || exit 1
+cd news_TEST_dir || exit 1
+
+mkdir -p one/.paludis/repositories/ || exit 1
+
+cat <<END > one/.paludis/repositories/one.conf
+location = `pwd`/repo1
+cache = /var/empty
+format = ebuild
+names_cache = /var/empty
+profiles = \${location}/profiles/testprofile
+END
+
+mkdir -p two/.paludis/repositories/ || exit 1
+
+cat <<END > two/.paludis/repositories/one.conf
+location = `pwd`/repo1
+cache = /var/empty
+format = ebuild
+names_cache = /var/empty
+profiles = \${location}/profiles/testprofile
+END
+
+cat <<END > two/.paludis/repositories/two.conf
+location = `pwd`/repo2
+cache = /var/empty
+format = ebuild
+names_cache = /var/empty
+profiles = \${location}/profiles/testprofile
+END
+
+mkdir -p var/lib/paludis/news
+cat <<END > var/lib/paludis/news/news-one.read
+END
+cat <<END > var/lib/paludis/news/news-one.unread
+END
+cat <<END > var/lib/paludis/news/news-two.read
+END
+cat <<END > var/lib/paludis/news/news-two.unread
+monkey
+END
+
+mkdir -p repo1/profiles/testprofile
+echo one > repo1/profiles/repo_name
+
+mkdir -p repo2/profiles/testprofile
+echo two > repo2/profiles/repo_name
+
+cd ..
+
diff --git a/hooks/run_test.bash b/hooks/run_test.bash
new file mode 100755
index 0000000..9a0d453
--- /dev/null
+++ b/hooks/run_test.bash
@@ -0,0 +1,63 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+shopt -s expand_aliases
+shopt -s extglob
+set +o posix
+
+export TEST_STATUS=
+export PALUDIS_IN_TEST_FRAMEWORK="yes"
+
+test_return_code()
+{
+ local r="$?"
+ if [[ "0" == "${r}" ]] ; then
+ echo -n "."
+ else
+ echo -n "!{retcode: ${r}}"
+ export local_test_status="fail"
+ export TEST_STATUS="fail"
+ fi
+}
+
+test_equality()
+{
+ if [[ "${1}" == "${2}" ]] ; then
+ echo -n "."
+ else
+ echo -n "!{'${1}' not equal to '${2}'}"
+ export local_test_status="fail"
+ export TEST_STATUS="fail"
+ fi
+}
+
+if test -f "$TEST_SCRIPT_DIR""${1%.bash}"_"setup.sh" ; then
+ echo ">>> setup for test ${1%.bash}"
+ if ! "$TEST_SCRIPT_DIR""${1%.bash}"_"setup.sh" ; then
+ echo ">>> exiting with error for test ${1%.bash}"
+ exit 255
+ fi
+fi
+
+echo "Test program ${1%.bash}:"
+source "${1}" || exit 200
+
+for testname in $(set | grep '_TEST *() *$' ) ; do
+ [[ ${testname/()} != ${testname} ]] && continue
+ echo -n "* ${testname%_TEST}: "
+ export local_test_status=""
+ ${testname}
+ [[ -z "$local_test_status" ]] && echo " OK" || echo " FAIL"
+done
+
+if test -f "$TEST_SCRIPT_DIR""${1%.bash}"_"cleanup.sh" ; then
+ echo ">>> cleanup for test ${1%.bash}"
+ if ! "$TEST_SCRIPT_DIR""${1%.bash}"_"cleanup.sh" ; then
+ echo ">>> exiting with error for test ${1%.bash}"
+ exit 255
+ fi
+fi
+
+[[ -z "$TEST_STATUS" ]]
+
+