Skip to content

Commit 3b072c5

Browse files
avargitster
authored andcommitted
tests: replace test_tristate with "git env--helper"
The test_tristate helper introduced in 83d842d ("tests: turn on network daemon tests by default", 2014-02-10) can now be better implemented with "git env--helper" to give the variables in question the standard boolean behavior. The reason for the "tristate" was to have all of false/true/auto, where "auto" meant either "false" or "true" depending on what the fallback was. With the --default option to "git env--helper" we can simply have e.g. GIT_TEST_HTTPD where we know if it's true because the user asked explicitly ("true"), or true implicitly ("auto"). This breaks backwards compatibility for explicitly setting "auto" for these variables, but I don't think anyone cares. That was always intended to be internal. This means the test_normalize_bool() code in test-lib-functions.sh goes away in addition to test_tristate(). We still need the test_skip_or_die() helper, but now it takes the variable name instead of the value, and uses "git env--bool" to distinguish a default "true" from an explicit "true" (in those "explicit true" cases we want to fail the test in question). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 423b05e commit 3b072c5

File tree

5 files changed

+22
-70
lines changed

5 files changed

+22
-70
lines changed

t/lib-git-daemon.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@
1515
#
1616
# test_done
1717

18-
test_tristate GIT_TEST_GIT_DAEMON
19-
if test "$GIT_TEST_GIT_DAEMON" = false
18+
if ! git env--helper --type=bool --default=true --exit-code GIT_TEST_GIT_DAEMON
2019
then
2120
skip_all="git-daemon testing disabled (unset GIT_TEST_GIT_DAEMON to enable)"
2221
test_done
2322
fi
2423

2524
if test_have_prereq !PIPE
2625
then
27-
test_skip_or_die $GIT_TEST_GIT_DAEMON "file system does not support FIFOs"
26+
test_skip_or_die GIT_TEST_GIT_DAEMON "file system does not support FIFOs"
2827
fi
2928

3029
test_set_port LIB_GIT_DAEMON_PORT
@@ -73,7 +72,7 @@ start_git_daemon() {
7372
kill "$GIT_DAEMON_PID"
7473
wait "$GIT_DAEMON_PID"
7574
unset GIT_DAEMON_PID
76-
test_skip_or_die $GIT_TEST_GIT_DAEMON \
75+
test_skip_or_die GIT_TEST_GIT_DAEMON \
7776
"git daemon failed to start"
7877
fi
7978
}

t/lib-git-svn.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,12 @@ svn_cmd () {
6969
maybe_start_httpd () {
7070
loc=${1-svn}
7171

72-
test_tristate GIT_SVN_TEST_HTTPD
73-
case $GIT_SVN_TEST_HTTPD in
74-
true)
72+
if git env--helper --type=bool --default=false --exit-code GIT_TEST_HTTPD
73+
then
7574
. "$TEST_DIRECTORY"/lib-httpd.sh
7675
LIB_HTTPD_SVN="$loc"
7776
start_httpd
78-
;;
79-
esac
77+
fi
8078
}
8179

8280
convert_to_rev_db () {
@@ -106,8 +104,7 @@ EOF
106104
}
107105

108106
require_svnserve () {
109-
test_tristate GIT_TEST_SVNSERVE
110-
if ! test "$GIT_TEST_SVNSERVE" = true
107+
if ! git env--helper --type=bool --default=false --exit-code GIT_TEST_SVNSERVE
111108
then
112109
skip_all='skipping svnserve test. (set $GIT_TEST_SVNSERVE to enable)'
113110
test_done

t/lib-httpd.sh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ then
4141
test_done
4242
fi
4343

44-
test_tristate GIT_TEST_HTTPD
45-
if test "$GIT_TEST_HTTPD" = false
44+
if ! git env--helper --type=bool --default=true --exit-code GIT_TEST_HTTPD
4645
then
4746
skip_all="Network testing disabled (unset GIT_TEST_HTTPD to enable)"
4847
test_done
4948
fi
5049

5150
if ! test_have_prereq NOT_ROOT; then
52-
test_skip_or_die $GIT_TEST_HTTPD \
51+
test_skip_or_die GIT_TEST_HTTPD \
5352
"Cannot run httpd tests as root"
5453
fi
5554

@@ -95,7 +94,7 @@ GIT_TRACE=$GIT_TRACE; export GIT_TRACE
9594

9695
if ! test -x "$LIB_HTTPD_PATH"
9796
then
98-
test_skip_or_die $GIT_TEST_HTTPD "no web server found at '$LIB_HTTPD_PATH'"
97+
test_skip_or_die GIT_TEST_HTTPD "no web server found at '$LIB_HTTPD_PATH'"
9998
fi
10099

101100
HTTPD_VERSION=$($LIB_HTTPD_PATH -v | \
@@ -107,19 +106,19 @@ then
107106
then
108107
if ! test $HTTPD_VERSION -ge 2
109108
then
110-
test_skip_or_die $GIT_TEST_HTTPD \
109+
test_skip_or_die GIT_TEST_HTTPD \
111110
"at least Apache version 2 is required"
112111
fi
113112
if ! test -d "$DEFAULT_HTTPD_MODULE_PATH"
114113
then
115-
test_skip_or_die $GIT_TEST_HTTPD \
114+
test_skip_or_die GIT_TEST_HTTPD \
116115
"Apache module directory not found"
117116
fi
118117

119118
LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH"
120119
fi
121120
else
122-
test_skip_or_die $GIT_TEST_HTTPD \
121+
test_skip_or_die GIT_TEST_HTTPD \
123122
"Could not identify web server at '$LIB_HTTPD_PATH'"
124123
fi
125124

@@ -184,7 +183,7 @@ start_httpd() {
184183
if test $? -ne 0
185184
then
186185
cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null
187-
test_skip_or_die $GIT_TEST_HTTPD "web server setup failed"
186+
test_skip_or_die GIT_TEST_HTTPD "web server setup failed"
188187
fi
189188
}
190189

t/t5512-ls-remote.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ test_expect_success 'ls-remote --symref omits filtered-out matches' '
267267
'
268268

269269
test_lazy_prereq GIT_DAEMON '
270-
test_tristate GIT_TEST_GIT_DAEMON &&
271-
test "$GIT_TEST_GIT_DAEMON" != false
270+
git env--helper --type=bool --default=true --exit-code GIT_TEST_GIT_DAEMON
272271
'
273272

274273
# This test spawns a daemon, so run it only if the user would be OK with

t/test-lib-functions.sh

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,62 +1035,20 @@ perl () {
10351035
command "$PERL_PATH" "$@" 2>&7
10361036
} 7>&2 2>&4
10371037

1038-
# Is the value one of the various ways to spell a boolean true/false?
1039-
test_normalize_bool () {
1040-
git -c magic.variable="$1" config --bool magic.variable 2>/dev/null
1041-
}
1042-
1043-
# Given a variable $1, normalize the value of it to one of "true",
1044-
# "false", or "auto" and store the result to it.
1045-
#
1046-
# test_tristate GIT_TEST_HTTPD
1047-
#
1048-
# A variable set to an empty string is set to 'false'.
1049-
# A variable set to 'false' or 'auto' keeps its value.
1050-
# Anything else is set to 'true'.
1051-
# An unset variable defaults to 'auto'.
1052-
#
1053-
# The last rule is to allow people to set the variable to an empty
1054-
# string and export it to decline testing the particular feature
1055-
# for versions both before and after this change. We used to treat
1056-
# both unset and empty variable as a signal for "do not test" and
1057-
# took any non-empty string as "please test".
1058-
1059-
test_tristate () {
1060-
if eval "test x\"\${$1+isset}\" = xisset"
1061-
then
1062-
# explicitly set
1063-
eval "
1064-
case \"\$$1\" in
1065-
'') $1=false ;;
1066-
auto) ;;
1067-
*) $1=\$(test_normalize_bool \$$1 || echo true) ;;
1068-
esac
1069-
"
1070-
else
1071-
eval "$1=auto"
1072-
fi
1073-
}
1074-
10751038
# Exit the test suite, either by skipping all remaining tests or by
1076-
# exiting with an error. If "$1" is "auto", we then we assume we were
1077-
# opportunistically trying to set up some tests and we skip. If it is
1078-
# "true", then we report a failure.
1039+
# exiting with an error. If our prerequisite variable $1 falls back
1040+
# on a default assume we were opportunistically trying to set up some
1041+
# tests and we skip. If it is explicitly "true", then we report a failure.
10791042
#
10801043
# The error/skip message should be given by $2.
10811044
#
10821045
test_skip_or_die () {
1083-
case "$1" in
1084-
auto)
1046+
if ! git env--helper --mode-bool --variable=$1 --default=0 --exit-code --quiet
1047+
then
10851048
skip_all=$2
10861049
test_done
1087-
;;
1088-
true)
1089-
error "$2"
1090-
;;
1091-
*)
1092-
error "BUG: test tristate is '$1' (real error: $2)"
1093-
esac
1050+
fi
1051+
error "$2"
10941052
}
10951053

10961054
# The following mingw_* functions obey POSIX shell syntax, but are actually

0 commit comments

Comments
 (0)