aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2018-09-30 19:57:52 +0200
committerMichał Górny <mgorny@gentoo.org>2019-04-09 13:05:55 +0200
commit6149e0a69a06f25328b4954505ab317b5d7b1287 (patch)
tree15a47055c99dc64c1587890d9d44e789ff20823e
parentAdd a runner for all tests (diff)
downloadgithooks-6149e0a69a06f25328b4954505ab317b5d7b1287.tar.gz
githooks-6149e0a69a06f25328b4954505ab317b5d7b1287.tar.bz2
githooks-6149e0a69a06f25328b4954505ab317b5d7b1287.zip
update-04-utf8: Add tests
Signed-off-by: Michał Górny <mgorny@gentoo.org>
-rwxr-xr-xlocal/tests/run-all.sh1
-rwxr-xr-xlocal/tests/update-04-utf8.sh37
2 files changed, 38 insertions, 0 deletions
diff --git a/local/tests/run-all.sh b/local/tests/run-all.sh
index b51b6e2..117f210 100755
--- a/local/tests/run-all.sh
+++ b/local/tests/run-all.sh
@@ -6,6 +6,7 @@
. /lib/gentoo/functions.sh
TESTS=(
+ update-04-utf8.sh
update-05-manifest.sh
update-06-copyright.sh
)
diff --git a/local/tests/update-04-utf8.sh b/local/tests/update-04-utf8.sh
new file mode 100755
index 0000000..f471948
--- /dev/null
+++ b/local/tests/update-04-utf8.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+# Tests for update-04-utf8 hook
+# Copyright 2018 Michał Górny
+# Distributed under the terms of the GNU General Public License v2 or later
+
+. "${BASH_SOURCE%/*}"/lib.sh
+HOOK_PATH=${BASH_SOURCE%/*}/../update-04-utf8
+[[ ${HOOK_PATH} == /* ]] || HOOK_PATH=${PWD}/${HOOK_PATH}
+
+FAIL_MSG="Commit * contains invalid UTF-8 in the commit metadata"
+
+export GIT_COMMITTER_NAME='UTF-8 Guy ĄĆĘŁŃÓŚŹŻ'
+export GIT_COMMITTER_EMAIL='utf8@example.com'
+export GIT_AUTHOR_NAME=${GIT_COMMITTER_NAME}
+export GIT_AUTHOR_EMAIL=${GIT_COMMITTER_EMAIL}
+
+tbegin "Testing valid UTF-8 commit"
+git commit -q --allow-empty -m "Valid UTF-8: ąćęłńóśźż"
+test_success
+
+tbegin "Testing commit with invalid UTF-8 in commit message"
+git -c i18n.commitencoding=iso-8859-2 commit -q --allow-empty -m $'Invalid UTF-8: \261\346'
+test_failure "${FAIL_MSG}"
+
+tbegin "Testing commit with invalid UTF-8 in committer's name"
+export GIT_COMMITTER_NAME=$'ISO-8859-2 guy \261\346'
+git -c i18n.commitencoding=iso-8859-2 commit -q --allow-empty -m "Some message"
+test_failure "${FAIL_MSG}"
+export GIT_COMMITTER_NAME=${GIT_AUTHOR_NAME}
+
+tbegin "Testing commit with invalid UTF-8 in author's name"
+export GIT_AUTHOR_NAME=$'ISO-8859-2 guy \261\346'
+git -c i18n.commitencoding=iso-8859-2 commit -q --allow-empty -m "Some message"
+test_failure "${FAIL_MSG}"
+export GIT_AUTHOR_NAME=${GIT_COMMITTER_NAME}
+
+exit "${TEST_RET}"