2013-11-26 05:03:06 +08:00
|
|
|
# Shell library to run git-daemon in tests. Ends the test early if
|
|
|
|
# GIT_TEST_GIT_DAEMON is not set.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
#
|
|
|
|
# . ./test-lib.sh
|
|
|
|
# . "$TEST_DIRECTORY"/lib-git-daemon.sh
|
|
|
|
# start_git_daemon
|
|
|
|
#
|
|
|
|
# test_expect_success '...' '
|
|
|
|
# ...
|
|
|
|
# '
|
|
|
|
#
|
|
|
|
# test_expect_success ...
|
|
|
|
#
|
|
|
|
# stop_git_daemon
|
|
|
|
# test_done
|
2012-01-07 19:42:45 +08:00
|
|
|
|
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>
2014-02-11 05:29:37 +08:00
|
|
|
test_tristate GIT_TEST_GIT_DAEMON
|
|
|
|
if test "$GIT_TEST_GIT_DAEMON" = false
|
2012-01-07 19:42:45 +08:00
|
|
|
then
|
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>
2014-02-11 05:29:37 +08:00
|
|
|
skip_all="git-daemon testing disabled (unset GIT_TEST_GIT_DAEMON to enable)"
|
2012-01-07 19:42:45 +08:00
|
|
|
test_done
|
|
|
|
fi
|
|
|
|
|
2016-01-28 00:19:48 +08:00
|
|
|
if test_have_prereq !PIPE
|
|
|
|
then
|
|
|
|
test_skip_or_die $GIT_TEST_GIT_DAEMON "file system does not support FIFOs"
|
|
|
|
fi
|
|
|
|
|
2014-02-11 03:16:38 +08:00
|
|
|
LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-${this_test#t}}
|
2012-01-07 19:42:45 +08:00
|
|
|
|
|
|
|
GIT_DAEMON_PID=
|
|
|
|
GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo
|
|
|
|
GIT_DAEMON_URL=git://127.0.0.1:$LIB_GIT_DAEMON_PORT
|
|
|
|
|
|
|
|
start_git_daemon() {
|
|
|
|
if test -n "$GIT_DAEMON_PID"
|
|
|
|
then
|
|
|
|
error "start_git_daemon already called"
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"
|
|
|
|
|
|
|
|
trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT
|
|
|
|
|
|
|
|
say >&3 "Starting git daemon ..."
|
2012-01-07 19:42:47 +08:00
|
|
|
mkfifo git_daemon_output
|
2017-02-25 17:37:30 +08:00
|
|
|
${LIB_GIT_DAEMON_COMMAND:-git daemon} \
|
|
|
|
--listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
|
2012-01-07 19:42:45 +08:00
|
|
|
--reuseaddr --verbose \
|
|
|
|
--base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
|
|
|
|
"$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
|
2012-01-07 19:42:47 +08:00
|
|
|
>&3 2>git_daemon_output &
|
2012-01-07 19:42:45 +08:00
|
|
|
GIT_DAEMON_PID=$!
|
2012-01-07 19:42:47 +08:00
|
|
|
{
|
2012-04-27 05:00:39 +08:00
|
|
|
read line <&7
|
2012-01-07 19:42:47 +08:00
|
|
|
echo >&4 "$line"
|
2012-04-27 05:00:39 +08:00
|
|
|
cat <&7 >&4 &
|
|
|
|
} 7<git_daemon_output &&
|
2012-01-07 19:42:47 +08:00
|
|
|
|
2012-04-27 05:00:39 +08:00
|
|
|
# Check expected output
|
|
|
|
if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
|
|
|
|
then
|
|
|
|
kill "$GIT_DAEMON_PID"
|
|
|
|
wait "$GIT_DAEMON_PID"
|
|
|
|
trap 'die' EXIT
|
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>
2014-02-11 05:29:37 +08:00
|
|
|
test_skip_or_die $GIT_TEST_GIT_DAEMON \
|
|
|
|
"git daemon failed to start"
|
2012-04-27 05:00:39 +08:00
|
|
|
fi
|
2012-01-07 19:42:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
stop_git_daemon() {
|
|
|
|
if test -z "$GIT_DAEMON_PID"
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
trap 'die' EXIT
|
|
|
|
|
|
|
|
# kill git-daemon child of git
|
|
|
|
say >&3 "Stopping git daemon ..."
|
|
|
|
kill "$GIT_DAEMON_PID"
|
|
|
|
wait "$GIT_DAEMON_PID" >&3 2>&4
|
|
|
|
ret=$?
|
2016-06-25 03:45:12 +08:00
|
|
|
if test_match_signal 15 $?
|
2012-01-07 19:42:45 +08:00
|
|
|
then
|
|
|
|
error "git daemon exited with status: $ret"
|
|
|
|
fi
|
|
|
|
GIT_DAEMON_PID=
|
2012-01-07 19:42:47 +08:00
|
|
|
rm -f git_daemon_output
|
2012-01-07 19:42:45 +08:00
|
|
|
}
|