autoconf-patches
[Top][All Lists]
Advanced

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

[PATCH] autotest: Avoid nonportable : redirections in functions.


From: Nick Bowler
Subject: [PATCH] autotest: Avoid nonportable : redirections in functions.
Date: Mon, 8 Mar 2021 20:06:40 -0500

Using : with redirections in a shell function is one of the nonportable
constructs discussed in the Autoconf manual; ยง11.4 "File Descriptors":

  Solaris 10 sh will try to optimize away a : command (even if it is
  redirected) ... in a shell function after the first call:
  [...]
  $ f () { : >$1; }; f y1; f y2; f y3;
  $ ls y*
  y1

Nevertheless, autotest-generated testsuites use exactly this sort of
redirection when preparing the environment for AT_CHECK.  The result,
when using such a shell, is that the stdout and stderr files do not
get truncated between multiple AT_CHECK invocations in a test group:
instead, each AT_CHECK command appends to the output of the previous
one.  This obviously does not end well.

The manual suggests using eval to work around this limitation, so
let's do just that.

* lib/autotest/general.m4 (at_fn_check_prepare_[no]trace): Work around
failure of : redirections in some shells.
---
 lib/autotest/general.m4 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/autotest/general.m4 b/lib/autotest/general.m4
index 40c92d93..3e2bf510 100644
--- a/lib/autotest/general.m4
+++ b/lib/autotest/general.m4
@@ -260,7 +260,7 @@ at_fn_check_prepare_notrace ()
   $at_trace_echo "Not enabling shell tracing (command contains $[1])"
   AS_ECHO(["$[2]"]) >"$at_check_line_file"
   at_check_trace=: at_check_filter=:
-  : >"$at_stdout"; : >"$at_stderr"
+  eval ': >"$at_stdout"; : >"$at_stderr"'
 }
 
 AS_FUNCTION_DESCRIBE([at_fn_check_prepare_trace], [LINE],
@@ -270,7 +270,7 @@ at_fn_check_prepare_trace ()
 {
   AS_ECHO(["$[1]"]) >"$at_check_line_file"
   at_check_trace=$at_traceon at_check_filter=$at_check_filter_trace
-  : >"$at_stdout"; : >"$at_stderr"
+  eval ': >"$at_stdout"; : >"$at_stderr"'
 }
 
 AS_FUNCTION_DESCRIBE([at_fn_check_prepare_dynamic], [COMMAND LINE],
-- 
2.26.2




reply via email to

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