summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-06-14 15:37:48 +0200
committerJim Meyering <meyering@redhat.com>2011-06-17 08:54:08 +0200
commit7f8d9892fb4ce29821fc824defaa6e0d32740feb (patch)
tree7b063f6c3a212ca1131d1bafecabd0ff1ec02419
parent6b687452d8c08a1b00f53402caf651229cdb0c51 (diff)
downloadcoreutils-7f8d9892fb4ce29821fc824defaa6e0d32740feb.tar.xz
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.
-rw-r--r--tests/init.sh12
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/init.sh b/tests/init.sh
index 4a5262630..5f06b5e0a 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -74,7 +74,17 @@ 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_; }
+# Call w2_ only via warn_, since correct expansion of "$*" depends on
+# IFS starting with ' '.
+w2_ () { printf '%s\n' "$*" 1>&$stderr_fileno_ ; }
+warn_ ()
+{
+ # If IFS does not start with ' ', set it and emit the warning in a subshell.
+ case $IFS in
+ ' '*) w2_ "$@";;
+ *) (IFS=' '; w2_ "$@");;
+ esac
+}
fail_ () { warn_ "$ME_: failed test: $@"; Exit 1; }
skip_ () { warn_ "$ME_: skipped test: $@"; Exit 77; }
fatal_ () { warn_ "$ME_: hard error: $@"; Exit 99; }