coreutils
[Top][All Lists]
Advanced

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

RE: [PATCH] tests: use printf, not echo in init.sh's warn_ function


From: Voelker, Bernhard
Subject: RE: [PATCH] tests: use printf, not echo in init.sh's warn_ function
Date: Mon, 20 Jun 2011 09:25:49 +0200

Jim Meyering wrote:

> From 7f8d9892fb4ce29821fc824defaa6e0d32740feb Mon Sep 17 00:00:00 2001
> From: Jim Meyering <address@hidden>
> Date: Tue, 14 Jun 2011 15:37:48 +0200
> Subject: [PATCH 1/3] 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.
> ---
>  tests/init.sh |   12 +++++++++++-
>  1 files changed, 11 insertions(+), 1 deletions(-)
> 
> diff --git a/tests/init.sh b/tests/init.sh
> index 4a52626..5f06b5e 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; }
> --
> 1.7.6.rc0.293.g40857
> 
> 
> From 13672ec3211a5a77caf16dc24b83100d57e2a2ec Mon Sep 17 00:00:00 2001
> From: Jim Meyering <address@hidden>
> Date: Fri, 17 Jun 2011 09:02:09 +0200
> Subject: [PATCH 2/3] tests: make init.sh's warn_ emit to both the tty and the
>  log file
> 
> * tests/init.sh (warn_): When $stderr_fileno_ != 2,
> emit the diagnostic to both the tty and the log file.
> ---
>  tests/init.sh |    8 ++++++--
>  1 files changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/init.sh b/tests/init.sh
> index 5f06b5e..d7a5d83 100644
> --- a/tests/init.sh
> +++ b/tests/init.sh
> @@ -75,8 +75,12 @@ Exit () { set +e; (exit $1); exit $1; }
>  : ${stderr_fileno_=2}
> 
>  # Call w2_ only via warn_, since correct expansion of "$*" depends on
> -# IFS starting with ' '.
> -w2_ () { printf '%s\n' "$*" 1>&$stderr_fileno_ ; }
> +# 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.
> +w2_ () { printf '%s\n' "$*" >&2
> +         test $stderr_fileno_ = 2 \
> +           || { printf '%s\n' "$*" | head -1 >&$stderr_fileno_ ; } ; }
>  warn_ ()
>  {
>    # If IFS does not start with ' ', set it and emit the warning in a 
> subshell.
> --
> 1.7.6.rc0.293.g40857

why not re-using the same function, i.e. why not retire w2_?
btw: isn't head -1 deprecated use?

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' "$*" | head -n 1 >&$stderr_fileno_ ; } ;;
    *) (IFS=' '; warn_ "$@");;
  esac
}

Have a nice day,
Berny


reply via email to

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