aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2018-09-29 11:51:15 +0200
committerMichał Górny <mgorny@gentoo.org>2019-04-09 13:05:55 +0200
commitaa5e79362796919573a0841a691107f0c52a3e41 (patch)
treeb69b3e28fe76f8962511d11d391913704d3edcd1 /local/tests
parentupdate-05-manifest: Add tests (diff)
downloadgithooks-aa5e79362796919573a0841a691107f0c52a3e41.tar.gz
githooks-aa5e79362796919573a0841a691107f0c52a3e41.tar.bz2
githooks-aa5e79362796919573a0841a691107f0c52a3e41.zip
Add a runner for all tests
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'local/tests')
-rw-r--r--local/tests/lib.sh6
-rwxr-xr-xlocal/tests/run-all.sh25
-rwxr-xr-xlocal/tests/update-05-manifest.sh2
-rwxr-xr-xlocal/tests/update-06-copyright.sh2
4 files changed, 34 insertions, 1 deletions
diff --git a/local/tests/lib.sh b/local/tests/lib.sh
index 8ecefdf..12160a7 100644
--- a/local/tests/lib.sh
+++ b/local/tests/lib.sh
@@ -3,13 +3,15 @@
# Copyright 2018 Michał Górny
# Distributed under the terms of the GNU General Public License v2 or later
-. /lib/gentoo/functions.sh
+[[ -z ${RC_GOT_FUNCTIONS} ]] && . /lib/gentoo/functions.sh
die() {
echo "died @ ${BASH_SOURCE[1]}:${BASH_LINENO[0]}" >&2
exit 1
}
+TEST_RET=0
+
# Starts a test. Creates temporary git repo and enters it.
# $1 - test description (printed)
tbegin() {
@@ -53,6 +55,7 @@ run_test() {
test_success() {
run_test
tend ${?}
+ : $(( TEST_RET |= ${?} ))
}
# Run the hook for all commits since the initial commit.
@@ -69,4 +72,5 @@ test_failure() {
[[ ${msg} == ${expected} ]]
tend ${?} "'${msg}' != '${expected}'"
+ : $(( TEST_RET |= ${?} ))
}
diff --git a/local/tests/run-all.sh b/local/tests/run-all.sh
new file mode 100755
index 0000000..b51b6e2
--- /dev/null
+++ b/local/tests/run-all.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+# Tests for git hooks
+# Copyright 2018 Michał Górny
+# Distributed under the terms of the GNU General Public License v2 or later
+
+. /lib/gentoo/functions.sh
+
+TESTS=(
+ update-05-manifest.sh
+ update-06-copyright.sh
+)
+
+ret=0
+for t in "${TESTS[@]}"; do
+ einfo "${t} tests:"
+ eindent
+ (
+ . "${BASH_SOURCE%/*}/${t}"
+ )
+ : $(( ret |= ${?} ))
+ eoutdent
+done
+
+[[ ${ret} -eq 0 ]] || eerror "Some of the tests failed."
+exit "${ret}"
diff --git a/local/tests/update-05-manifest.sh b/local/tests/update-05-manifest.sh
index 4be7cfd..1597092 100755
--- a/local/tests/update-05-manifest.sh
+++ b/local/tests/update-05-manifest.sh
@@ -48,3 +48,5 @@ test_failure "${FAIL_HASH}"
tbegin "Testing empty checksum set"
make_manifest "DIST empty.file 0"
test_failure "${FAIL_HASH}"
+
+exit "${TEST_RET}"
diff --git a/local/tests/update-06-copyright.sh b/local/tests/update-06-copyright.sh
index 1ffc1d3..a8816e0 100755
--- a/local/tests/update-06-copyright.sh
+++ b/local/tests/update-06-copyright.sh
@@ -336,3 +336,5 @@ git merge -q -m "Test merge commit" -q test-branch
test_failure "${FAIL_NO_SIGNOFF}"
eoutdent
+
+exit "${TEST_RET}"