[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/8] Maintainer-check: warn against zsh xtrace bug
From: |
Stefano Lattarini |
Subject: |
[PATCH 2/8] Maintainer-check: warn against zsh xtrace bug |
Date: |
Mon, 1 Feb 2010 16:58:37 +0100 |
User-agent: |
KMail/1.12.1 (Linux/2.6.30-2-686; KDE/4.3.2; i686; ; ) |
Maintainer-check: warn against zsh xtrace bug.
Extended target maintainer-check, to warn against idioms and
constructs in test scripts which might trigger the Zsh xtrace
bug.
* Makefile.am (sc_tests_stderr_redirection): New check.
(sc_tests_stderr_redirection__perl_code): New internal macro.
(sc_tests_stderr_redirection__whitelist): Likewise.
(syntax_check_rules): Added `sc_tests_stderr_redirection'.
From ec8b0ea72f2423d648e366d76ac192c7307e1411 Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <address@hidden>
Date: Tue, 8 Dec 2009 18:09:14 +0100
Subject: [PATCH 2/8] Maintainer-check: warn against zsh xtrace bug
Extended target maintainer-check, to warn against idioms and
constructs in test scripts which might trigger the Zsh xtrace
bug.
* Makefile.am (sc_tests_stderr_redirection): New check.
(sc_tests_stderr_redirection__perl_code): New internal macro.
(sc_tests_stderr_redirection__whitelist): Likewise.
(syntax_check_rules): Added `sc_tests_stderr_redirection'.
---
ChangeLog | 10 +++++++++
Makefile.am | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Makefile.in | 44 +++++++++++++++++++++++++++++++++++++++
3 files changed, 120 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 825e919..0b81e60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-01-31 Stefano Lattarini <address@hidden>
+
+ Extended target maintainer-check, to warn against idioms and
+ constructs in test scripts which might trigger the Zsh xtrace
+ bug.
+ * Makefile.am (sc_tests_stderr_redirection): New check.
+ (sc_tests_stderr_redirection__perl_code): New internal macro.
+ (sc_tests_stderr_redirection__whitelist): Likewise.
+ (syntax_check_rules): Added `sc_tests_stderr_redirection'.
+
2010-01-31 Stefano Lattarini <address@hidden>
Testsuite: avoid Zsh-related problem with `set -x'.
diff --git a/Makefile.am b/Makefile.am
index 08047d2..fc8207a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -190,6 +190,7 @@ sc_tests_required_after_defs \
sc_tests_overriding_macros_on_cmdline \
sc_tests_plain_sleep \
sc_tests_plain_egrep_fgrep \
+sc_tests_stderr_redirection \
sc_mkdir_p \
sc_perl_at_substs \
sc_unquoted_DESTDIR \
@@ -496,6 +497,71 @@ sc_at_in_texi:
exit 1; \
fi
+## Helper internal macro, holding a list of `file-name:line-number'
+## couples which are exempted from the checks done by target
+## `sc_tests_stderr_redirection' below.
+sc_tests_stderr_redirection__whitelist = \
+ ccnoco.test:37 \
+ depcomp5.test:24
+
+## Helper internal macro, used in the target `sc_tests_stderr_redirection'
+## below. Do NOT use single quotes in the definition of this macro (using
+## them in `##' comments is ok, though, as they get stripped by automake).
+sc_tests_stderr_redirection__perl_code = \
+ use strict; \
+ use warnings FATAL => "all"; \
+ $$^W = 1; \
+ my $$e = 0; \
+ ## List of whitelisted `file-name:line-number' couples, for which
+ ## our checks are to be skipped.
+ my @whitelist = qw!$(sc_tests_stderr_redirection__whitelist)!; \
+ my %whitelist = map { $$_ => 1 } @whitelist; \
+ foreach my $$file (@ARGV) { \
+ open(FILE, "<$$file") or die "$$file: cannot open: $$!\n"; \
+ while (<FILE>) { \
+ ## Remove traling newline from current input line.
+ chomp; \
+ if (exists $$whitelist{"$$file:$$."}) { \
+ ## Current line is whitelisted, checks must be skipped
+ print "$@: INFO: skipping whitelisted line $$file:$$.\n"; \
+ next; \
+ }; \
+ ## Save original input line.
+ my $$s = $$_; \
+ ## Normalize format of redirections.
+ s|(>+)\s*|$$1|g; \
+ ## For our purposes, there is no distinction between overriding
+ ## (`> out') and appending (`>> out') redirections.
+ s|>>|>|g; \
+ ## The construct `>/dev/null 2>&1' still redirects stderr to
+ ## /dev/null, so we can safely ignore it.
+ s|>/dev/null\s+2>&1\b||g; \
+ ## Look for bad stderr redirections, and if any is found,
+ ## display the guilty line (with file name and line number),
+ ## and properly update the exit status.
+ if (m|\b2>(?!/dev/null\b)|) { \
+ print "$$file:$$.: $$s\n"; \
+ $$e = 1; \
+ }; \
+ }; \
+ close(FILE) or die "$$file: cannot close: $$!\n"; \
+ }; \
+ exit $$e;
+
+## Redirecting standard error to something != /dev/null might be
+## inappropriate when shell traces are on, due to a bug in Zsh hadling
+## of the xtrace flag.
+sc_tests_stderr_redirection:
+ @cd $(srcdir)/tests || exit 1; \
+ $(PERL) -e '$(sc_tests_stderr_redirection__perl_code)' *.test; \
+ case $$? in \
+ 0) exit 0;; \
+ 1) echo $@: The previous lines might trigger a Zsh xtrace bug.; \
+ echo $@: Consider using the run_command shell function.;; \
+ *) echo $@: INTERNAL ERROR in auxiliary perl script.;; \
+ esac 1>&2; \
+ exit 1;
+
git-dist: maintainer-check
## Make sure the NEWS file is up-to-date.
diff --git a/Makefile.in b/Makefile.in
index e8fb282..0082bde 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -312,12 +312,45 @@ sc_tests_required_after_defs \
sc_tests_overriding_macros_on_cmdline \
sc_tests_plain_sleep \
sc_tests_plain_egrep_fgrep \
+sc_tests_stderr_redirection \
sc_mkdir_p \
sc_perl_at_substs \
sc_unquoted_DESTDIR \
sc_tabs_in_texi \
sc_at_in_texi
+sc_tests_stderr_redirection__whitelist = \
+ ccnoco.test:37 \
+ depcomp5.test:24
+
+sc_tests_stderr_redirection__perl_code = \
+ use strict; \
+ use warnings FATAL => "all"; \
+ $$^W = 1; \
+ my $$e = 0; \
+ my @whitelist = qw!$(sc_tests_stderr_redirection__whitelist)!; \
+ my %whitelist = map { $$_ => 1 } @whitelist; \
+ foreach my $$file (@ARGV) { \
+ open(FILE, "<$$file") or die "$$file: cannot open: $$!\n"; \
+ while (<FILE>) { \
+ chomp; \
+ if (exists $$whitelist{"$$file:$$."}) { \
+ print "$@: INFO: skipping whitelisted line $$file:$$.\n"; \
+ next; \
+ }; \
+ my $$s = $$_; \
+ s|(>+)\s*|$$1|g; \
+ s|>>|>|g; \
+ s|>/dev/null\s+2>&1\b||g; \
+ if (m|\b2>(?!/dev/null\b)|) { \
+ print "$$file:$$.: $$s\n"; \
+ $$e = 1; \
+ }; \
+ }; \
+ close(FILE) or die "$$file: cannot close: $$!\n"; \
+ }; \
+ exit $$e;
+
WGET = wget
WGET_SV_CVS = $(WGET) http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/
WGET_SV_GIT_CF = $(WGET)
'http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;hb=HEAD;f='
@@ -1210,6 +1243,17 @@ sc_at_in_texi:
exit 1; \
fi
+sc_tests_stderr_redirection:
+ @cd $(srcdir)/tests || exit 1; \
+ $(PERL) -e '$(sc_tests_stderr_redirection__perl_code)' *.test; \
+ case $$? in \
+ 0) exit 0;; \
+ 1) echo $@: The previous lines might trigger a Zsh xtrace bug.; \
+ echo $@: Consider using the run_command shell function.;; \
+ *) echo $@: INTERNAL ERROR in auxiliary perl script.;; \
+ esac 1>&2; \
+ exit 1;
+
git-dist: maintainer-check
@if sed 1q $(srcdir)/NEWS | grep -e "$(VERSION)" > /dev/null; then :;
else \
echo "NEWS not updated; not releasing" 1>&2; \
--
1.6.5
- [PATCH 0/8] Towards a Zsh-compatible Automake testsuite, Stefano Lattarini, 2010/02/01
- [PATCH 1/8] Testsuite: avoid Zsh-related problem with `set -x', Stefano Lattarini, 2010/02/01
- [PATCH 2/8] Maintainer-check: warn against zsh xtrace bug,
Stefano Lattarini <=
- [PATCH 3/8] Testsuite: remove AUTOMAKE_fails and AUTOMAKE_run, Stefano Lattarini, 2010/02/01
- [PATCH 4/8] Work around a bug of AT&T Ksh w.r.t. ${1+"$@"}, Stefano Lattarini, 2010/02/01
- [PATCH 5/8] Improve description of `run_command' in README, Stefano Lattarini, 2010/02/01
- [PATCH 6/8] Tests: prefer run_command over direct stdout redirection(s), Stefano Lattarini, 2010/02/01
- [PATCH 7/8] Testsuite: run_command can now set env variables, Stefano Lattarini, 2010/02/01
- [PATCH 8/8] Testsuite: avoid redundant use of the `env' utility., Stefano Lattarini, 2010/02/01