[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] tests: use printf, not echo in init.sh's warn_ function
From: |
Jim Meyering |
Subject: |
[PATCH] tests: use printf, not echo in init.sh's warn_ function |
Date: |
Mon, 19 Sep 2011 19:29:40 +0200 |
FYI, this syncs this change from coreutils' init.sh:
>From c37da522c67143c74f2a6ddc25dda4b87a0a5032 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Mon, 19 Sep 2011 19:27:53 +0200
Subject: [PATCH] tests: use printf, not echo in init.sh's warn_ function
* tests/init.sh (warn_): Use printf, not echo. The latter would
misbehave when given strings containing a backslash or starting
with e.g., -n. James Youngman suggested setting IFS.
---
ChangeLog | 5 +++++
tests/init.sh | 15 ++++++++++++++-
2 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 50a43e8..cdf1379 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2011-09-19 Jim Meyering <address@hidden>
+ tests: use printf, not echo in init.sh's warn_ function
+ * tests/init.sh (warn_): Use printf, not echo. The latter would
+ misbehave when given strings containing a backslash or starting
+ with e.g., -n. James Youngman suggested setting IFS.
+
getcwd: don't fail in a deep directory on a system without openat
Before this change, getcwd would fail when called from a directory
of depth PATH_MAX / 3 or greater. That was due to the fact that
diff --git a/tests/init.sh b/tests/init.sh
index e6f5f1c..373d9d4 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -74,7 +74,20 @@ Exit () { set +e; (exit $1); exit $1; }
# the reason for skip/failure to console, rather than to the .log files.
: ${stderr_fileno_=2}
-warn_ () { echo "$@" 1>&$stderr_fileno_; }
+# Note that correct expansion of "$*" depends on IFS starting with ' '.
+# Always write the full diagnostic to stderr.
+# When stderr_fileno_ is not 2, also emit the first line of the
+# diagnostic to that file descriptor.
+warn_ ()
+{
+ # If IFS does not start with ' ', set it and emit the warning in a subshell.
+ case $IFS in
+ ' '*) printf '%s\n' "$*" >&2
+ test $stderr_fileno_ = 2 \
+ || { printf '%s\n' "$*" | sed 1q >&$stderr_fileno_ ; } ;;
+ *) (IFS=' '; warn_ "$@");;
+ esac
+}
fail_ () { warn_ "$ME_: failed test: $@"; Exit 1; }
skip_ () { warn_ "$ME_: skipped test: $@"; Exit 77; }
fatal_ () { warn_ "$ME_: hard error: $@"; Exit 99; }
--
1.7.7.rc0.362.g5a14
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] tests: use printf, not echo in init.sh's warn_ function,
Jim Meyering <=