aboutsummaryrefslogtreecommitdiff
path: root/test/test-lib.sh
diff options
context:
space:
mode:
authorMichal Sojka <sojkam1@fel.cvut.cz>2010-11-14 22:54:28 +0100
committerCarl Worth <cworth@cworth.org>2010-11-16 11:28:06 -0800
commitac9dbb47de734afb0ddd4d0b2eb8f5027b1a7f60 (patch)
tree408ad9517cd4d2388909d258a1ecc4975389f5cf /test/test-lib.sh
parent75d616c6caa0e0ac51c34371ebee7574dbea2952 (diff)
test: Better handling of stdout and stderr
Git-style tests (test_expect_success etc.) suppress stdout and stderr unless -v is given. Notmuch-style tests (created by test_begin_subtest and test_expect_equal) do not have this behavior so implement it the same. Additionally, for both test styles, the test-lib.sh is changed so that the content of suppressed stdout and stderr is shown in case of failed test. Finally a test for this functionality is added to basic tests.
Diffstat (limited to 'test/test-lib.sh')
-rw-r--r--test/test-lib.sh21
1 files changed, 15 insertions, 6 deletions
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 418eaa7..68c9cf8 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -165,12 +165,6 @@ fi
echo $(basename "$0"): "Testing ${test_description}"
exec 5>&1
-if test "$verbose" = "t"
-then
- exec 4>&2 3>&1
-else
- exec 4>/dev/null 3>/dev/null
-fi
test_failure=0
test_count=0
@@ -403,6 +397,11 @@ add_email_corpus ()
test_begin_subtest ()
{
test_subtest_name="$1"
+ # Remember stdout and stderr file descriptios and redirect test
+ # output to the previously prepared file descriptors 3 and 4 (see
+ # bellow)
+ if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
+ exec 6>&1 7>&2 >&3 2>&4
}
# Pass test if two arguments match
@@ -413,6 +412,7 @@ test_begin_subtest ()
# name.
test_expect_equal ()
{
+ exec 1>&6 2>&7 # Restore stdout and stderr
test "$#" = 3 && { prereq=$1; shift; } || prereq=
test "$#" = 2 ||
error "bug in the test script: not 2 or 3 parameters to test_expect_equal"
@@ -508,6 +508,7 @@ test_failure_ () {
echo " $1"
shift
echo "$@" | sed -e 's/^/ /'
+ if test "$verbose" != "t"; then cat test.output; fi
test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
}
@@ -529,6 +530,7 @@ test_debug () {
test_run_ () {
test_cleanup=:
+ if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi
eval >&3 2>&4 "$1"
eval_ret=$?
eval >&3 2>&4 "$test_cleanup"
@@ -918,6 +920,13 @@ EOF
# in subprocesses like git equals our $PWD (for pathname comparisons).
cd -P "$test" || error "Cannot setup test environment"
+if test "$verbose" = "t"
+then
+ exec 4>&2 3>&1
+else
+ exec 4>test.output 3>&4
+fi
+
this_test=${0##*/}
for skp in $NOTMUCH_SKIP_TESTS
do