t5701: use test_file_size() to get the size of a file

The 'basics of object-info' test runs 'wc -c | xargs' twice to get the
size of two.t. The pipe to xargs is only there to strip the blanks
that some platforms pad the output of wc with.

Use the test_file_size() helper, which outputs the size directly, and
store the result in a variable. Because 'git rev-parse two:two.t' is
also run multiple times, store its output in a variable as well.

Storing them in variables outside the HERE-document has the added
benefit of preserving their exit statuses.

Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Pablo Sabater
2026-08-04 20:42:55 +02:00
committed by Junio C Hamano
parent 669c4ad5dc
commit 8de924dc94

View File

@@ -344,20 +344,23 @@ test_expect_success 'unexpected lines are not allowed in fetch request' '
test_expect_success 'basics of object-info' '
test_config transfer.advertiseObjectInfo true &&
two_oid=$(git rev-parse two:two.t) &&
two_size=$(test_file_size two.t) &&
test-tool pkt-line pack >in <<-EOF &&
command=object-info
object-format=$(test_oid algo)
0001
size
oid $(git rev-parse two:two.t)
oid $(git rev-parse two:two.t)
oid $two_oid
oid $two_oid
0000
EOF
cat >expect <<-EOF &&
size
$(git rev-parse two:two.t) $(wc -c <two.t | xargs)
$(git rev-parse two:two.t) $(wc -c <two.t | xargs)
$two_oid $two_size
$two_oid $two_size
0000
EOF