summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2014-12-21 15:46:37 +0100
committerAllan McRae <allan@archlinux.org>2015-01-11 09:58:24 +0100
commitca5af32b9931172387cf3df47cece22bf1523186 (patch)
treed62425ceb16514caaa6c36d4f71dbc965b4f232f /test
parentf617b6acd4e33586819ac5728825cbdcac12f042 (diff)
downloadpacman-ca5af32b9931172387cf3df47cece22bf1523186.tar.gz
pacman-ca5af32b9931172387cf3df47cece22bf1523186.tar.xz
Add testrunner for makepkg-template
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'test')
-rw-r--r--test/scripts/Makefile.am1
-rw-r--r--test/scripts/makepkg-template-tests/testcase-config-template9
-rwxr-xr-xtest/scripts/makepkg-template_test.sh67
3 files changed, 77 insertions, 0 deletions
diff --git a/test/scripts/Makefile.am b/test/scripts/Makefile.am
index 8d6bc842..ed1a9511 100644
--- a/test/scripts/Makefile.am
+++ b/test/scripts/Makefile.am
@@ -1,6 +1,7 @@
check_SCRIPTS = \
parseopts_test.sh \
pacman-db-upgrade-v9.py \
+ makepkg-template_test.sh \
human_to_size_test.sh
noinst_SCRIPTS = $(check_SCRIPTS)
diff --git a/test/scripts/makepkg-template-tests/testcase-config-template b/test/scripts/makepkg-template-tests/testcase-config-template
new file mode 100644
index 00000000..66267d3b
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/testcase-config-template
@@ -0,0 +1,9 @@
+arguments+=()
+expected_exitcode=0
+
+# set IFS="" if you want trailing new line(s), otherwise remove it
+IFS="" read -d '' expected_output <<'EOF'
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+EOF
diff --git a/test/scripts/makepkg-template_test.sh b/test/scripts/makepkg-template_test.sh
new file mode 100755
index 00000000..b2531d4a
--- /dev/null
+++ b/test/scripts/makepkg-template_test.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+source "$(dirname "$0")"/../tap.sh || exit 1
+
+script=${1:-${PMTEST_SCRIPT_DIR}makepkg-template}
+
+if ! type -p "$script" &>/dev/null; then
+ tap_bail "makepkg-template executable (%s) could not be located" "${script}"
+ exit 1
+fi
+
+TMPDIR="$(mktemp -d "/tmp/${0##*/}.XXXXXX")"
+trap "rm -rf '${TMPDIR}'" EXIT TERM
+cp -r "${0%/*}/makepkg-template-tests" "$TMPDIR/makepkg-template-tests"
+
+# normalize paths
+script="$(readlink -f $(type -p "$script"))"
+cd "$TMPDIR"
+testdir="./makepkg-template-tests"
+
+
+total=$(find "$testdir" -maxdepth 1 -mindepth 1 -type d | wc -l)
+if [[ -z "$total" ]]; then
+ tap_bail "unable to determine total number of tests"
+ exit 1
+fi
+tap_plan "$((total*3))"
+
+run_test() {
+ local testcase=$1 exitcode expected_result expected_output
+ local -a arguments
+ local -i expected_exitcode=-1
+
+ [[ -f "$testdir/$testcase/testcase-config" ]] || continue
+ source "$testdir/$testcase/testcase-config"
+
+ mkdir "$TMPDIR/$testcase"
+ touch "$TMPDIR/$testcase/result"
+
+ # work around autotools not putting symlinks into the release tarball
+ [[ -d "$TMPDIR/$testdir/$testcase/templates" ]] || mkdir "$TMPDIR/$testdir/$testcase/templates"
+ if type -t _setup_testcase >/dev/null; then
+ cd "$TMPDIR/$testdir/$testcase"
+ _setup_testcase
+ unset -f _setup_testcase
+ cd "$TMPDIR"
+ fi
+
+ LC_ALL=C "$script" \
+ --template-dir "$testdir/$testcase/templates" \
+ -p "$testdir/$testcase/PKGBUILD" \
+ -o "$TMPDIR/$testcase/result" \
+ &> "$TMPDIR/$testcase/output" "${arguments[@]}"
+ exitcode=$?
+
+ tap_is_int "$exitcode" "$expected_exitcode" "$testcase exitcode"
+ tap_diff "$TMPDIR/$testcase/output" <(printf "%s" "$expected_output") "$testcase output"
+ tap_diff "$TMPDIR/$testcase/result" <(printf "%s" "$expected_result") "$testcase resulting PKGBUILD"
+}
+
+for dir in "$testdir/"*; do
+ if [[ -d "$dir" ]]; then
+ run_test "${dir##*/}"
+ fi
+done
+
+tap_finish