tests: turn on network daemon tests by default

We do not run the httpd nor git-daemon tests by default, as they are rather heavyweight and require network access (albeit over localhost). However, it would be nice if more pepole ran them, for two reasons: 1. We would get more test coverage on more systems. 2. The point of the test suite is to find regressions. It is very easy to change some of the underlying code and break the httpd code without realizing you are even affecting it. Running the httpd tests helps find these problems sooner (ideally before the patches even hit the list). We still want to leave an "out", though, for people who really do not want to run them. For that reason, the GIT_TEST_HTTPD and GIT_TEST_GIT_DAEMON variables are now tri-state booleans (true/false/auto), so you can say GIT_TEST_HTTPD=false to turn the tests back off. To support those who want a stable single way to disable these tests across versions of Git before and after this change, an empty string explicitly set to these variables is also taken as "false", so the behaviour changes only for those who: a. did not express any preference by leaving these variables unset. They did not test these features before, but now they do; or b. did express that they want to test these features by setting GIT_TEST_FEATURE=false (or any equivalent other ways to tell "false" to Git, e.g. "0"), which has been a valid but funny way to say that they do want to test the feature only because we used to interpret any non-empty string to mean "yes please test". They no longer test that feature. In addition, we are forgiving of common setup failures (e.g., you do not have apache installed, or have an old version) when the tri-state is "auto" (or unset), but report an error when it is "true". This makes "auto" a sane default, as we should not cause failures on setups where the tests cannot run. But it allows people who use "true" to catch regressions in their system (e.g., they uninstalled apache, but were expecting their automated test runs to test git-httpd, and would want to be notified). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 10, 2014 at 16:29 UTC 83d842dc8ce4380aa365485b4d9845762f80c6db
3 files changed +74 -14
t/lib-git-daemon.sh
+5 -3
@@ -16,9 +16,10 @@
16 # stop_git_daemon
17 # test_done
18
19 -if test -z "$GIT_TEST_GIT_DAEMON"
19 +test_tristate GIT_TEST_GIT_DAEMON
20 +if test "$GIT_TEST_GIT_DAEMON" = false
21 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)"
23 test_done
24 fi
25
@@ -58,7 +59,8 @@ start_git_daemon() {
59 kill "$GIT_DAEMON_PID"
60 wait "$GIT_DAEMON_PID"
61 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"
64 fi
65 }
66
t/lib-httpd.sh
+11 -11
@@ -30,9 +30,10 @@
30 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
31 #
32
33 -if test -z "$GIT_TEST_HTTPD"
33 +test_tristate GIT_TEST_HTTPD
34 +if test "$GIT_TEST_HTTPD" = false
35 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)"
37 test_done
38 fi
39
@@ -76,8 +77,7 @@ GIT_VALGRIND_OPTIONS=$GIT_VALGRIND_OPTIONS; export GIT_VALGRIND_OPTIONS
77
78 if ! test -x "$LIB_HTTPD_PATH"
79 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'"
81 fi
82
83 HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
@@ -89,19 +89,20 @@ then
89 then
90 if ! test $HTTPD_VERSION -ge 2
91 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"
94 fi
95 if ! test -d "$DEFAULT_HTTPD_MODULE_PATH"
96 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"
99 fi
100
101 LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH"
102 fi
103 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'"
106 fi
107
108 prepare_httpd() {
@@ -155,9 +156,8 @@ start_httpd() {
156 >&3 2>&4
157 if test $? -ne 0
158 then
158 - skip_all="skipping test, web server setup failed"
159 trap 'die' EXIT
160 - test_done
160 + test_skip_or_die $GIT_TEST_HTTPD "web server setup failed"
161 fi
162 }
163
t/test-lib-functions.sh
+58
@@ -716,6 +716,64 @@ perl () {
716 command "$PERL_PATH" "$@"
717 }
718
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 +
777 # The following mingw_* functions obey POSIX shell syntax, but are actually
778 # bash scripts, and are meant to be used only with bash on Windows.
779