t5530: modernize tests

Refactor tests to follow modern best practices:

  - Merge together tests that set up and verify a single use case.

  - Drop empty newlines at the beginning and end of test bodies.

  - Don't change directories in the main test body.

  - Remove an unused `D` variable.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2025-09-05 08:18:01 +02:00
committed by Junio C Hamano
parent 16bd9f20a4
commit 7a57fb1a59

View File

@@ -4,8 +4,6 @@ test_description='errors in upload-pack'
. ./test-lib.sh . ./test-lib.sh
D=$(pwd)
corrupt_repo () { corrupt_repo () {
object_sha1=$(git rev-parse "$1") && object_sha1=$(git rev-parse "$1") &&
ob=$(expr "$object_sha1" : "\(..\)") && ob=$(expr "$object_sha1" : "\(..\)") &&
@@ -21,11 +19,7 @@ test_expect_success 'setup and corrupt repository' '
test_tick && test_tick &&
echo changed >file && echo changed >file &&
git commit -a -m changed && git commit -a -m changed &&
corrupt_repo HEAD:file corrupt_repo HEAD:file &&
'
test_expect_success 'fsck fails' '
test_must_fail git fsck test_must_fail git fsck
' '
@@ -40,17 +34,12 @@ test_expect_success 'upload-pack fails due to error in pack-objects packing' '
' '
test_expect_success 'corrupt repo differently' ' test_expect_success 'corrupt repo differently' '
git hash-object -w file && git hash-object -w file &&
corrupt_repo HEAD^^{tree} corrupt_repo HEAD^^{tree} &&
'
test_expect_success 'fsck fails' '
test_must_fail git fsck test_must_fail git fsck
' '
test_expect_success 'upload-pack fails due to error in rev-list' '
test_expect_success 'upload-pack fails due to error in rev-list' '
printf "%04xwant %s\n%04xshallow %s00000009done\n0000" \ printf "%04xwant %s\n%04xshallow %s00000009done\n0000" \
$(($hexsz + 10)) $(git rev-parse HEAD) \ $(($hexsz + 10)) $(git rev-parse HEAD) \
$(($hexsz + 12)) $(git rev-parse HEAD^) >input && $(($hexsz + 12)) $(git rev-parse HEAD^) >input &&
@@ -59,7 +48,6 @@ test_expect_success 'upload-pack fails due to error in rev-list' '
' '
test_expect_success 'upload-pack fails due to bad want (no object)' ' test_expect_success 'upload-pack fails due to bad want (no object)' '
printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \ printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
$(($hexsz + 29)) $(test_oid deadbeef) >input && $(($hexsz + 29)) $(test_oid deadbeef) >input &&
test_must_fail git upload-pack . <input >output 2>output.err && test_must_fail git upload-pack . <input >output 2>output.err &&
@@ -69,7 +57,6 @@ test_expect_success 'upload-pack fails due to bad want (no object)' '
' '
test_expect_success 'upload-pack fails due to bad want (not tip)' ' test_expect_success 'upload-pack fails due to bad want (not tip)' '
oid=$(echo an object we have | git hash-object -w --stdin) && oid=$(echo an object we have | git hash-object -w --stdin) &&
printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \ printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
$(($hexsz + 29)) "$oid" >input && $(($hexsz + 29)) "$oid" >input &&
@@ -80,7 +67,6 @@ test_expect_success 'upload-pack fails due to bad want (not tip)' '
' '
test_expect_success 'upload-pack fails due to error in pack-objects enumeration' ' test_expect_success 'upload-pack fails due to error in pack-objects enumeration' '
printf "%04xwant %s\n00000009done\n0000" \ printf "%04xwant %s\n00000009done\n0000" \
$((hexsz + 10)) $(git rev-parse HEAD) >input && $((hexsz + 10)) $(git rev-parse HEAD) >input &&
test_must_fail git upload-pack . <input >/dev/null 2>output.err && test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
@@ -105,18 +91,9 @@ test_expect_success 'upload-pack tolerates EOF just after stateless client wants
test_cmp expect actual test_cmp expect actual
' '
test_expect_success 'create empty repository' '
mkdir foo &&
cd foo &&
git init
'
test_expect_success 'fetch fails' ' test_expect_success 'fetch fails' '
git init foo &&
test_must_fail git fetch .. main test_must_fail git -C foo fetch .. main
' '
test_done test_done