diff mbox series

[v2,08/11] upload-pack tests: avoid a non-zero "grep" exit status

Message ID 20210116153554.12604-9-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series tests: add a bash "set -o pipefail" test mode | expand

Commit Message

Ævar Arnfjörð Bjarmason Jan. 16, 2021, 3:35 p.m. UTC
Continue changing a test that 763b47bafa (t5703: stop losing return
codes of git commands, 2019-11-27) already refactored. A follow-up
commit will add support for testing under bash's "set -o pipefail",
under that mode this test will fail because sometimes there's no
commits in the "objs" output.

It's easier to just fix this than to exempt these tests under a
soon-to-be added "set -o pipefail" test mode. So let's do that.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t5703-upload-pack-ref-in-want.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Junio C Hamano Jan. 16, 2021, 9:48 p.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Continue changing a test that 763b47bafa (t5703: stop losing return
> codes of git commands, 2019-11-27) already refactored. A follow-up
> commit will add support for testing under bash's "set -o pipefail",
> under that mode this test will fail because sometimes there's no
> commits in the "objs" output.
>
> It's easier to just fix this than to exempt these tests under a
> soon-to-be added "set -o pipefail" test mode. So let's do that.

Hmph, if you do not like the fact that grep indicates hits vs no
hits via its exit codes and you are purely interested in its text
munging utility, why not use a more appropriate tool than grep piped
to cut?  Running the same grep twice just to work around its exit
code looks doubly suboptimal.

	sed -n -e 's/\([0-9a-f][0-9a-f]*\) commit .*/\1/p' objs |
	sort >actual_commits

perhaps?

> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/t5703-upload-pack-ref-in-want.sh | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
> index eab966985b..420cf2bbde 100755
> --- a/t/t5703-upload-pack-ref-in-want.sh
> +++ b/t/t5703-upload-pack-ref-in-want.sh
> @@ -16,7 +16,11 @@ get_actual_commits () {
>  	test-tool pkt-line unpack-sideband <out >o.pack &&
>  	git index-pack o.pack &&
>  	git verify-pack -v o.idx >objs &&
> -	grep commit objs | cut -d" " -f1 | sort >actual_commits
> +	>actual_commits &&
> +	if grep -q commit objs
> +	then
> +		grep commit objs | cut -d" " -f1 | sort >actual_commits
> +	fi
>  }
>  
>  check_output () {
diff mbox series

Patch

diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh
index eab966985b..420cf2bbde 100755
--- a/t/t5703-upload-pack-ref-in-want.sh
+++ b/t/t5703-upload-pack-ref-in-want.sh
@@ -16,7 +16,11 @@  get_actual_commits () {
 	test-tool pkt-line unpack-sideband <out >o.pack &&
 	git index-pack o.pack &&
 	git verify-pack -v o.idx >objs &&
-	grep commit objs | cut -d" " -f1 | sort >actual_commits
+	>actual_commits &&
+	if grep -q commit objs
+	then
+		grep commit objs | cut -d" " -f1 | sort >actual_commits
+	fi
 }
 
 check_output () {