Skip to content

Commit 822ee89

Browse files
jiangxingitster
authored andcommitted
t5411: refactor check of refs using test_cmp_refs
Add new helper 'test_cmp_refs' to check references in a repository. Signed-off-by: Jiang Xin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8388a64 commit 822ee89

31 files changed

+126
-264
lines changed

t/t5411/common-functions.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,18 @@ filter_out_user_friendly_and_stable_output () {
5959
make_user_friendly_and_stable_output |
6060
sed -n ${1+"$@"}
6161
}
62+
63+
test_cmp_refs () {
64+
indir=
65+
if test "$1" = "-C"
66+
then
67+
shift
68+
indir="$1"
69+
shift
70+
fi
71+
indir=${indir:+"$indir"/}
72+
cat >show-ref.expect &&
73+
git ${indir:+ -C "$indir"} show-ref >show-ref.pristine &&
74+
make_user_friendly_and_stable_output <show-ref.pristine >show-ref.filtered &&
75+
test_cmp show-ref.expect show-ref.filtered
76+
}

t/t5411/once-0010-report-status-v1.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,9 @@ test_expect_success "proc-receive: report status v1" '
8383
EOF
8484
test_cmp expect actual &&
8585
86-
git -C "$upstream" show-ref >out &&
87-
make_user_friendly_and_stable_output <out >actual &&
88-
cat >expect <<-EOF &&
86+
test_cmp_refs -C "$upstream" <<-EOF
8987
<COMMIT-A> refs/for/main/topic1
9088
<COMMIT-A> refs/heads/foo
9189
<COMMIT-B> refs/heads/main
9290
EOF
93-
test_cmp expect actual
9491
'

t/t5411/test-0000-standard-git-push.sh

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ test_expect_success "git-push ($PROTOCOL)" '
1919
* [new branch] HEAD -> next
2020
EOF
2121
test_cmp expect actual &&
22-
git -C "$upstream" show-ref >out &&
23-
make_user_friendly_and_stable_output <out >actual &&
24-
cat >expect <<-EOF &&
22+
23+
test_cmp_refs -C "$upstream" <<-EOF
2524
<COMMIT-B> refs/heads/main
2625
<COMMIT-A> refs/heads/next
2726
EOF
28-
test_cmp expect actual
2927
'
3028

3129
# Refs of upstream : main(B) next(A)
@@ -46,13 +44,11 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
4644
! [rejected] <COMMIT-B> -> next (atomic push failed)
4745
EOF
4846
test_cmp expect actual &&
49-
git -C "$upstream" show-ref >out &&
50-
make_user_friendly_and_stable_output <out >actual &&
51-
cat >expect <<-EOF &&
47+
48+
test_cmp_refs -C "$upstream" <<-EOF
5249
<COMMIT-B> refs/heads/main
5350
<COMMIT-A> refs/heads/next
5451
EOF
55-
test_cmp expect actual
5652
'
5753

5854
# Refs of upstream : main(B) next(A)
@@ -77,13 +73,11 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" '
7773
! [rejected] main -> main (non-fast-forward)
7874
EOF
7975
test_cmp expect actual &&
80-
git -C "$upstream" show-ref >out &&
81-
make_user_friendly_and_stable_output <out >actual &&
82-
cat >expect <<-EOF &&
76+
77+
test_cmp_refs -C "$upstream" <<-EOF
8378
<COMMIT-B> refs/heads/main
8479
<COMMIT-B> refs/heads/next
8580
EOF
86-
test_cmp expect actual
8781
'
8882

8983
# Refs of upstream : main(B) next(B)
@@ -119,15 +113,13 @@ test_expect_success "git-push -f ($PROTOCOL)" '
119113
* [new branch] HEAD -> a/b/c
120114
EOF
121115
test_cmp expect actual &&
122-
git -C "$upstream" show-ref >out &&
123-
make_user_friendly_and_stable_output <out >actual &&
124-
cat >expect <<-EOF &&
116+
117+
test_cmp_refs -C "$upstream" <<-EOF
125118
<COMMIT-A> refs/heads/a/b/c
126119
<COMMIT-A> refs/heads/main
127120
<COMMIT-A> refs/review/main/topic
128121
<TAG-v123> refs/tags/v123
129122
EOF
130-
test_cmp expect actual
131123
'
132124

133125
# Refs of upstream : main(A) tags/v123 refs/review/main/topic(A) a/b/c(A)

t/t5411/test-0001-standard-git-push--porcelain.sh

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ test_expect_success "git-push ($PROTOCOL/porcelain)" '
2020
Done
2121
EOF
2222
test_cmp expect actual &&
23-
git -C "$upstream" show-ref >out &&
24-
make_user_friendly_and_stable_output <out >actual &&
25-
cat >expect <<-EOF &&
23+
24+
test_cmp_refs -C "$upstream" <<-EOF
2625
<COMMIT-B> refs/heads/main
2726
<COMMIT-A> refs/heads/next
2827
EOF
29-
test_cmp expect actual
3028
'
3129

3230
# Refs of upstream : main(B) next(A)
@@ -48,13 +46,11 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
4846
! <COMMIT-B>:refs/heads/next [rejected] (atomic push failed)
4947
EOF
5048
test_cmp expect actual &&
51-
git -C "$upstream" show-ref >out &&
52-
make_user_friendly_and_stable_output <out >actual &&
53-
cat >expect <<-EOF &&
49+
50+
test_cmp_refs -C "$upstream" <<-EOF
5451
<COMMIT-B> refs/heads/main
5552
<COMMIT-A> refs/heads/next
5653
EOF
57-
test_cmp expect actual
5854
'
5955

6056
# Refs of upstream : main(B) next(A)
@@ -80,13 +76,11 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL/porcelain)" '
8076
Done
8177
EOF
8278
test_cmp expect actual &&
83-
git -C "$upstream" show-ref >out &&
84-
make_user_friendly_and_stable_output <out >actual &&
85-
cat >expect <<-EOF &&
79+
80+
test_cmp_refs -C "$upstream" <<-EOF
8681
<COMMIT-B> refs/heads/main
8782
<COMMIT-B> refs/heads/next
8883
EOF
89-
test_cmp expect actual
9084
'
9185

9286
# Refs of upstream : main(B) next(B)
@@ -123,15 +117,13 @@ test_expect_success "git-push -f ($PROTOCOL/porcelain)" '
123117
Done
124118
EOF
125119
test_cmp expect actual &&
126-
git -C "$upstream" show-ref >out &&
127-
make_user_friendly_and_stable_output <out >actual &&
128-
cat >expect <<-EOF &&
120+
121+
test_cmp_refs -C "$upstream" <<-EOF
129122
<COMMIT-A> refs/heads/a/b/c
130123
<COMMIT-A> refs/heads/main
131124
<COMMIT-A> refs/review/main/topic
132125
<TAG-v123> refs/tags/v123
133126
EOF
134-
test_cmp expect actual
135127
'
136128

137129
# Refs of upstream : main(A) tags/v123 refs/review/main/topic(A) a/b/c(A)

t/t5411/test-0002-pre-receive-declined.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ test_expect_success "git-push is declined ($PROTOCOL)" '
2020
! [remote rejected] HEAD -> next (pre-receive hook declined)
2121
EOF
2222
test_cmp expect actual &&
23-
git -C "$upstream" show-ref >out &&
24-
make_user_friendly_and_stable_output <out >actual &&
25-
cat >expect <<-EOF &&
23+
24+
test_cmp_refs -C "$upstream" <<-EOF
2625
<COMMIT-A> refs/heads/main
2726
EOF
28-
test_cmp expect actual
2927
'
3028

3129
test_expect_success "cleanup ($PROTOCOL)" '

t/t5411/test-0003-pre-receive-declined--porcelain.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ test_expect_success "git-push is declined ($PROTOCOL/porcelain)" '
2121
Done
2222
EOF
2323
test_cmp expect actual &&
24-
git -C "$upstream" show-ref >out &&
25-
make_user_friendly_and_stable_output <out >actual &&
26-
cat >expect <<-EOF &&
24+
25+
test_cmp_refs -C "$upstream" <<-EOF
2726
<COMMIT-A> refs/heads/main
2827
EOF
29-
test_cmp expect actual
3028
'
3129

3230
test_expect_success "cleanup ($PROTOCOL/porcelain)" '

t/t5411/test-0011-no-hook-error.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL)
1919
! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
2020
EOF
2121
test_cmp expect actual &&
22-
git -C "$upstream" show-ref >out &&
23-
make_user_friendly_and_stable_output <out >actual &&
24-
cat >expect <<-EOF &&
22+
23+
test_cmp_refs -C "$upstream" <<-EOF
2524
<COMMIT-A> refs/heads/main
2625
<COMMIT-A> refs/heads/next
2726
EOF
28-
test_cmp expect actual
2927
'
3028

3129
# Refs of upstream : main(A) next(A)
@@ -55,10 +53,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
5553
! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
5654
EOF
5755
test_cmp expect actual &&
58-
git -C "$upstream" show-ref >out &&
59-
make_user_friendly_and_stable_output <out >actual &&
60-
cat >expect <<-EOF &&
56+
57+
test_cmp_refs -C "$upstream" <<-EOF
6158
<COMMIT-A> refs/heads/main
6259
EOF
63-
test_cmp expect actual
6460
'

t/t5411/test-0012-no-hook-error--porcelain.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/
2020
Done
2121
EOF
2222
test_cmp expect actual &&
23-
git -C "$upstream" show-ref >out &&
24-
make_user_friendly_and_stable_output <out >actual &&
25-
cat >expect <<-EOF &&
23+
24+
test_cmp_refs -C "$upstream" <<-EOF
2625
<COMMIT-A> refs/heads/main
2726
<COMMIT-A> refs/heads/next
2827
EOF
29-
test_cmp expect actual
3028
'
3129

3230
# Refs of upstream : main(A) next(A)
@@ -57,10 +55,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
5755
Done
5856
EOF
5957
test_cmp expect actual &&
60-
git -C "$upstream" show-ref >out &&
61-
make_user_friendly_and_stable_output <out >actual &&
62-
cat >expect <<-EOF &&
58+
59+
test_cmp_refs -C "$upstream" <<-EOF
6360
<COMMIT-A> refs/heads/main
6461
EOF
65-
test_cmp expect actual
6662
'

t/t5411/test-0013-bad-protocol.sh

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" '
3434
EOF
3535
test_cmp expect actual-error &&
3636
37-
git -C "$upstream" show-ref >out &&
38-
make_user_friendly_and_stable_output <out >actual &&
39-
cat >expect <<-EOF &&
37+
test_cmp_refs -C "$upstream" <<-EOF
4038
<COMMIT-A> refs/heads/main
4139
EOF
42-
test_cmp expect actual
4340
'
4441

4542
test_expect_success "setup proc-receive hook (hook --die-read-version, $PROTOCOL)" '
@@ -68,12 +65,9 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTO
6865
grep "remote: fatal: die with the --die-read-version option" out-$test_count &&
6966
grep "remote: error: fail to negotiate version with proc-receive hook" out-$test_count &&
7067
71-
git -C "$upstream" show-ref >out &&
72-
make_user_friendly_and_stable_output <out >actual &&
73-
cat >expect <<-EOF &&
68+
test_cmp_refs -C "$upstream" <<-EOF
7469
<COMMIT-A> refs/heads/main
7570
EOF
76-
test_cmp expect actual
7771
'
7872

7973
test_expect_success "setup proc-receive hook (hook --die-write-version, $PROTOCOL)" '
@@ -102,12 +96,9 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROT
10296
grep "remote: fatal: die with the --die-write-version option" out-$test_count &&
10397
grep "remote: error: fail to negotiate version with proc-receive hook" out-$test_count &&
10498
105-
git -C "$upstream" show-ref >out &&
106-
make_user_friendly_and_stable_output <out >actual &&
107-
cat >expect <<-EOF &&
99+
test_cmp_refs -C "$upstream" <<-EOF
108100
<COMMIT-A> refs/heads/main
109101
EOF
110-
test_cmp expect actual
111102
'
112103

113104
test_expect_success "setup proc-receive hook (hook --die-read-commands, $PROTOCOL)" '
@@ -135,12 +126,9 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROT
135126
test_cmp expect actual &&
136127
grep "remote: fatal: die with the --die-read-commands option" out-$test_count &&
137128
138-
git -C "$upstream" show-ref >out &&
139-
make_user_friendly_and_stable_output <out >actual &&
140-
cat >expect <<-EOF &&
129+
test_cmp_refs -C "$upstream" <<-EOF
141130
<COMMIT-A> refs/heads/main
142131
EOF
143-
test_cmp expect actual
144132
'
145133

146134
test_expect_success "setup proc-receive hook (hook --die-read-push-options, $PROTOCOL)" '
@@ -170,12 +158,9 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $
170158
test_cmp expect actual &&
171159
grep "remote: fatal: die with the --die-read-push-options option" out-$test_count &&
172160
173-
git -C "$upstream" show-ref >out &&
174-
make_user_friendly_and_stable_output <out >actual &&
175-
cat >expect <<-EOF &&
161+
test_cmp_refs -C "$upstream" <<-EOF
176162
<COMMIT-A> refs/heads/main
177163
EOF
178-
test_cmp expect actual
179164
'
180165

181166
test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL)" '
@@ -203,12 +188,9 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTO
203188
test_cmp expect actual &&
204189
grep "remote: fatal: die with the --die-write-report option" out-$test_count &&
205190
206-
git -C "$upstream" show-ref >out &&
207-
make_user_friendly_and_stable_output <out >actual &&
208-
cat >expect <<-EOF &&
191+
test_cmp_refs -C "$upstream" <<-EOF
209192
<COMMIT-A> refs/heads/main
210193
EOF
211-
test_cmp expect actual
212194
'
213195

214196
test_expect_success "setup proc-receive hook (no report, $PROTOCOL)" '
@@ -240,13 +222,10 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" '
240222
EOF
241223
test_cmp expect actual &&
242224
243-
git -C "$upstream" show-ref >out &&
244-
make_user_friendly_and_stable_output <out >actual &&
245-
cat >expect <<-EOF &&
225+
test_cmp_refs -C "$upstream" <<-EOF
246226
<COMMIT-A> refs/heads/main
247227
<COMMIT-A> refs/heads/next
248228
EOF
249-
test_cmp expect actual
250229
'
251230

252231
# Refs of upstream : main(A) next(A)
@@ -284,12 +263,9 @@ test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" '
284263
EOF
285264
test_cmp expect actual &&
286265
287-
git -C "$upstream" show-ref >out &&
288-
make_user_friendly_and_stable_output <out >actual &&
289-
cat >expect <<-EOF &&
266+
test_cmp_refs -C "$upstream" <<-EOF
290267
<COMMIT-A> refs/heads/main
291268
EOF
292-
test_cmp expect actual
293269
'
294270

295271
test_expect_success "setup proc-receive hook (unknown status, $PROTOCOL)" '
@@ -320,10 +296,7 @@ test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" '
320296
EOF
321297
test_cmp expect actual &&
322298
323-
git -C "$upstream" show-ref >out &&
324-
make_user_friendly_and_stable_output <out >actual &&
325-
cat >expect <<-EOF &&
299+
test_cmp_refs -C "$upstream" <<-EOF
326300
<COMMIT-A> refs/heads/main
327301
EOF
328-
test_cmp expect actual
329302
'

0 commit comments

Comments
 (0)