Subject: Re: [PATCH v2 10/11] test-lib: make it possible to override how test code is eval'd

From: Junio C Hamano <[email-masked]>
Date: Thu, 05 Jun 2014 14:11:19 -0700

Richard Hansen <[email-masked]> writes:

> Because test_eval_ is defined while zsh is in sh emulation mode, the
> shell code passed as an argument to test_expect_success would normally
> be evaluated in sh emulation mode.  However, with this change, it is
> now possible to evaluate the test code in zsh mode by adding the
> following line to a zsh-based test script:
>
>     emulate -R zsh -c 'test_eval_override () { eval "$*"; }'
>
> With test_eval_override defined in zsh emulation mode, the call to
> test_eval_override from test_eval_ will temporarily cause zsh to
> switch from sh emulation mode to zsh emulation mode.

Micronit: aren't all "zsh emulation mode"s above "zsh native mode"s?

In any case, the above explanation confuses me somewhat.  test_eval_
is fed a scriptlet defined for various test_expect_success tests,
and they are written in POSIX shells, not zsh, so wouldn't it be
wrong to run them as if they are zsh native scripts, following
non-POSIX shell syntax rules?

Puzzled...

> Signed-off-by: Richard Hansen <[email-masked]>
> ---
>  t/test-lib.sh | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index c081668..3779634 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -414,7 +414,12 @@ maybe_setup_valgrind () {
>  test_eval_ () {
>  	# This is a separate function because some tests use
>  	# "return" to end a test_expect_success block early.
> -	eval </dev/null >&3 2>&4 "$*"
> +	if command -v test_eval_override >/dev/null 2>&1
> +	then
> +		test_eval_override "$*"
> +	else
> +		eval "$*"
> +	fi </dev/null >&3 2>&4
>  }
>  
>  test_run_ () {