summaryrefslogtreecommitdiff
path: root/t/test-lib-functions.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-12-05 20:52:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-12-05 20:52:48 (GMT)
commite0f9ec90278ec989ac7840a69f42a414f0db23f5 (patch)
treeda196a1d49be6527919614e004f0090a9ffef590 /t/test-lib-functions.sh
parentfd952307ec2a260b1ed668d56f1a4cf3569baee3 (diff)
parenta85efb598565718a06e560eb3f1ca038f6f3cd39 (diff)
downloadgit-e0f9ec90278ec989ac7840a69f42a414f0db23f5.zip
git-e0f9ec90278ec989ac7840a69f42a414f0db23f5.tar.gz
git-e0f9ec90278ec989ac7840a69f42a414f0db23f5.tar.bz2
Merge branch 'sg/test-bool-env'
Recently we have declared that GIT_TEST_* variables take the usual boolean values (it used to be that some used "non-empty means true" and taking GIT_TEST_VAR=YesPlease as true); make sure we notice and fail when non-bool strings are given to these variables. * sg/test-bool-env: t5608-clone-2gb.sh: turn GIT_TEST_CLONE_2GB into a bool tests: add 'test_bool_env' to catch non-bool GIT_TEST_* values
Diffstat (limited to 't/test-lib-functions.sh')
-rw-r--r--t/test-lib-functions.sh30
1 files changed, 29 insertions, 1 deletions
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index efcd96f..dc7a041 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1186,6 +1186,34 @@ perl () {
command "$PERL_PATH" "$@" 2>&7
} 7>&2 2>&4
+# Given the name of an environment variable with a bool value, normalize
+# its value to a 0 (true) or 1 (false or empty string) return code.
+#
+# test_bool_env GIT_TEST_HTTPD <default-value>
+#
+# Return with code corresponding to the given default value if the variable
+# is unset.
+# Abort the test script if either the value of the variable or the default
+# are not valid bool values.
+
+test_bool_env () {
+ if test $# != 2
+ then
+ BUG "test_bool_env requires two parameters (variable name and default value)"
+ fi
+
+ git env--helper --type=bool --default="$2" --exit-code "$1"
+ ret=$?
+ case $ret in
+ 0|1) # unset or valid bool value
+ ;;
+ *) # invalid bool value or something unexpected
+ error >&7 "test_bool_env requires bool values both for \$$1 and for the default fallback"
+ ;;
+ esac
+ return $ret
+}
+
# Exit the test suite, either by skipping all remaining tests or by
# exiting with an error. If our prerequisite variable $1 falls back
# on a default assume we were opportunistically trying to set up some
@@ -1194,7 +1222,7 @@ perl () {
# The error/skip message should be given by $2.
#
test_skip_or_die () {
- if ! git env--helper --type=bool --default=false --exit-code $1
+ if ! test_bool_env "$1" false
then
skip_all=$2
test_done