]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: fix false fails due to passing env vars to returns_
authorPádraig Brady <P@draigBrady.com>
Tue, 22 Nov 2016 01:23:22 +0000 (01:23 +0000)
committerPádraig Brady <P@draigBrady.com>
Tue, 22 Nov 2016 20:04:25 +0000 (20:04 +0000)
On BSD /bin/sh it was seen that unexported env vars passed to
returns_() would not be propagated to the wrapped command.

* cfg.mk (sc_prohibit_env_returns): Add a syntax check to disallow.
* tests/misc/csplit-io-err.sh: Rearrange to export vars in a subshell.
* tests/rm/rm-readdir-fail.sh: Likewise.
* tests/misc/nohup.sh: Export and unset vars around returns_.
* tests/misc/printenv.sh: Likewise.
Reported by Assaf Gordon

cfg.mk
tests/misc/csplit-io-err.sh
tests/misc/nohup.sh
tests/misc/printenv.sh
tests/rm/rm-readdir-fail.sh

diff --git a/cfg.mk b/cfg.mk
index 5d42bf14efc24b6141962223fe53d5ae1db32cab..9e4f8a31a7568d34b419c6cedcb5ba8528d41492 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -510,6 +510,14 @@ sc_prohibit_and_fail_1:
        in_vc_files='^tests/'                                           \
          $(_sc_search_regexp)
 
+# Ensure that env vars are not passed through returns_ as
+# that was seen to fail on FreeBSD /bin/sh at least
+sc_prohibit_env_returns:
+       @prohibit='=[^ ]* returns_ '                                    \
+       halt='Passing env vars to returns_ is non portable'             \
+       in_vc_files='^tests/'                                           \
+         $(_sc_search_regexp)
+
 # The mode part of a setfacl -m option argument must be three bytes long.
 # I.e., an argument of user:bin:rw or user:bin:r will make Solaris 10's
 # setfacl reject it with: "Unrecognized character found in mode field".
index 982df161f80cd17639ce3945f801462015fd460f..900e38bee797c13d512bdfc19cc41a5b98fd4e60 100755 (executable)
@@ -66,9 +66,9 @@ gcc_shared_ k.c k.so \
 # Split the input, and force fwrite() failure -
 # the 'csplit' command should fail with exit code 1
 # (checked with 'returns_ 1 ... || fail=1')
-seq 10 \
-  | LD_PRELOAD=$LD_PRELOAD:./k.so returns_ 1 csplit - 1 4 2>out \
-  || fail=1
+seq 10 |
+(export LD_PRELOAD=$LD_PRELOAD:./k.so
returns_ 1 csplit - 1 4 2>out) || fail=1
 
 test -e preloaded || skip_ 'LD_PRELOAD interception failed'
 
index e9c8c389aed674283744039cdc180b28f455c8bd..1b43b606f05aef3ef41a7d002b6021ef5022a5e9 100755 (executable)
@@ -118,6 +118,8 @@ EOF
 # Make sure it fails with exit status of 125 when given too few arguments,
 # except that POSIX requires 127 in this case.
 returns_ 125 nohup >/dev/null 2>&1 || fail=1
-POSIXLY_CORRECT=1 returns_ 127 nohup >/dev/null 2>&1 || fail=1
+export POSIXLY_CORRECT=1
+returns_ 127 nohup >/dev/null 2>&1 || fail=1
+unset POSIXLY_CORRECT
 
 Exit $fail
index 2017e5df66b49ca374f6966107d739dcf97d0399..b33c0292c0050c8c38df04b3049ea2c1eb2adf6e 100755 (executable)
@@ -59,8 +59,10 @@ EOF
 compare exp out || fail=1
 
 # Exit status reflects missing variable, but remaining arguments processed.
-ENV_TEST1=a returns_ 1 env -- printenv ENV_TEST2 ENV_TEST1 > out || fail=1
-ENV_TEST1=a returns_ 1 env -- printenv ENV_TEST1 ENV_TEST2 >> out || fail=1
+export ENV_TEST1=a
+returns_ 1 env -- printenv ENV_TEST2 ENV_TEST1 > out || fail=1
+returns_ 1 env -- printenv ENV_TEST1 ENV_TEST2 >> out || fail=1
+unset ENV_TEST1
 cat <<EOF > exp || framework_failure_
 a
 a
index d9d8efdb4dea155a536b62ee15337c2701ac10bc..835d3424f8eab41e9413109543f00b4f52fedf0e 100755 (executable)
@@ -88,7 +88,8 @@ gcc_shared_ k.c k.so \
 export READDIR_PARTIAL
 for READDIR_PARTIAL in '' '1'; do
   rm -f preloaded
-  (LD_PRELOAD=$LD_PRELOAD:./k.so returns_ 1 rm -Rf dir 2>>err) || fail=1
+  (export LD_PRELOAD=$LD_PRELOAD:./k.so
+   returns_ 1 rm -Rf dir 2>>err) || fail=1
   test -f preloaded ||
     skip_ "internal test failure: maybe LD_PRELOAD doesn't work?"
 done