summaryrefslogtreecommitdiff
path: root/t/lib-git-daemon.sh
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-01-25 19:16:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-01-25 21:50:03 (GMT)
commit314a73d6585bf9caecac3243f7de2d7330e1ff9f (patch)
tree96b2f5957ae40f6e4a33d5155c3a26950658d190 /t/lib-git-daemon.sh
parent02adf84ab8996cb80d7468f1d3c13be19f929294 (diff)
downloadgit-314a73d6585bf9caecac3243f7de2d7330e1ff9f.zip
git-314a73d6585bf9caecac3243f7de2d7330e1ff9f.tar.gz
git-314a73d6585bf9caecac3243f7de2d7330e1ff9f.tar.bz2
t/lib-git-daemon: record daemon log
When we start git-daemon for our tests, we send its stderr log stream to a named pipe. We synchronously read the first line to make sure that the daemon started, and then dump the rest to descriptor 4. This is handy for debugging test output with "--verbose", but the tests themselves can't access the log data. Let's dump the log into a file, as well, so that future tests can check the log. There are a few subtleties worth calling out here: - we'll continue to send output to descriptor 4 for viewing/debugging, which would imply swapping out "cat" for "tee". But we want to ensure that there's no buffering, and "tee" doesn't have a standard way to ask for that. So we'll use a shell loop around "read" and "printf" instead. That ensures that after a request has been served, the matching log entries will have made it to the file. - the existing first-line shell loop used read/echo. We'll switch to consistently using "read -r" and "printf" to relay data as faithfully as possible. - we open the logfile for append, rather than just output. That makes it OK for tests to truncate the logfile without restarting the daemon (the OS will atomically seek to the end of the file when outputting each line). That allows tests to look at the log without worrying about pollution from earlier tests. Helped-by: Lucas Werkmeister <mail@lucaswerkmeister.de> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/lib-git-daemon.sh')
-rw-r--r--t/lib-git-daemon.sh16
1 files changed, 12 insertions, 4 deletions
diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh
index 987d406..9612ccc 100644
--- a/t/lib-git-daemon.sh
+++ b/t/lib-git-daemon.sh
@@ -53,11 +53,19 @@ start_git_daemon() {
"$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
>&3 2>git_daemon_output &
GIT_DAEMON_PID=$!
+ >daemon.log
{
- read line <&7
- echo >&4 "$line"
- cat <&7 >&4 &
- } 7<git_daemon_output &&
+ read -r line <&7
+ printf "%s\n" "$line"
+ printf >&4 "%s\n" "$line"
+ (
+ while read -r line <&7
+ do
+ printf "%s\n" "$line"
+ printf >&4 "%s\n" "$line"
+ done
+ ) &
+ } 7<git_daemon_output >>"$TRASH_DIRECTORY/daemon.log" &&
# Check expected output
if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"