[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[FYI] {test-protocols} tap/awk: don't redirect awk stderr to log files
From: |
Stefano Lattarini |
Subject: |
[FYI] {test-protocols} tap/awk: don't redirect awk stderr to log files |
Date: |
Thu, 25 Aug 2011 14:00:12 +0200 |
* 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.
---
ChangeLog | 12 ++++++++++
lib/tap-driver.sh | 22 ++++++++++++------
tests/Makefile.am | 1 +
tests/Makefile.in | 1 +
tests/tap-driver-stderr.test | 49 ++++++++++++++++++++++++++++++++++++++++++
5 files changed, 77 insertions(+), 8 deletions(-)
create mode 100755 tests/tap-driver-stderr.test
diff --git a/ChangeLog b/ChangeLog
index 2e8088a..b1f251d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2011-08-24 Stefano Lattarini <address@hidden>
+ 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 <address@hidden>
+
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
diff --git a/lib/tap-driver.sh b/lib/tap-driver.sh
index bec914f..16a4e04 100755
--- a/lib/tap-driver.sh
+++ b/lib/tap-driver.sh
@@ -23,7 +23,7 @@
# bugs to <address@hidden> or send patches to
# <address@hidden>.
-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.
@@ -116,8 +116,14 @@ else
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" \
@@ -141,7 +147,7 @@ fi
function fatal(msg)
{
- print me ": " msg | "cat >&3"
+ print me ": " msg | "cat >&2"
exit 1
}
@@ -248,10 +254,10 @@ function report(result, details)
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)
@@ -498,7 +504,7 @@ while (1)
$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
@@ -588,7 +594,7 @@ exit 0
'
# 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"
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4c8f342..300bd26 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1225,6 +1225,7 @@ tap-common-setup.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 \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index d9fafa7..720771a 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -1463,6 +1463,7 @@ tap-common-setup.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 \
diff --git a/tests/tap-driver-stderr.test b/tests/tap-driver-stderr.test
new file mode 100755
index 0000000..396624e
--- /dev/null
+++ b/tests/tap-driver-stderr.test
@@ -0,0 +1,49 @@
+#! /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
+
+:
--
1.7.2.3
- [FYI] {test-protocols} tap/awk: remove obsolete "FIXME" comment, Stefano Lattarini, 2011/08/25
- [FYI] {test-protocols} tap/perl: add copyright notice, version string, and emacs stuff, Stefano Lattarini, 2011/08/25
- [FYI] {test-protocols} tap/awk: don't redirect awk stderr to log files,
Stefano Lattarini <=
- [FYI] {test-protocols} tap/perl: don't redirect perl warnings/errors to log files, Stefano Lattarini, 2011/08/25
- [FYI] {test-protocols} tap: improve syncing between awk+shell and perl implementations, Stefano Lattarini, 2011/08/25
- [FYI] {test-protocols} coverage: more about escaping of TAP directives, Stefano Lattarini, 2011/08/25
- [FYI] {test-protocols} tap/awk: allow escaping of TAP directives, Stefano Lattarini, 2011/08/25