Re: [PATCH v3 13/35] userdiff tests: factor out test_diff_funcname() logic

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

 



Ævar Arnfjörð Bjarmason  <avarab@xxxxxxxxx> writes:

> Factor out logic in test_diff_funcname() into two helper functions,
> these will be useful in a follow-up commit where we'll do this munging
> in more than one place.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
> ---
>  t/t4018-diff-funcname.sh | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh
> index 2365f0e361e..8a8a7a99c88 100755
> --- a/t/t4018-diff-funcname.sh
> +++ b/t/t4018-diff-funcname.sh
> @@ -75,6 +75,17 @@ test_expect_success 'setup hunk header tests' '
>  	git -C t4018 add .
>  '
>  
> +do_change_me () {
> +	file=$1
> +	sed -e "s/ChangeMe/IWasChanged/" <"$file" >tmp &&
> +	mv tmp "$file"
> +}
> +
> +last_diff_context_line () {

What this helper computes looks more like header line for each and
every hunk, not just the last one, to me.  Misnamed?

> +	file=$1
> +	sed -n -e "s/^.*@@$//p" -e "s/^.*@@ //p" <$file

Style.

 - Redirection operators should be written with space before, but no
   space after them.  In other words, write 'echo test >"$file"'
   instead of 'echo test> $file' or 'echo test > $file'.  Note that
   even though it is not required by POSIX to double-quote the
   redirection target in a variable (as shown above), our code does so
   because some versions of bash issue a warning without the quotes.

In any case, I wonder if this kind of clean-up should have been done
immediately before step 11/35, not after 11/35 started rewriting the
framework.  Any touch-up done after 11/35 risks smelling like "oops,
we found a better way to write it after we did the big rewrite".

> +}
> +
>  # check each individual file
>  for i in $(git -C t4018 ls-files)
>  do
> @@ -85,13 +96,12 @@ do
>  
>  		# add test file to the index
>  		git add \"$i\" &&
> -		# place modified file in the worktree
> -		sed -e 's/ChangeMe/IWasChanged/' <\"t4018/$i.content\" >\"$i\"
> +		do_change_me \"$i\"
>  	"
>  
>  	test_expect_success "hunk header: $i" "
>  		git diff -U1 $i >diff &&
> -		sed -n -e 's/^.*@@$//p' -e 's/^.*@@ //p' <diff >ctx &&
> +		last_diff_context_line diff >ctx &&
>  		test_cmp t4018/$i.header ctx
>  	"
>  done




[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]

  Powered by Linux