Re: [PATCH v2] tests: lint for run-away here-doc

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

 



Hi,

Junio C Hamano wrote:

> We found a few run-away here documents that are started with an
> end-of-here-doc marker that is incorrectly spelled, e.g.
>
> 	git some command >actual &&
> 	cat <<EOF >expect
> 	...
> 	EOF &&
> 	test_cmp expect actual
>
> which ends up slurping the entire remainder of the script as if it
> were the data.  Often the command that gets misused like this exits
> without failure (e.g. "cat" in the above example), which makes the
> command appear to work, without eve executing the remainder of the

s/eve/ever/

> test.
>
> Piggy-back on the test that catches &&-chain breakage to detect this
> case as well.
>
> Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
> ---

I also wonder if we can use an "sh -n" style syntax check some day,
but that's likely harder.

[...]
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -624,9 +624,9 @@ test_run_ () {
>  		trace=
>  		# 117 is magic because it is unlikely to match the exit
>  		# code of other programs
> -		test_eval_ "(exit 117) && $1"
> -		if test "$?" != 117; then
> -			error "bug in the test script: broken &&-chain: $1"
> +		if test "OK-117" != "$(test_eval_ "(exit 117) && $1${LF}${LF}echo OK-\$?" 3>&1)"
> +		then
> +			error "bug in the test script: broken &&-chain or run-away HERE-DOC: $1"
>  		fi

Neat.  Why the double-LF?

In some shells, the 3>&1 will last past the function call.
Fortunately, the $() substitution creates a subshell so this doesn't
affect anything later on.

test_eval_inner_ contains a warning not to append anything after the
commands to be evaluated, since whatever you append would pollute -x
tracing output.  Fortunately, in this context we have already set
trace= so the warning does not apply.

Reviewed-by: Jonathan Nieder <jrnieder@xxxxxxxxx>

Thanks.



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]