aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2018-11-01 21:58:04 +0100
committerMichał Górny <mgorny@gentoo.org>2019-04-09 13:05:55 +0200
commit01c76c6978bc0b2a667fd35cae150600ace1ea50 (patch)
treeade1f9fb04e0e41b0f53f437235383ff31b2b863 /local/tests
parentupdate-06-copyright: Allow for comments in S-o-b (diff)
downloadgithooks-01c76c6978bc0b2a667fd35cae150600ace1ea50.tar.gz
githooks-01c76c6978bc0b2a667fd35cae150600ace1ea50.tar.bz2
githooks-01c76c6978bc0b2a667fd35cae150600ace1ea50.zip
update-06-copyright: Support new/removed branches better
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'local/tests')
-rw-r--r--local/tests/lib.sh54
-rwxr-xr-xlocal/tests/update-06-copyright.sh36
2 files changed, 90 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 |= ${?} ))
+}
diff --git a/local/tests/update-06-copyright.sh b/local/tests/update-06-copyright.sh
index 0e0d3be..0b93044 100755
--- a/local/tests/update-06-copyright.sh
+++ b/local/tests/update-06-copyright.sh
@@ -343,4 +343,40 @@ test_failure "${FAIL_NO_SIGNOFF}"
eoutdent
+einfo "Branch addition / removal tests"
+eindent
+
+tbegin "Forked branch with sign-off present"
+git checkout -q -b test-branch
+git commit --allow-empty -m "Commit with sign-off
+
+Signed-off-by: ${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>" -q
+test_branch_success test-branch
+
+tbegin "Forked branch with new non-signed commit"
+git checkout -q -b test-branch
+git commit --allow-empty -m "Commit without sign-off" -q
+test_branch_failure test-branch "${FAIL_NO_SIGNOFF}"
+
+tbegin "Copy of master branch"
+git checkout -q -b test-branch
+test_branch_success test-branch
+
+tbegin "New independent branch with sign-off"
+git checkout --orphan test-branch -q
+git commit --allow-empty -m "Commit with sign-off
+
+Signed-off-by: ${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>" -q
+test_branch_success test-branch
+
+tbegin "New independent branch without sign-off"
+git checkout --orphan test-branch -q
+git commit --allow-empty -m "Commit without sign-off" -q
+test_branch_failure test-branch "${FAIL_NO_SIGNOFF}"
+
+tbegin "Branch removal"
+test_branch_removal
+
+eoutdent
+
exit "${TEST_RET}"