summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'local/tests/lib.sh')
-rw-r--r--local/tests/lib.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/local/tests/lib.sh b/local/tests/lib.sh
index 12160a7..cd6543d 100644
--- a/local/tests/lib.sh
+++ b/local/tests/lib.sh
@@ -50,6 +50,18 @@ run_test() {
)
}
+# Run the test for specified branch, presuming it's a new branch.
+# $1 - branch name
+run_test_branch() {
+ local branch=${1}
+
+ (
+ set -- "refs/heads/${branch}" 0000000000000000000000000000000000000000 HEAD
+ set +e
+ . "${HOOK_PATH}"
+ )
+}
+
# Run the hook for all commits since the initial commit.
# Expect success.
test_success() {
@@ -58,6 +70,16 @@ test_success() {
: $(( TEST_RET |= ${?} ))
}
+# Run the hook presuming new branch is added.
+# Expect success.
+# $1 - branch name
+test_branch_success() {
+ local branch=${1}
+ run_test_branch "${branch}"
+ tend ${?}
+ : $(( TEST_RET |= ${?} ))
+}
+
# Run the hook for all commits since the initial commit.
# Expect failure with message matching the pattern.
# $1 - bash pattern to match
@@ -74,3 +96,35 @@ test_failure() {
tend ${?} "'${msg}' != '${expected}'"
: $(( TEST_RET |= ${?} ))
}
+
+# Run the hook presuming new branch is added.
+# Expect failure with message matching the pattern.
+# $1 - branch name
+# $2 - bash pattern to match
+test_branch_failure() {
+ local branch=${1}
+ local expected=${2}
+ local msg
+
+ if msg=$(run_test_branch "${branch}"); then
+ tend 1 "Hook unexpectedly succeeded"
+ return 1
+ fi
+
+ [[ ${msg} == ${expected} ]]
+ tend ${?} "'${msg}' != '${expected}'"
+ : $(( TEST_RET |= ${?} ))
+}
+
+# Run the hook presuming branch is being removed.
+# Expect success (our hooks shouldn't prevent removal).
+test_branch_removal() {
+ (
+ set -- "refs/heads/removed-branch" HEAD 0000000000000000000000000000000000000000
+ set +e
+ . "${HOOK_PATH}"
+ )
+
+ tend ${?}
+ : $(( TEST_RET |= ${?} ))
+}