Hi Bruno.

On Saturday 12 November 2011, Bruno Haible wrote:
> Jim Meyering wrote:
> > > 2011-11-11  Bruno Haible  <[email protected]>
> > >
> > >       Fix test suite execution failure on OSF/1 5.1.
> > >       * tests/Makefile.am (TESTS_ENVIRONMENT): Use only the portable form 
> > > of
> > >       the 'export' shell built-in.
> > 
> > Thanks, but I'd like to find a way to resolve this that does not involve
> > repeating every envvar name.
> 
> If that's your requirement, how about this patch then? Tested on OSF/1 and
> Solaris. With this, "make check" passes in the tests/ directory.
> 
> 
> 2011-11-12  Bruno Haible  <[email protected]>
> 
>       Fix test suite execution failure on OSF/1 5.1.
>       * tests/Makefile.am (TESTS_ENVIRONMENT): Use a shell function, to
>       ensure that we use only the portable form of the 'export' shell
>       built-in.
> 
> --- grep-2.9.69-f91c/tests/Makefile.am        2011-10-10 14:41:27.000000000 
> +0200
> +++ grep-2.9.69-f91c/tests/Makefile.am        2011-11-12 13:52:58.000000000 
> +0100
> @@ -105,7 +105,20 @@
>  TESTS_ENVIRONMENT =                          \
>    tmp__=$$TMPDIR; test -d "$$tmp__" || tmp__=.;      \
>    TMPDIR=$$tmp__; export TMPDIR;             \
> -  export                                     \
> +                                             \
> +  export_with_values ()                                      \
> +  {                                                  \
> +    sed_extract_var='s/=.*//';                               \
> +    sed_quote_value="s/=\\(.*\\)/='\\1'/";           \
> +    for arg in "$$@"; do                             \
> +      var=`echo "$$arg" | sed -e "$$sed_extract_var"`;       \
> +      arg=`echo "$$arg" | sed -e "$$sed_quote_value"`;       \
> +      eval "$$arg";                                  \
> +      export "$$var";                                        \
> +    done;                                            \
> +  };                                                 \
> +                                             \
> +  export_with_values                         \
>
This might cause annoying slow-downs on systems where forks are more
expensive (i.e., MinGW and Cygwin).  What about doing something like
this instead, so that the extra forks are avoided when the shell is
Bash (as is the usual case under MinGW and Cygwin, if I'm not
mistaken):

  if test -n "$BASH_VERSION"; then
    export_with_values () { export "$@"; }
  else
    export_with_values () { ... your implementation here ... }
  fi

My testing shows that this idiom should work with at least bash 4.1,
3.2, 3.0, 2.05 and 2.0.

Regards,
  Stefano

Reply via email to