Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/test/scripts/makepkg-template_test.sh
blob: b2531d4a7e9a0e042b36ec84557e9d8b03d1707a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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