aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-03-11 11:38:02 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-03-11 11:38:02 +0000
commit498e58c79df61064a772ec332c9904848b422d15 (patch)
treedfd13b75657fed1b526c453205d352e665b6c355
parent8fe0374c9bb9f452bced3e139983758218ecf363 (diff)
downloadpaludis-498e58c79df61064a772ec332c9904848b422d15.tar.gz
paludis-498e58c79df61064a772ec332c9904848b422d15.tar.xz
Some rather hacky tests for some ebuild/ things.
-rw-r--r--ebuild/Makefile.am11
-rwxr-xr-xebuild/ebuild.bash2
-rw-r--r--ebuild/echo_functions.bash8
-rw-r--r--ebuild/echo_functions_TEST.bash45
-rw-r--r--ebuild/list_functions.bash12
-rw-r--r--ebuild/list_functions_TEST.bash74
-rw-r--r--ebuild/run_test.bash47
7 files changed, 187 insertions, 12 deletions
diff --git a/ebuild/Makefile.am b/ebuild/Makefile.am
index c279086..838a7d0 100644
--- a/ebuild/Makefile.am
+++ b/ebuild/Makefile.am
@@ -28,5 +28,14 @@ libexecprog_SCRIPTS = \
unpack_functions.bash \
usage_error.bash
-EXTRA_DIST = $(libexecprog_SCRIPTS)
+TESTS_ENVIRONMENT = env \
+ PALUDIS_EBUILD_DIR="$(srcdir)/ebuild/" \
+ TEST_SCRIPT_DIR="$(srcdir)/" \
+ $(SHELL) $(top_srcdir)/ebuild/run_test.bash
+
+TESTS = echo_functions_TEST.bash list_functions_TEST.bash
+EXTRA_DIST = $(libexecprog_SCRIPTS) run_test.bash $(TESTS)
+
+check_SCRIPTS = run_test.bash $(TESTS)
+check_PROGRAMS =
diff --git a/ebuild/ebuild.bash b/ebuild/ebuild.bash
index a052bd1..f513e1f 100755
--- a/ebuild/ebuild.bash
+++ b/ebuild/ebuild.bash
@@ -72,7 +72,7 @@ ebuild_load_ebuild()
[[ ${RDEPEND-unset} == "unset" ]] && RDEPEND="${DEPEND}"
}
-case ${1:x} in
+[[ -n "${PALUDIS_IN_TEST_FRAMEWORK}" ]] || case ${1:x} in
metadata)
for f in cut tr ; do
eval "export ebuild_real_${f}=\"$(which $f )\""
diff --git a/ebuild/echo_functions.bash b/ebuild/echo_functions.bash
index c8a6edf..bc7e190 100644
--- a/ebuild/echo_functions.bash
+++ b/ebuild/echo_functions.bash
@@ -24,18 +24,18 @@
use_with()
{
if useq "${1}" ; then
- echo "--with-${2:1}${3+=${3}}"
+ echo "--with-${2:-${1}}${3+=${3}}"
else
- echo "--without-${2:1}"
+ echo "--without-${2:-${1}}"
fi
}
use_enable()
{
if useq "${1}" ; then
- echo "--enable-${2:1}${3+=${3}}"
+ echo "--enable-${2:-${1}}${3+=${3}}"
else
- echo "--disable-${2:1}"
+ echo "--disable-${2:-${1}}"
fi
}
diff --git a/ebuild/echo_functions_TEST.bash b/ebuild/echo_functions_TEST.bash
new file mode 100644
index 0000000..128474a
--- /dev/null
+++ b/ebuild/echo_functions_TEST.bash
@@ -0,0 +1,45 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.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
+
+use_with_TEST()
+{
+ export USE="foo"
+ test_equality "$(use_with foo )" "--with-foo"
+ test_equality "$(use_with foo bar )" "--with-bar"
+ test_equality "$(use_with foo bar baz )" "--with-bar=baz"
+
+ export USE="oink"
+ test_equality "$(use_with foo )" "--without-foo"
+ test_equality "$(use_with foo bar )" "--without-bar"
+ test_equality "$(use_with foo bar baz )" "--without-bar"
+}
+
+
+use_enable_TEST()
+{
+ export USE="foo"
+ test_equality "$(use_enable foo )" "--enable-foo"
+ test_equality "$(use_enable foo bar )" "--enable-bar"
+ test_equality "$(use_enable foo bar baz )" "--enable-bar=baz"
+
+ export USE="oink"
+ test_equality "$(use_enable foo )" "--disable-foo"
+ test_equality "$(use_enable foo bar )" "--disable-bar"
+ test_equality "$(use_enable foo bar baz )" "--disable-bar"
+}
+
diff --git a/ebuild/list_functions.bash b/ebuild/list_functions.bash
index 8efc1d0..b852ade 100644
--- a/ebuild/list_functions.bash
+++ b/ebuild/list_functions.bash
@@ -23,13 +23,13 @@
use()
{
- useq "${USE}" "${1}"
+ useq "${1}"
}
usev()
{
- if useq "${USE}" "${1}" ; then
- echo "${1}"
+ if useq "${1}" ; then
+ echo "${1#!}"
return 0
else
return 1
@@ -39,9 +39,9 @@ usev()
useq()
{
if [[ "${1:0:1}" == "!" ]] ; then
- ! hasq "${USE}" "${1}"
+ ! hasq "${1#!}" "${USE}"
else
- hasq "${USE}" "${1}"
+ hasq "${1}" "${USE}"
fi
}
@@ -64,7 +64,7 @@ hasq()
{
local x= want="$1"
shift
- for x in "$@" ; do
+ for x in $@ ; do
[[ "${x}" == "${want}" ]] && return 0
done
return 1
diff --git a/ebuild/list_functions_TEST.bash b/ebuild/list_functions_TEST.bash
new file mode 100644
index 0000000..46117c9
--- /dev/null
+++ b/ebuild/list_functions_TEST.bash
@@ -0,0 +1,74 @@
+#!/bin/bash
+# vim: set sw=4 sts=4 et :
+
+# Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.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
+
+use_TEST()
+{
+ export USE="foo bar"
+
+ use foo ; test_return_code
+ use bar ; test_return_code
+ ! use baz ; test_return_code
+ ! use foofoo ; test_return_code
+ ! use fo ; test_return_code
+
+ ! use !foo ; test_return_code
+ ! use !bar ; test_return_code
+ use !baz ; test_return_code
+ use !foofoo ; test_return_code
+ use !fo ; test_return_code
+}
+
+usev_TEST()
+{
+ export USE="foo bar"
+ usev foo 1>/dev/null ; test_return_code
+ test_equality "$(usev foo)" "foo"
+
+ usev bar 1>/dev/null ; test_return_code
+ test_equality "$(usev bar)" "bar"
+
+ ! usev baz 1>/dev/null ; test_return_code
+ test_equality "$(usev baz)" ""
+
+ ! usev !foo 1>/dev/null ; test_return_code
+ test_equality "$(usev !foo)" ""
+
+ ! usev !bar 1>/dev/null ; test_return_code
+ test_equality "$(usev !bar)" ""
+
+ ! usev baz 1>/dev/null ; test_return_code
+ test_equality "$(usev !baz)" "baz"
+}
+
+useq_TEST()
+{
+ export USE="foo bar"
+
+ useq foo ; test_return_code
+ useq bar ; test_return_code
+ ! useq baz ; test_return_code
+ ! useq foofoo ; test_return_code
+ ! useq fo ; test_return_code
+
+ ! useq !foo ; test_return_code
+ ! useq !bar ; test_return_code
+ useq !baz ; test_return_code
+ useq !foofoo ; test_return_code
+ useq !fo ; test_return_code
+}
+
diff --git a/ebuild/run_test.bash b/ebuild/run_test.bash
new file mode 100644
index 0000000..b5587b9
--- /dev/null
+++ b/ebuild/run_test.bash
@@ -0,0 +1,47 @@
+#!/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
+}
+
+echo "Test program ${1}:"
+source "$(dirname ${1} )/ebuild.bash" || exit 200
+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
+
+[[ -z "$TEST_STATUS" ]]
+