On 11/13/2016 03:38 AM, Jim Meyering wrote:
> I noticed many tests that compare directly with "$?". However, we now
> have the "returns_" function (from init.sh) that can be used to make
> the resulting code a little less error-prone: all on one line/stmt, it
> is harder to accidentally insert code that accidentally clobbers "$?".
> 
> Here's an example of what most of these changes look like:
> 
>   -ls -l --time-style=XX > out 2> err
>   -test $? = 2 || fail=1
>   +returns_ 2 ls -l --time-style=XX > out 2> err || fail=1

Nice work, thanks!

BTW: what was your search pattern?  I mean, is there a reason
you left places like the following alone?


  $ git grep -B1 -F '$? = ' -- tests
  ..
  tests/misc/stdbuf.sh-stdbuf -ol true # Capital 'L' required
  tests/misc/stdbuf.sh:test $? = 125 || fail=1 # Internal error is a particular 
status
  ..

  $ git grep -B1 -F '$? != ' -- tests
  tests/du/8gb.sh-dd bs=1 seek=8G of=big < /dev/null 2> /dev/null
  tests/du/8gb.sh:if test $? != 0; then
  ..


Furthermore, we need to tweak a syntax-check, see attached.

Thanks & have a nice day,
Berny

>From 40122a96dfa97c25c26abb3f47fa8d577cffa666 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <[email protected]>
Date: Sun, 13 Nov 2016 18:16:32 +0100
Subject: [PATCH] maint: add 'returns_' to exclude list in
 sc_prohibit_and_fail_1

The previous commit v8.25-96-g22063c8 lets 'make syntax-check' fail,
because the above check falsely detects a case where 'returns_' is
already in use.

* cfg.mk (sc_prohibit_and_fail_1): Add 'returns_' to exclude list.
---
 cfg.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cfg.mk b/cfg.mk
index 11e42b9..a05fc02 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -502,7 +502,7 @@ sc_prohibit_fail_0:
 # independently check its contents and thus detect any crash messages.
 sc_prohibit_and_fail_1:
 	@prohibit='&& fail=1'						\
-	exclude='(stat|kill|test |EGREP|grep|compare|2> *[^/])'		\
+	exclude='(returns_|stat|kill|test |EGREP|grep|compare|2> *[^/])' \
 	halt='&& fail=1 detected. Please use: returns_ 1 ... || fail=1'	\
 	in_vc_files='^tests/'						\
 	  $(_sc_search_regexp)
-- 
2.1.4

Reply via email to