Skip to content

Commit ee3a81e

Browse files
committed
Merge branch 'jk/run-network-tests-by-default'
Teach "make test" to run networking tests when possible by default. * jk/run-network-tests-by-default: tests: turn on network daemon tests by default
2 parents 4c4ac4d + 83d842d commit ee3a81e

File tree

3 files changed

+74
-14
lines changed

3 files changed

+74
-14
lines changed

t/lib-git-daemon.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
# stop_git_daemon
1717
# test_done
1818

19-
if test -z "$GIT_TEST_GIT_DAEMON"
19+
test_tristate GIT_TEST_GIT_DAEMON
20+
if test "$GIT_TEST_GIT_DAEMON" = false
2021
then
21-
skip_all="git-daemon testing disabled (define GIT_TEST_GIT_DAEMON to enable)"
22+
skip_all="git-daemon testing disabled (unset GIT_TEST_GIT_DAEMON to enable)"
2223
test_done
2324
fi
2425

@@ -58,7 +59,8 @@ start_git_daemon() {
5859
kill "$GIT_DAEMON_PID"
5960
wait "$GIT_DAEMON_PID"
6061
trap 'die' EXIT
61-
error "git daemon failed to start"
62+
test_skip_or_die $GIT_TEST_GIT_DAEMON \
63+
"git daemon failed to start"
6264
fi
6365
}
6466

t/lib-httpd.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
# Copyright (c) 2008 Clemens Buchacher <[email protected]>
3131
#
3232

33-
if test -z "$GIT_TEST_HTTPD"
33+
test_tristate GIT_TEST_HTTPD
34+
if test "$GIT_TEST_HTTPD" = false
3435
then
35-
skip_all="Network testing disabled (define GIT_TEST_HTTPD to enable)"
36+
skip_all="Network testing disabled (unset GIT_TEST_HTTPD to enable)"
3637
test_done
3738
fi
3839

@@ -76,8 +77,7 @@ GIT_VALGRIND_OPTIONS=$GIT_VALGRIND_OPTIONS; export GIT_VALGRIND_OPTIONS
7677

7778
if ! test -x "$LIB_HTTPD_PATH"
7879
then
79-
skip_all="skipping test, no web server found at '$LIB_HTTPD_PATH'"
80-
test_done
80+
test_skip_or_die $GIT_TEST_HTTPD "no web server found at '$LIB_HTTPD_PATH'"
8181
fi
8282

8383
HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
@@ -89,19 +89,20 @@ then
8989
then
9090
if ! test $HTTPD_VERSION -ge 2
9191
then
92-
skip_all="skipping test, at least Apache version 2 is required"
93-
test_done
92+
test_skip_or_die $GIT_TEST_HTTPD \
93+
"at least Apache version 2 is required"
9494
fi
9595
if ! test -d "$DEFAULT_HTTPD_MODULE_PATH"
9696
then
97-
skip_all="Apache module directory not found. Skipping tests."
98-
test_done
97+
test_skip_or_die $GIT_TEST_HTTPD \
98+
"Apache module directory not found"
9999
fi
100100

101101
LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH"
102102
fi
103103
else
104-
error "Could not identify web server at '$LIB_HTTPD_PATH'"
104+
test_skip_or_die $GIT_TEST_HTTPD \
105+
"Could not identify web server at '$LIB_HTTPD_PATH'"
105106
fi
106107

107108
prepare_httpd() {
@@ -155,9 +156,8 @@ start_httpd() {
155156
>&3 2>&4
156157
if test $? -ne 0
157158
then
158-
skip_all="skipping test, web server setup failed"
159159
trap 'die' EXIT
160-
test_done
160+
test_skip_or_die $GIT_TEST_HTTPD "web server setup failed"
161161
fi
162162
}
163163

t/test-lib-functions.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,64 @@ perl () {
716716
command "$PERL_PATH" "$@"
717717
}
718718

719+
# Is the value one of the various ways to spell a boolean true/false?
720+
test_normalize_bool () {
721+
git -c magic.variable="$1" config --bool magic.variable 2>/dev/null
722+
}
723+
724+
# Given a variable $1, normalize the value of it to one of "true",
725+
# "false", or "auto" and store the result to it.
726+
#
727+
# test_tristate GIT_TEST_HTTPD
728+
#
729+
# A variable set to an empty string is set to 'false'.
730+
# A variable set to 'false' or 'auto' keeps its value.
731+
# Anything else is set to 'true'.
732+
# An unset variable defaults to 'auto'.
733+
#
734+
# The last rule is to allow people to set the variable to an empty
735+
# string and export it to decline testing the particular feature
736+
# for versions both before and after this change. We used to treat
737+
# both unset and empty variable as a signal for "do not test" and
738+
# took any non-empty string as "please test".
739+
740+
test_tristate () {
741+
if eval "test x\"\${$1+isset}\" = xisset"
742+
then
743+
# explicitly set
744+
eval "
745+
case \"\$$1\" in
746+
'') $1=false ;;
747+
auto) ;;
748+
*) $1=\$(test_normalize_bool \$$1 || echo true) ;;
749+
esac
750+
"
751+
else
752+
eval "$1=auto"
753+
fi
754+
}
755+
756+
# Exit the test suite, either by skipping all remaining tests or by
757+
# exiting with an error. If "$1" is "auto", we then we assume we were
758+
# opportunistically trying to set up some tests and we skip. If it is
759+
# "true", then we report a failure.
760+
#
761+
# The error/skip message should be given by $2.
762+
#
763+
test_skip_or_die () {
764+
case "$1" in
765+
auto)
766+
skip_all=$2
767+
test_done
768+
;;
769+
true)
770+
error "$2"
771+
;;
772+
*)
773+
error "BUG: test tristate is '$1' (real error: $2)"
774+
esac
775+
}
776+
719777
# The following mingw_* functions obey POSIX shell syntax, but are actually
720778
# bash scripts, and are meant to be used only with bash on Windows.
721779

0 commit comments

Comments
 (0)