[pacman-dev] [PATCH v4 01/11] Add testrunner for makepkg-template
Andrew Gregory
andrew.gregory.8 at gmail.com
Sun Dec 28 16:15:54 UTC 2014
On 12/28/14 at 04:23pm, Florian Pritz wrote:
> Signed-off-by: Florian Pritz <bluewind at xinu.at>
> ---
>
> v4:
> - adjusted to tap.sh
> - move expected output/result/exitcode/arguments into a single file called
> testcase-config
> - removed line number removal code (depends on "[PATCH] makepkg-template:
> Remove linenumber/file from errors" to be merged)
> - normalize paths by cd'ing into the testdir rather than using sed
>
> The test files are simply adjusted to the changes to the main script, but I
> hope this is the last iteration so I'm posting them again for context.
>
> Makefile.am | 2 +
> test/scripts/Makefile.am | 1 +
> .../testcase-config-template | 9 ++++
> test/scripts/makepkg-template_test.sh | 52 ++++++++++++++++++++++
> 4 files changed, 64 insertions(+)
> create mode 100644 test/scripts/makepkg-template-tests/testcase-config-template
> create mode 100755 test/scripts/makepkg-template_test.sh
>
> diff --git a/Makefile.am b/Makefile.am
> index 01ea4f1..9dbacca 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -28,6 +28,7 @@ $(top_srcdir)/test/pacman/tests/TESTS: $(wildcard test/pacman/tests/*.py*)
>
> TESTS = test/scripts/parseopts_test.sh \
> test/scripts/human_to_size_test.sh \
> + test/scripts/makepkg-template_test.sh \
> test/scripts/pacman-db-upgrade-v9.py \
> test/util/pacsorttest.sh \
> test/util/vercmptest.sh
> @@ -37,6 +38,7 @@ TEST_SUITE_LOG = test/test-suite.log
> TEST_EXTENSIONS = .py
> AM_TESTS_ENVIRONMENT = \
> PMTEST_UTIL_DIR=$(top_builddir)/src/util/; export PMTEST_UTIL_DIR; \
> + PMTEST_SCRIPT_DIR=$(top_srcdir)/scripts/; export PMTEST_SCRIPT_DIR; \
> PMTEST_SCRIPTLIB_DIR=$(top_srcdir)/scripts/library/; export PMTEST_SCRIPTLIB_DIR;
> LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
> $(top_srcdir)/build-aux/tap-driver.sh
> diff --git a/test/scripts/Makefile.am b/test/scripts/Makefile.am
> index 8d6bc84..ed1a951 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 0000000..66267d3
> --- /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 0000000..34185db
> --- /dev/null
> +++ b/test/scripts/makepkg-template_test.sh
> @@ -0,0 +1,52 @@
> +#!/bin/bash
> +
> +source "$(dirname "$0")"/../tap.sh || exit 1
> +
> +# source the library function
This comment does not apply here.
> +script=$(readlink -f "${1:-${PMTEST_SCRIPT_DIR}/makepkg-template}")
This doesn't match our other test scripts which all fall back to
looking for the program in PATH.
> +if [[ -z $script || ! -f $script ]]; then
> + tap_bail "makepkg-template executable (%s) could not be located" "${script}"
> + exit 1
> +fi
> +
> +# normalize paths
> +cd "${0%/*}"
> +testdir="./makepkg-template-tests"
> +
> +TMPDIR="$(mktemp -d "/tmp/${0##*/}.XXXXXX")"
> +trap "rm -rf '${TMPDIR}'" EXIT TERM
> +
> +total=$(find "$testdir" -maxdepth 1 -mindepth 1 -type d | wc -l)
> +[[ -n "$total" ]] || tap_bail "unable to determine total number of tests"
You need to exit after tap_bail.
> +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"
> +
> + 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
> --
> 2.2.1
More information about the pacman-dev
mailing list