@matheusbsbs / matheus-bagliano / commits / 44138559e8
Fork 0

test-lib.sh: optionally output to test-results/$TEST.out, too

When tests are run in parallel and a few tests fail, it does not help that the output of the terminal is totally confusing, as you rarely know which test which line came from. So introduce the option '--tee' which triggers that the output of the tests will be written to t/test-results/$TEST.out in addition to the terminal, where $TEST is the basename of the script. Unfortunately, there seems to be no way to redirect a given file descriptor to a specified subprocess in POSIX shell, only redirection to a file is supported via 'exec > $FILE'. At least with bash, one might think that 'exec >($COMMAND)' would work as intended, but it does not. The common way to work around the lack of proper tools support is to work with named pipes, alas, one of our most beloved platforms does not really support named pipes. Besides, we would need a pipe for every script, as the whole point of this patch is to allow parallel execution. Therefore, we handle the redirection in the following way: when '--tee' was passed to the test script, the variable GIT_TEST_TEE_STARTED is set (to avoid triggering that code path again) and the script is started _again_, in a subshell, redirected to the command "tee". Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Feb 4, 2009 at 00:26 UTC 44138559e8b7c89768a2450220b831847059311c
2 files changed +24
t/README
+6
@@ -65,6 +65,12 @@ appropriately before running "make".
65 the test script when running under -i). Valgrind errors
66 go to stderr, so you might want to pass the -v option, too.
67
68 +--tee::
69 + In addition to printing the test output to the terminal,
70 + write it to files named 't/test-results/$TEST_NAME.out'.
71 + As the names depend on the tests' file names, it is safe to
72 + run the tests with this option in parallel.
73 +
74 Skipping Tests
75 --------------
76
t/test-lib.sh
+18
@@ -3,6 +3,22 @@
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 +# if --tee was passed, write the output not only to the terminal, but
7 +# additionally to the file test-results/$BASENAME.out, too.
8 +case "$GIT_TEST_TEE_STARTED, $* " in
9 +done,*)
10 + # do not redirect again
11 + ;;
12 +*' --tee '*)
13 + mkdir -p test-results
14 + BASE=test-results/$(basename "$0" .sh)
15 + (GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1;
16 + echo $? > $BASE.exit) | tee $BASE.out
17 + test "$(cat $BASE.exit)" = 0
18 + exit
19 + ;;
20 +esac
21 +
22 # Keep the original TERM for say_color
23 ORIGINAL_TERM=$TERM
24
@@ -96,6 +112,8 @@ do
112 shift ;;
113 --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
114 valgrind=t; shift ;;
115 + --tee)
116 + shift ;; # was handled already
117 *)
118 break ;;
119 esac