bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] maint.mk: add syntax check for use of compare from init.sh


From: Eric Blake
Subject: [PATCH] maint.mk: add syntax check for use of compare from init.sh
Date: Tue, 29 Nov 2011 15:56:38 -0700

Comparing expected against actual gives more consistent diff listings
when reporting test failures.  Enforce this idiom on test files
that use init.sh, and allow projects to recognize an alternate
pattern for recognizing tests scripts that use a compare function.

* top/maint.mk (sc_prohibit_reversed_compare_failure): New rule,
moved here from coreutils.

Signed-off-by: Eric Blake <address@hidden>
---

>> You're welcome to remove it from coreutils' cfg.mk, too.
> 
> Okay, I'm now in the middle of coding up the move, and will post and
> push the patches if results look reasonable with libvirt.

Here's what I'm pushing to gnulib.  I tested it with libvirt, where
I had to add an override in cfg.mk to detect the problems:
 _test_script_regex = \<\(init\|test-lib\)\.sh\>

It threw me a bit that $prohibit is an ERE, but $containing is a BRE.
I wonder if we should fix $(_sc_search_regexp) to consistently use
ERE, but it would be an incompatible change for existing checks.

I also tested with grep and coreutils, at points both before and after
your recent global cleanups, to prove that it caught the problems and
that the problem is now fixed.  A slight tweak to the forbid pattern
is handy for actual cases I found in libvirt by manual inspection,
which had uses like 'compare "$actual" "$exp"' and 'compare file
file-exp'.  That tweak also exposed two places missed in coreutils,
which I will fix in the next patch to coreutils.

 ChangeLog    |    4 ++++
 top/maint.mk |   10 ++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 95d71fd..9735aa8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-11-29  Eric Blake  <address@hidden>

+       maint.mk: add syntax check for use of compare from init.sh
+       * top/maint.mk (sc_prohibit_reversed_compare_failure): New rule,
+       moved here from coreutils.
+
        manywarnings: drop -Wunsuffixed-float-constants
        * m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC): C99 does not allow
        '1.0D', which is the only way to silence this warning for 'double'.
diff --git a/top/maint.mk b/top/maint.mk
index 76844a0..e1375df 100644
--- a/top/maint.mk
+++ b/top/maint.mk
@@ -1157,6 +1157,16 @@ sc_cross_check_PATH_usage_in_tests:
                1>&2; exit 1; } || :;                                   \
        fi

+# BRE regex of file contents to identify a test script.
+_test_script_regex ?= \<init\.sh\>
+
+# In tests, use "compare expected actual", not the reverse.
+sc_prohibit_reversed_compare_failure:
+       @prohibit='\<compare [^ ]+ ([^ ]*exp|/dev/null)'                \
+       containing='$(_test_script_regex)'                              \
+       halt='reversed compare arguments'                               \
+         $(_sc_search_regexp)
+
 # #if HAVE_... will evaluate to false for any non numeric string.
 # That would be flagged by using -Wundef, however gnulib currently
 # tests many undefined macros, and so we can't enable that option.
-- 
1.7.7.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]