Merge branch 'ab/test-env'

Many GIT_TEST_* environment variables control various aspects of
how our tests are run, but a few followed "non-empty is true, empty
or unset is false" while others followed the usual "there are a few
ways to spell true, like yes, on, etc., and also ways to spell
false, like no, off, etc." convention.

* ab/test-env:
  env--helper: mark a file-local symbol as static
  tests: make GIT_TEST_FAIL_PREREQS a boolean
  tests: replace test_tristate with "git env--helper"
  tests README: re-flow a previously changed paragraph
  tests: make GIT_TEST_GETTEXT_POISON a boolean
  t6040 test: stop using global "script" variable
  config.c: refactor die_bad_number() to not call gettext() early
  env--helper: new undocumented builtin wrapping git_env_*()
  config tests: simplify include cycle test
This commit is contained in:
Junio C Hamano
2019-07-25 13:59:20 -07:00
24 changed files with 298 additions and 127 deletions

View File

@ -309,7 +309,7 @@ test_unset_prereq () {
}
test_set_prereq () {
if test -n "$GIT_TEST_FAIL_PREREQS"
if test -n "$GIT_TEST_FAIL_PREREQS_INTERNAL"
then
case "$1" in
# The "!" case is handled below with
@ -1050,62 +1050,20 @@ perl () {
command "$PERL_PATH" "$@" 2>&7
} 7>&2 2>&4
# Is the value one of the various ways to spell a boolean true/false?
test_normalize_bool () {
git -c magic.variable="$1" config --bool magic.variable 2>/dev/null
}
# Given a variable $1, normalize the value of it to one of "true",
# "false", or "auto" and store the result to it.
#
# test_tristate GIT_TEST_HTTPD
#
# A variable set to an empty string is set to 'false'.
# A variable set to 'false' or 'auto' keeps its value.
# Anything else is set to 'true'.
# An unset variable defaults to 'auto'.
#
# The last rule is to allow people to set the variable to an empty
# string and export it to decline testing the particular feature
# for versions both before and after this change. We used to treat
# both unset and empty variable as a signal for "do not test" and
# took any non-empty string as "please test".
test_tristate () {
if eval "test x\"\${$1+isset}\" = xisset"
then
# explicitly set
eval "
case \"\$$1\" in
'') $1=false ;;
auto) ;;
*) $1=\$(test_normalize_bool \$$1 || echo true) ;;
esac
"
else
eval "$1=auto"
fi
}
# Exit the test suite, either by skipping all remaining tests or by
# exiting with an error. If "$1" is "auto", we then we assume we were
# opportunistically trying to set up some tests and we skip. If it is
# "true", then we report a failure.
# exiting with an error. If our prerequisite variable $1 falls back
# on a default assume we were opportunistically trying to set up some
# tests and we skip. If it is explicitly "true", then we report a failure.
#
# The error/skip message should be given by $2.
#
test_skip_or_die () {
case "$1" in
auto)
if ! git env--helper --type=bool --default=false --exit-code $1
then
skip_all=$2
test_done
;;
true)
error "$2"
;;
*)
error "BUG: test tristate is '$1' (real error: $2)"
esac
fi
error "$2"
}
# The following mingw_* functions obey POSIX shell syntax, but are actually