git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] t: detect and signal failure within loop

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 22, 2022, 20:59 UTC
Message-ID
<xmqqfshoataq.fsf@gitster.g>
In-Reply-To
<xmqqwnb0av09.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 18 quoted lines
> "Eric Sunshine via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> diff --git a/t/t5329-pack-objects-cruft.sh b/t/t5329-pack-objects-cruft.sh
>> index 8968f7a08d8..6049e2c1d78 100755
>> --- a/t/t5329-pack-objects-cruft.sh
>> +++ b/t/t5329-pack-objects-cruft.sh
>> @@ -29,7 +29,7 @@ basic_cruft_pack_tests () {
>>  				while read oid
>>  				do
>>  					path="$objdir/$(test_oid_to_path "$oid")" &&
>> -					printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")"
>> +					printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")" || exit 1
>>  				done |
>>  				sort -k1
>>  			) >expect &&
>
> With the loop being on the upstream of a pipe, does the added "exit
> 1" have any effect?
And the answer is "no".  Without use of rhetorical question:
    The loop is on the upstream side of a pipe, so "exit 1" will be
    lost.  "sort -k1" will get a shortened output, unless the
    failure happens at the last iteration, so it is likely that the
    test may fail, but relying on the "expect" (what is supposed to
    have the _right_ answer) file not being right to get our
    breakage noticed does not sound right.
> Everything else in these three patches looked very sensible, but
> this one I found questionable.

As to the questionable one, we could probably do something like the attached patch if we really wanted to. We can guarantee that this "expect" will never match any "actual", which is output from pack-mtimes test tool command. Whatever "tricky/ugly" approach we choose to take, I think this one deserves to be done in a single patch on its own with an explanation.

----- >8 --------- >8 --------- >8 --------- >8 ---- t5329: notice a failure within a loop

We try to write "|| return 1" at the end of a sequence of &&-chained command in a loop of our tests, so that a failure of any step during the earlier iteration of the loop can properly be caught.

There is one loop in this test script that is used to compute the expected result, that will be later compared with an actual output produced by the "test-tool pack-mtimes" command. This particular loop, however, is placed on the upstream side of a pipe, whose non-zero exit code does not get noticed.

Emit a line that will never be produced by the "test-tool pack-mtimes" to cause the later comparison to fail. As we use test_cmp to compare this "expected output" file with the "actual output", the "error message" we are emitting into the expected output stream will stand out and shown to the tester.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t5329-pack-objects-cruft.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git c/t/t5329-pack-objects-cruft.sh w/t/t5329-pack-objects-cruft.sh
index 6049e2c1d7..43d752acc7 100755
--- c/t/t5329-pack-objects-cruft.sh
+++ w/t/t5329-pack-objects-cruft.sh
@@ -29,7 +29,8 @@ basic_cruft_pack_tests () {
 				while read oid
 				do
 					path="$objdir/$(test_oid_to_path "$oid")" &&
-					printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")"
+					printf "%s %d\n" "$oid" "$(test-tool chmtime --get "$path")" ||
+					echo "object list generation failed for $obj"
 				done |
 				sort -k1
 			) >expect &&
Previous: Junio C HamanoNext: Johannes Sixt
Message 7 of 10 in “tests: fix broken &&-chains & abort loops on error”
  1. 0/3 tests: fix broken &&-chains & abort loops on errorEric Sunshine via GitGitGadget, Aug 22, 2022
  2. 1/3 t2407: fix broken &&-chains in compound statementEric Sunshine via GitGitGadget, Aug 22, 2022
  3. 2/3 t1092: fix buggy sparse "blame" testEric Sunshine via GitGitGadget, Aug 22, 2022
  4. Derrick StoleeAug 22, 2022
  5. 3/3 t: detect and signal failure within loopEric Sunshine via GitGitGadget, Aug 22, 2022
  6. Junio C HamanoAug 22, 2022
  7. Junio C HamanoAug 22, 2022
  8. Johannes SixtAug 23, 2022
  9. Elijah NewrenAug 23, 2022
  10. Eric SunshineAug 28, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.