Skip to content

Commit 110c8fe

Browse files
committed
Merge branch 'ak/t1016-style'
Test modernization. * ak/t1016-style: t1016: clean up style
2 parents 6890c99 + a1fb77f commit 110c8fe

File tree

1 file changed

+130
-132
lines changed

1 file changed

+130
-132
lines changed

t/t1016-compatObjectFormat.sh

Lines changed: 130 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -24,84 +24,83 @@ TEST_PASSES_SANITIZE_LEAK=true
2424
# the commit is identical to the commit in the other repository.
2525

2626
compat_hash () {
27-
case "$1" in
28-
"sha1")
29-
echo "sha256"
30-
;;
31-
"sha256")
32-
echo "sha1"
33-
;;
34-
esac
27+
case "$1" in
28+
"sha1")
29+
echo "sha256"
30+
;;
31+
"sha256")
32+
echo "sha1"
33+
;;
34+
esac
3535
}
3636

3737
hello_oid () {
38-
case "$1" in
39-
"sha1")
40-
echo "$hello_sha1_oid"
41-
;;
42-
"sha256")
43-
echo "$hello_sha256_oid"
44-
;;
45-
esac
38+
case "$1" in
39+
"sha1")
40+
echo "$hello_sha1_oid"
41+
;;
42+
"sha256")
43+
echo "$hello_sha256_oid"
44+
;;
45+
esac
4646
}
4747

4848
tree_oid () {
49-
case "$1" in
50-
"sha1")
51-
echo "$tree_sha1_oid"
52-
;;
53-
"sha256")
54-
echo "$tree_sha256_oid"
55-
;;
56-
esac
49+
case "$1" in
50+
"sha1")
51+
echo "$tree_sha1_oid"
52+
;;
53+
"sha256")
54+
echo "$tree_sha256_oid"
55+
;;
56+
esac
5757
}
5858

5959
commit_oid () {
60-
case "$1" in
61-
"sha1")
62-
echo "$commit_sha1_oid"
63-
;;
64-
"sha256")
65-
echo "$commit_sha256_oid"
66-
;;
67-
esac
60+
case "$1" in
61+
"sha1")
62+
echo "$commit_sha1_oid"
63+
;;
64+
"sha256")
65+
echo "$commit_sha256_oid"
66+
;;
67+
esac
6868
}
6969

7070
commit2_oid () {
71-
case "$1" in
72-
"sha1")
73-
echo "$commit2_sha1_oid"
74-
;;
75-
"sha256")
76-
echo "$commit2_sha256_oid"
77-
;;
78-
esac
71+
case "$1" in
72+
"sha1")
73+
echo "$commit2_sha1_oid"
74+
;;
75+
"sha256")
76+
echo "$commit2_sha256_oid"
77+
;;
78+
esac
7979
}
8080

8181
del_sigcommit () {
82-
local delete="$1"
83-
84-
if test "$delete" = "sha256" ; then
85-
local pattern="gpgsig-sha256"
86-
else
87-
local pattern="gpgsig"
88-
fi
89-
test-tool delete-gpgsig "$pattern"
82+
local delete="$1"
83+
84+
if test "$delete" = "sha256" ; then
85+
local pattern="gpgsig-sha256"
86+
else
87+
local pattern="gpgsig"
88+
fi
89+
test-tool delete-gpgsig "$pattern"
9090
}
9191

92-
9392
del_sigtag () {
94-
local storage="$1"
95-
local delete="$2"
96-
97-
if test "$storage" = "$delete" ; then
98-
local pattern="trailer"
99-
elif test "$storage" = "sha256" ; then
100-
local pattern="gpgsig"
101-
else
102-
local pattern="gpgsig-sha256"
103-
fi
104-
test-tool delete-gpgsig "$pattern"
93+
local storage="$1"
94+
local delete="$2"
95+
96+
if test "$storage" = "$delete" ; then
97+
local pattern="trailer"
98+
elif test "$storage" = "sha256" ; then
99+
local pattern="gpgsig"
100+
else
101+
local pattern="gpgsig-sha256"
102+
fi
103+
test-tool delete-gpgsig "$pattern"
105104
}
106105

107106
base=$(pwd)
@@ -146,9 +145,9 @@ do
146145
'
147146
test_expect_success "create a $hash branch" '
148147
git checkout -b branch $(commit_oid $hash) &&
149-
echo "More more more give me more!" > more &&
148+
echo "More more more give me more!" >more &&
150149
eval more_${hash}_oid=$(git hash-object more) &&
151-
echo "Another and another and another" > another &&
150+
echo "Another and another and another" >another &&
152151
eval another_${hash}_oid=$(git hash-object another) &&
153152
git update-index --add more another &&
154153
git commit -m "Add more files!" &&
@@ -165,97 +164,96 @@ do
165164
'
166165
test_expect_success GPG2 "create additional $hash signed commits" '
167166
git commit --gpg-sign --allow-empty -m "This is an additional signed commit" &&
168-
git cat-file commit HEAD | del_sigcommit sha256 > "../${hash}_signedcommit3" &&
169-
git cat-file commit HEAD | del_sigcommit sha1 > "../${hash}_signedcommit4" &&
167+
git cat-file commit HEAD | del_sigcommit sha256 >"../${hash}_signedcommit3" &&
168+
git cat-file commit HEAD | del_sigcommit sha1 >"../${hash}_signedcommit4" &&
170169
eval signedcommit3_${hash}_oid=$(git hash-object -t commit -w ../${hash}_signedcommit3) &&
171170
eval signedcommit4_${hash}_oid=$(git hash-object -t commit -w ../${hash}_signedcommit4)
172171
'
173172
test_expect_success GPG2 "create additional $hash signed tags" '
174173
git tag -s -m "This is an additional signed tag" signedtag34 HEAD &&
175-
git cat-file tag signedtag34 | del_sigtag "${hash}" sha256 > ../${hash}_signedtag3 &&
176-
git cat-file tag signedtag34 | del_sigtag "${hash}" sha1 > ../${hash}_signedtag4 &&
174+
git cat-file tag signedtag34 | del_sigtag "${hash}" sha256 >../${hash}_signedtag3 &&
175+
git cat-file tag signedtag34 | del_sigtag "${hash}" sha1 >../${hash}_signedtag4 &&
177176
eval signedtag3_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag3) &&
178177
eval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4)
179178
'
180179
done
181180
cd "$base"
182181

183182
compare_oids () {
184-
test "$#" = 5 && { local PREREQ="$1"; shift; } || PREREQ=
185-
local type="$1"
186-
local name="$2"
187-
local sha1_oid="$3"
188-
local sha256_oid="$4"
189-
190-
echo ${sha1_oid} > ${name}_sha1_expected
191-
echo ${sha256_oid} > ${name}_sha256_expected
192-
echo ${type} > ${name}_type_expected
193-
194-
git --git-dir=repo-sha1/.git rev-parse --output-object-format=sha256 ${sha1_oid} > ${name}_sha1_sha256_found
195-
git --git-dir=repo-sha256/.git rev-parse --output-object-format=sha1 ${sha256_oid} > ${name}_sha256_sha1_found
196-
local sha1_sha256_oid="$(cat ${name}_sha1_sha256_found)"
197-
local sha256_sha1_oid="$(cat ${name}_sha256_sha1_found)"
198-
199-
test_expect_success $PREREQ "Verify ${type} ${name}'s sha1 oid" '
200-
git --git-dir=repo-sha256/.git rev-parse --output-object-format=sha1 ${sha256_oid} > ${name}_sha1 &&
201-
test_cmp ${name}_sha1 ${name}_sha1_expected
202-
'
203-
204-
test_expect_success $PREREQ "Verify ${type} ${name}'s sha256 oid" '
205-
git --git-dir=repo-sha1/.git rev-parse --output-object-format=sha256 ${sha1_oid} > ${name}_sha256 &&
206-
test_cmp ${name}_sha256 ${name}_sha256_expected
207-
'
183+
test "$#" = 5 && { local PREREQ="$1"; shift; } || PREREQ=
184+
local type="$1"
185+
local name="$2"
186+
local sha1_oid="$3"
187+
local sha256_oid="$4"
188+
189+
echo ${sha1_oid} >${name}_sha1_expected
190+
echo ${sha256_oid} >${name}_sha256_expected
191+
echo ${type} >${name}_type_expected
192+
193+
git --git-dir=repo-sha1/.git rev-parse --output-object-format=sha256 ${sha1_oid} >${name}_sha1_sha256_found
194+
git --git-dir=repo-sha256/.git rev-parse --output-object-format=sha1 ${sha256_oid} >${name}_sha256_sha1_found
195+
local sha1_sha256_oid="$(cat ${name}_sha1_sha256_found)"
196+
local sha256_sha1_oid="$(cat ${name}_sha256_sha1_found)"
197+
198+
test_expect_success $PREREQ "Verify ${type} ${name}'s sha1 oid" '
199+
git --git-dir=repo-sha256/.git rev-parse --output-object-format=sha1 ${sha256_oid} >${name}_sha1 &&
200+
test_cmp ${name}_sha1 ${name}_sha1_expected
201+
'
208202

209-
test_expect_success $PREREQ "Verify ${name}'s sha1 type" '
210-
git --git-dir=repo-sha1/.git cat-file -t ${sha1_oid} > ${name}_type1 &&
211-
git --git-dir=repo-sha256/.git cat-file -t ${sha256_sha1_oid} > ${name}_type2 &&
212-
test_cmp ${name}_type1 ${name}_type2 &&
213-
test_cmp ${name}_type1 ${name}_type_expected
214-
'
203+
test_expect_success $PREREQ "Verify ${type} ${name}'s sha256 oid" '
204+
git --git-dir=repo-sha1/.git rev-parse --output-object-format=sha256 ${sha1_oid} >${name}_sha256 &&
205+
test_cmp ${name}_sha256 ${name}_sha256_expected
206+
'
215207

216-
test_expect_success $PREREQ "Verify ${name}'s sha256 type" '
217-
git --git-dir=repo-sha256/.git cat-file -t ${sha256_oid} > ${name}_type3 &&
218-
git --git-dir=repo-sha1/.git cat-file -t ${sha1_sha256_oid} > ${name}_type4 &&
219-
test_cmp ${name}_type3 ${name}_type4 &&
220-
test_cmp ${name}_type3 ${name}_type_expected
221-
'
208+
test_expect_success $PREREQ "Verify ${name}'s sha1 type" '
209+
git --git-dir=repo-sha1/.git cat-file -t ${sha1_oid} >${name}_type1 &&
210+
git --git-dir=repo-sha256/.git cat-file -t ${sha256_sha1_oid} >${name}_type2 &&
211+
test_cmp ${name}_type1 ${name}_type2 &&
212+
test_cmp ${name}_type1 ${name}_type_expected
213+
'
222214

223-
test_expect_success $PREREQ "Verify ${name}'s sha1 size" '
224-
git --git-dir=repo-sha1/.git cat-file -s ${sha1_oid} > ${name}_size1 &&
225-
git --git-dir=repo-sha256/.git cat-file -s ${sha256_sha1_oid} > ${name}_size2 &&
226-
test_cmp ${name}_size1 ${name}_size2
227-
'
215+
test_expect_success $PREREQ "Verify ${name}'s sha256 type" '
216+
git --git-dir=repo-sha256/.git cat-file -t ${sha256_oid} >${name}_type3 &&
217+
git --git-dir=repo-sha1/.git cat-file -t ${sha1_sha256_oid} >${name}_type4 &&
218+
test_cmp ${name}_type3 ${name}_type4 &&
219+
test_cmp ${name}_type3 ${name}_type_expected
220+
'
228221

229-
test_expect_success $PREREQ "Verify ${name}'s sha256 size" '
230-
git --git-dir=repo-sha256/.git cat-file -s ${sha256_oid} > ${name}_size3 &&
231-
git --git-dir=repo-sha1/.git cat-file -s ${sha1_sha256_oid} > ${name}_size4 &&
232-
test_cmp ${name}_size3 ${name}_size4
233-
'
222+
test_expect_success $PREREQ "Verify ${name}'s sha1 size" '
223+
git --git-dir=repo-sha1/.git cat-file -s ${sha1_oid} >${name}_size1 &&
224+
git --git-dir=repo-sha256/.git cat-file -s ${sha256_sha1_oid} >${name}_size2 &&
225+
test_cmp ${name}_size1 ${name}_size2
226+
'
234227

235-
test_expect_success $PREREQ "Verify ${name}'s sha1 pretty content" '
236-
git --git-dir=repo-sha1/.git cat-file -p ${sha1_oid} > ${name}_content1 &&
237-
git --git-dir=repo-sha256/.git cat-file -p ${sha256_sha1_oid} > ${name}_content2 &&
238-
test_cmp ${name}_content1 ${name}_content2
239-
'
228+
test_expect_success $PREREQ "Verify ${name}'s sha256 size" '
229+
git --git-dir=repo-sha256/.git cat-file -s ${sha256_oid} >${name}_size3 &&
230+
git --git-dir=repo-sha1/.git cat-file -s ${sha1_sha256_oid} >${name}_size4 &&
231+
test_cmp ${name}_size3 ${name}_size4
232+
'
240233

241-
test_expect_success $PREREQ "Verify ${name}'s sha256 pretty content" '
242-
git --git-dir=repo-sha256/.git cat-file -p ${sha256_oid} > ${name}_content3 &&
243-
git --git-dir=repo-sha1/.git cat-file -p ${sha1_sha256_oid} > ${name}_content4 &&
244-
test_cmp ${name}_content3 ${name}_content4
245-
'
234+
test_expect_success $PREREQ "Verify ${name}'s sha1 pretty content" '
235+
git --git-dir=repo-sha1/.git cat-file -p ${sha1_oid} >${name}_content1 &&
236+
git --git-dir=repo-sha256/.git cat-file -p ${sha256_sha1_oid} >${name}_content2 &&
237+
test_cmp ${name}_content1 ${name}_content2
238+
'
246239

247-
test_expect_success $PREREQ "Verify ${name}'s sha1 content" '
248-
git --git-dir=repo-sha1/.git cat-file ${type} ${sha1_oid} > ${name}_content5 &&
249-
git --git-dir=repo-sha256/.git cat-file ${type} ${sha256_sha1_oid} > ${name}_content6 &&
250-
test_cmp ${name}_content5 ${name}_content6
251-
'
240+
test_expect_success $PREREQ "Verify ${name}'s sha256 pretty content" '
241+
git --git-dir=repo-sha256/.git cat-file -p ${sha256_oid} >${name}_content3 &&
242+
git --git-dir=repo-sha1/.git cat-file -p ${sha1_sha256_oid} >${name}_content4 &&
243+
test_cmp ${name}_content3 ${name}_content4
244+
'
252245

253-
test_expect_success $PREREQ "Verify ${name}'s sha256 content" '
254-
git --git-dir=repo-sha256/.git cat-file ${type} ${sha256_oid} > ${name}_content7 &&
255-
git --git-dir=repo-sha1/.git cat-file ${type} ${sha1_sha256_oid} > ${name}_content8 &&
256-
test_cmp ${name}_content7 ${name}_content8
257-
'
246+
test_expect_success $PREREQ "Verify ${name}'s sha1 content" '
247+
git --git-dir=repo-sha1/.git cat-file ${type} ${sha1_oid} >${name}_content5 &&
248+
git --git-dir=repo-sha256/.git cat-file ${type} ${sha256_sha1_oid} >${name}_content6 &&
249+
test_cmp ${name}_content5 ${name}_content6
250+
'
258251

252+
test_expect_success $PREREQ "Verify ${name}'s sha256 content" '
253+
git --git-dir=repo-sha256/.git cat-file ${type} ${sha256_oid} >${name}_content7 &&
254+
git --git-dir=repo-sha1/.git cat-file ${type} ${sha1_sha256_oid} >${name}_content8 &&
255+
test_cmp ${name}_content7 ${name}_content8
256+
'
259257
}
260258

261259
compare_oids 'blob' hello "$hello_sha1_oid" "$hello_sha256_oid"

0 commit comments

Comments
 (0)