2011-08-24 Stefano Lattarini <stefano.lattarini@gmail.com>
+ tap/awk: don't redirect awk stderr to log files
+ * lib/tap-driver.sh: Handle the file descriptors redirections
+ more smartly, to avoid sending error messages from awk (about
+ e.g. syntax or I/O errors) to the log files instead that to the
+ console.
+ * tests/tap-driver-stderr.test: New test, verifying the improved
+ driver behaviour. Notice that this test still fails when using
+ the perl implementation of the TAP driver.
+ * tests/Makefile.am (tap_other_tests): Update.
+
+2011-08-24 Stefano Lattarini <stefano.lattarini@gmail.com>
+
tap/awk: remove obsolete "FIXME" comment
* lib/tap-driver.sh: Remove obsolete "FIXME" comment about our
driver losing the exit status of the tested program; this issue
# bugs to <bug-automake@gnu.org> or send patches to
# <automake-patches@gnu.org>.
-scriptversion=2011-08-24.08; # UTC
+scriptversion=2011-08-24.09; # UTC
# Make unconditional expansion of undefined variables an error. This
# helps a lot in preventing typo-related bugs.
fi
{
- { test $merge -eq 0 || exec 2>&1; "$@"; echo $?; } \
- | LC_ALL=C ${AM_TAP_AWK-awk} \
+ { if test $merge -gt 0; then
+ exec 2>&1
+ else
+ exec 2>&3
+ fi
+ "$@"
+ echo $?
+ } | LC_ALL=C ${AM_TAP_AWK-awk} \
-v me="$me" \
-v test_script_name="$test_name" \
-v log_file="$log_file" \
function fatal(msg)
{
- print me ": " msg | "cat >&3"
+ print me ": " msg | "cat >&2"
exit 1
}
if (length(details))
msg = msg " " details
# Output on console might be colorized.
- print decorate_result(result) msg | "cat >&3";
+ print decorate_result(result) msg
# Log the result in the log file too, to help debugging (this is
# especially true when said result is a TAP error or "Bail out!").
- print result msg;
+ print result msg | "cat >&3";
}
function testsuite_error(error_message)
$0 = curline
}
# Copy any input line verbatim into the log file.
- print
+ print | "cat >&3"
# Parsing of TAP input should stop after a "Bail out!" directive.
if (bailed_out)
continue
'
# TODO: document that we consume the file descriptor 3 :-(
-} 3>&1 >"$log_file" 2>&1
+} 3>"$log_file"
test $? -eq 0 || fatal "I/O or internal error"
tap-bad-prog.tap \
tap-basic.test \
tap-diagnostic-custom.test \
+tap-driver-stderr.test \
tap-doc.test \
tap-doc2.test \
tap-more.test \
tap-bad-prog.tap \
tap-basic.test \
tap-diagnostic-custom.test \
+tap-driver-stderr.test \
tap-doc.test \
tap-doc2.test \
tap-more.test \
--- /dev/null
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Unit test on TAP driver:
+# - error messages from awk/shell/perl goes to the console
+
+required=non-root
+parallel_tests=yes
+. ./defs || Exit 1
+
+fetch_tap_driver
+
+tst=zardoz
+
+for suf in trs log; do
+
+ rm -f $tst.log $tst.trs
+ touch $tst.$suf
+ chmod a-w $tst.$suf
+
+ st=0
+ ./tap-driver --test-name $tst --log-file $tst.log --trs-file $tst.trs \
+ -- sh -c 'echo 1..1; echo ok 1; echo "Hello, World!"' \
+ >stdout 2>stderr && st=1
+ cat stdout
+ cat stderr >&2
+ cat $tst.log || :
+ cat $tst.trs || :
+ test $st -eq 0
+
+ $FGREP 'Hello, World!' stderr stdout && Exit 1
+ $FGREP $tst.$suf stderr
+
+done
+
+: