Re: [GSoC][PATCH 1/1] t9116: avoid using pipes

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

 



Thanks for contributing to Git.

On Sun, Mar 22, 2020 at 06:16:19PM +0530, Shanthanu wrote:
> Commit de26f02db1 (t9001, t9116: avoid pipes, 2020-02-14) noticed that
> when grepping through the output of a command, there is always a
> chance that something could go wrong.

That "something could go wrong" may deserve little bit more explanation
in the commit message.
One thing when using pipes is that we may loose return codes of programs
being part of the pipe.
The other thing is that it is hard to debug, if the test case fails.
Having the "out" file left on disk allows manual inspection, and tracking
down why it failed.
Having said this, we can make the test case even easier to debug, and consistant
with other test cases, please see below.

>
> So, redirect the output into a file and grep that file. Thus the log
> can be inspected easily if the grep fails.
>
> Signed-off-by: Shanthanu <shanthanu.s.rai9@xxxxxxxxx>
> ---
>
> In test 'test ascending revision range with --show-commit (sha1)',
> 'out1' variable is used since 'out' variable was already in use.
>
>  t/t9116-git-svn-log.sh | 36 ++++++++++++++++++++++++------------
>  1 file changed, 24 insertions(+), 12 deletions(-)
>
> diff --git a/t/t9116-git-svn-log.sh b/t/t9116-git-svn-log.sh
> index 0a9f1ef366..d82aa0fab9 100755
> --- a/t/t9116-git-svn-log.sh
> +++ b/t/t9116-git-svn-log.sh
> @@ -61,12 +61,14 @@ printf 'r1 \nr2 \nr4 \n' > expected-range-r1-r2-r4
>
>  test_expect_success 'test ascending revision range' "
>  	git reset --hard origin/trunk &&
> -	git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2-r4 -
> +	git svn log -r 1:4 >out &&
> +	grep '^r[0-9]' out | cut -d'|' -f1 | test_cmp expected-range-r1-r2-r4 -

That could be written as
	grep '^r[0-9]' out | cut -d'|' -f1 >actual &&
	test_cmp expected-range-r1-r2-r4 actual

Or something in that style  (and similar below).
What do you think ?

>  	"
>
>  test_expect_success 'test ascending revision range with --show-commit' "
>  	git reset --hard origin/trunk &&
> -	git svn log --show-commit -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2-r4 -
> +	git svn log --show-commit -r 1:4 >out &&
> +	grep '^r[0-9]' out | cut -d'|' -f1 | test_cmp expected-range-r1-r2-r4 -
>  	"
>
>  test_expect_success 'test ascending revision range with --show-commit (sha1)' "
> @@ -74,7 +76,8 @@ test_expect_success 'test ascending revision range with --show-commit (sha1)' "
>  	git svn find-rev r2 >>expected-range-r1-r2-r4-sha1 &&
>  	git svn find-rev r4 >>expected-range-r1-r2-r4-sha1 &&
>  	git reset --hard origin/trunk &&
> -	git svn log --show-commit -r 1:4 | grep '^r[0-9]' | cut -d'|' -f2 >out &&
> +	git svn log --show-commit -r 1:4 >out1 &&
> +	grep '^r[0-9]' out1 | cut -d'|' -f2 >out &&
>  	git rev-parse \$(cat out) >actual &&
>  	test_cmp expected-range-r1-r2-r4-sha1 actual
>  	"
> @@ -83,45 +86,52 @@ printf 'r4 \nr2 \nr1 \n' > expected-range-r4-r2-r1
>
>  test_expect_success 'test descending revision range' "
>  	git reset --hard origin/trunk &&
> -	git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4-r2-r1 -
> +	git svn log -r 4:1 >out &&
> +	grep '^r[0-9]' out | cut -d'|' -f1 | test_cmp expected-range-r4-r2-r1 -
>  	"
>
>  printf 'r1 \nr2 \n' > expected-range-r1-r2
>
>  test_expect_success 'test ascending revision range with unreachable revision' "
>  	git reset --hard origin/trunk &&
> -	git svn log -r 1:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2 -
> +	git svn log -r 1:3 >out &&
> +	grep '^r[0-9]' out | cut -d'|' -f1 | test_cmp expected-range-r1-r2 -
>  	"
>
>  printf 'r2 \nr1 \n' > expected-range-r2-r1
>
>  test_expect_success 'test descending revision range with unreachable revision' "
>  	git reset --hard origin/trunk &&
> -	git svn log -r 3:1 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2-r1 -
> +	git svn log -r 3:1 >out &&
> +	grep '^r[0-9]' out | cut -d'|' -f1 | test_cmp expected-range-r2-r1 -
>  	"
>
>  printf 'r2 \n' > expected-range-r2
>
>  test_expect_success 'test ascending revision range with unreachable upper boundary revision and 1 commit' "
>  	git reset --hard origin/trunk &&
> -	git svn log -r 2:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2 -
> +	git svn log -r 2:3 >out &&
> +	grep '^r[0-9]' out | cut -d'|' -f1 | test_cmp expected-range-r2 -
>  	"
>
>  test_expect_success 'test descending revision range with unreachable upper boundary revision and 1 commit' "
>  	git reset --hard origin/trunk &&
> -	git svn log -r 3:2 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2 -
> +	git svn log -r 3:2 >out &&
> +	grep '^r[0-9]' out | cut -d'|' -f1 | test_cmp expected-range-r2 -
>  	"
>
>  printf 'r4 \n' > expected-range-r4
>
>  test_expect_success 'test ascending revision range with unreachable lower boundary revision and 1 commit' "
>  	git reset --hard origin/trunk &&
> -	git svn log -r 3:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 -
> +	git svn log -r 3:4 >out &&
> +	grep '^r[0-9]' out | cut -d'|' -f1 | test_cmp expected-range-r4 -
>  	"
>
>  test_expect_success 'test descending revision range with unreachable lower boundary revision and 1 commit' "
>  	git reset --hard origin/trunk &&
> -	git svn log -r 4:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 -
> +	git svn log -r 4:3 >out &&
> +	grep '^r[0-9]' out | cut -d'|' -f1 | test_cmp expected-range-r4 -
>  	"
>
>  printf -- '------------------------------------------------------------------------\n' > expected-separator
> @@ -138,12 +148,14 @@ test_expect_success 'test descending revision range with unreachable boundary re
>
>  test_expect_success 'test ascending revision range with unreachable boundary revisions and 1 commit' "
>  	git reset --hard origin/trunk &&
> -	git svn log -r 3:5 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 -
> +	git svn log -r 3:5 >out &&
> +	grep '^r[0-9]' out | cut -d'|' -f1 | test_cmp expected-range-r4 -
>  	"
>
>  test_expect_success 'test descending revision range with unreachable boundary revisions and 1 commit' "
>  	git reset --hard origin/trunk &&
> -	git svn log -r 5:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 -
> +	git svn log -r 5:3 >out &&
> +	grep '^r[0-9]' out | cut -d'|' -f1 | test_cmp expected-range-r4 -
>  	"
>
>  test_done
> --
> 2.26.0.rc2.28.g7fcb965970
>




[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