Skip to content

Commit d784d97

Browse files
Denton-Lgitster
authored andcommitted
t4215: use helper function to check output
When git commands are placed in the upstream of a pipe, their return codes are lost. In this particular case, it is especially bad since we are testing the intricacies of `git log --graph` behavior and if we hit an unexpected failure or segfault, we want to know this. Extract the common output checking logic into check_graph() where we redirect the output of git commands upstream of pipe into a file and have sed read from that file so that git failures are detected. This patch is best viewed with `--color-moved`. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bbb13e8 commit d784d97

File tree

1 file changed

+97
-111
lines changed

1 file changed

+97
-111
lines changed

t/t4215-log-skewed-merges.sh

Lines changed: 97 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,25 @@ test_description='git log --graph of skewed merges'
44

55
. ./test-lib.sh
66

7+
check_graph () {
8+
cat >expect &&
9+
git log --graph --pretty=tformat:%s "$@" >actual.raw &&
10+
sed "s/ *$//" actual.raw >actual &&
11+
test_cmp expect actual
12+
}
13+
714
test_expect_success 'log --graph with merge fusing with its left and right neighbors' '
8-
cat >expect <<-\EOF &&
15+
git checkout --orphan _p &&
16+
test_commit A &&
17+
test_commit B &&
18+
git checkout -b _q @^ && test_commit C &&
19+
git checkout -b _r @^ && test_commit D &&
20+
git checkout _p && git merge --no-ff _q _r -m E &&
21+
git checkout _r && test_commit F &&
22+
git checkout _p && git merge --no-ff _r -m G &&
23+
git checkout @^^ && git merge --no-ff _p -m H &&
24+
25+
check_graph <<-\EOF
926
* H
1027
|\
1128
| * G
@@ -20,23 +37,20 @@ test_expect_success 'log --graph with merge fusing with its left and right neigh
2037
|/
2138
* A
2239
EOF
23-
24-
git checkout --orphan _p &&
25-
test_commit A &&
26-
test_commit B &&
27-
git checkout -b _q @^ && test_commit C &&
28-
git checkout -b _r @^ && test_commit D &&
29-
git checkout _p && git merge --no-ff _q _r -m E &&
30-
git checkout _r && test_commit F &&
31-
git checkout _p && git merge --no-ff _r -m G &&
32-
git checkout @^^ && git merge --no-ff _p -m H &&
33-
34-
git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual &&
35-
test_cmp expect actual
3640
'
3741

3842
test_expect_success 'log --graph with left-skewed merge' '
39-
cat >expect <<-\EOF &&
43+
git checkout --orphan 0_p && test_commit 0_A &&
44+
git checkout -b 0_q 0_p && test_commit 0_B &&
45+
git checkout -b 0_r 0_p &&
46+
test_commit 0_C &&
47+
test_commit 0_D &&
48+
git checkout -b 0_s 0_p && test_commit 0_E &&
49+
git checkout -b 0_t 0_p && git merge --no-ff 0_r^ 0_s -m 0_F &&
50+
git checkout 0_p && git merge --no-ff 0_s -m 0_G &&
51+
git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H &&
52+
53+
check_graph <<-\EOF
4054
*-----. 0_H
4155
|\ \ \ \
4256
| | | | * 0_G
@@ -57,23 +71,20 @@ test_expect_success 'log --graph with left-skewed merge' '
5771
|/
5872
* 0_A
5973
EOF
60-
61-
git checkout --orphan 0_p && test_commit 0_A &&
62-
git checkout -b 0_q 0_p && test_commit 0_B &&
63-
git checkout -b 0_r 0_p &&
64-
test_commit 0_C &&
65-
test_commit 0_D &&
66-
git checkout -b 0_s 0_p && test_commit 0_E &&
67-
git checkout -b 0_t 0_p && git merge --no-ff 0_r^ 0_s -m 0_F &&
68-
git checkout 0_p && git merge --no-ff 0_s -m 0_G &&
69-
git checkout @^ && git merge --no-ff 0_q 0_r 0_t 0_p -m 0_H &&
70-
71-
git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual &&
72-
test_cmp expect actual
7374
'
7475

7576
test_expect_success 'log --graph with nested left-skewed merge' '
76-
cat >expect <<-\EOF &&
77+
git checkout --orphan 1_p &&
78+
test_commit 1_A &&
79+
test_commit 1_B &&
80+
test_commit 1_C &&
81+
git checkout -b 1_q @^ && test_commit 1_D &&
82+
git checkout 1_p && git merge --no-ff 1_q -m 1_E &&
83+
git checkout -b 1_r @~3 && test_commit 1_F &&
84+
git checkout 1_p && git merge --no-ff 1_r -m 1_G &&
85+
git checkout @^^ && git merge --no-ff 1_p -m 1_H &&
86+
87+
check_graph <<-\EOF
7788
* 1_H
7889
|\
7990
| * 1_G
@@ -88,23 +99,24 @@ test_expect_success 'log --graph with nested left-skewed merge' '
8899
|/
89100
* 1_A
90101
EOF
91-
92-
git checkout --orphan 1_p &&
93-
test_commit 1_A &&
94-
test_commit 1_B &&
95-
test_commit 1_C &&
96-
git checkout -b 1_q @^ && test_commit 1_D &&
97-
git checkout 1_p && git merge --no-ff 1_q -m 1_E &&
98-
git checkout -b 1_r @~3 && test_commit 1_F &&
99-
git checkout 1_p && git merge --no-ff 1_r -m 1_G &&
100-
git checkout @^^ && git merge --no-ff 1_p -m 1_H &&
101-
102-
git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual &&
103-
test_cmp expect actual
104102
'
105103

106104
test_expect_success 'log --graph with nested left-skewed merge following normal merge' '
107-
cat >expect <<-\EOF &&
105+
git checkout --orphan 2_p &&
106+
test_commit 2_A &&
107+
test_commit 2_B &&
108+
test_commit 2_C &&
109+
git checkout -b 2_q @^^ &&
110+
test_commit 2_D &&
111+
test_commit 2_E &&
112+
git checkout -b 2_r @^ && test_commit 2_F &&
113+
git checkout 2_q &&
114+
git merge --no-ff 2_r -m 2_G &&
115+
git merge --no-ff 2_p^ -m 2_H &&
116+
git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J &&
117+
git checkout 2_p && git merge --no-ff 2_s -m 2_K &&
118+
119+
check_graph <<-\EOF
108120
* 2_K
109121
|\
110122
| * 2_J
@@ -124,27 +136,23 @@ test_expect_success 'log --graph with nested left-skewed merge following normal
124136
|/
125137
* 2_A
126138
EOF
127-
128-
git checkout --orphan 2_p &&
129-
test_commit 2_A &&
130-
test_commit 2_B &&
131-
test_commit 2_C &&
132-
git checkout -b 2_q @^^ &&
133-
test_commit 2_D &&
134-
test_commit 2_E &&
135-
git checkout -b 2_r @^ && test_commit 2_F &&
136-
git checkout 2_q &&
137-
git merge --no-ff 2_r -m 2_G &&
138-
git merge --no-ff 2_p^ -m 2_H &&
139-
git checkout -b 2_s @^^ && git merge --no-ff 2_q -m 2_J &&
140-
git checkout 2_p && git merge --no-ff 2_s -m 2_K &&
141-
142-
git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual &&
143-
test_cmp expect actual
144139
'
145140

146141
test_expect_success 'log --graph with nested right-skewed merge following left-skewed merge' '
147-
cat >expect <<-\EOF &&
142+
git checkout --orphan 3_p &&
143+
test_commit 3_A &&
144+
git checkout -b 3_q &&
145+
test_commit 3_B &&
146+
test_commit 3_C &&
147+
git checkout -b 3_r @^ &&
148+
test_commit 3_D &&
149+
git checkout 3_q && git merge --no-ff 3_r -m 3_E &&
150+
git checkout 3_p && git merge --no-ff 3_q -m 3_F &&
151+
git checkout 3_r && test_commit 3_G &&
152+
git checkout 3_p && git merge --no-ff 3_r -m 3_H &&
153+
git checkout @^^ && git merge --no-ff 3_p -m 3_J &&
154+
155+
check_graph <<-\EOF
148156
* 3_J
149157
|\
150158
| * 3_H
@@ -161,26 +169,21 @@ test_expect_success 'log --graph with nested right-skewed merge following left-s
161169
|/
162170
* 3_A
163171
EOF
164-
165-
git checkout --orphan 3_p &&
166-
test_commit 3_A &&
167-
git checkout -b 3_q &&
168-
test_commit 3_B &&
169-
test_commit 3_C &&
170-
git checkout -b 3_r @^ &&
171-
test_commit 3_D &&
172-
git checkout 3_q && git merge --no-ff 3_r -m 3_E &&
173-
git checkout 3_p && git merge --no-ff 3_q -m 3_F &&
174-
git checkout 3_r && test_commit 3_G &&
175-
git checkout 3_p && git merge --no-ff 3_r -m 3_H &&
176-
git checkout @^^ && git merge --no-ff 3_p -m 3_J &&
177-
178-
git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual &&
179-
test_cmp expect actual
180172
'
181173

182174
test_expect_success 'log --graph with right-skewed merge following a left-skewed one' '
183-
cat >expect <<-\EOF &&
175+
git checkout --orphan 4_p &&
176+
test_commit 4_A &&
177+
test_commit 4_B &&
178+
test_commit 4_C &&
179+
git checkout -b 4_q @^^ && test_commit 4_D &&
180+
git checkout -b 4_r 4_p^ && git merge --no-ff 4_q -m 4_E &&
181+
git checkout -b 4_s 4_p^^ &&
182+
git merge --no-ff 4_r -m 4_F &&
183+
git merge --no-ff 4_p -m 4_G &&
184+
git checkout @^^ && git merge --no-ff 4_s -m 4_H &&
185+
186+
check_graph --date-order <<-\EOF
184187
* 4_H
185188
|\
186189
| * 4_G
@@ -198,24 +201,25 @@ test_expect_success 'log --graph with right-skewed merge following a left-skewed
198201
|/
199202
* 4_A
200203
EOF
201-
202-
git checkout --orphan 4_p &&
203-
test_commit 4_A &&
204-
test_commit 4_B &&
205-
test_commit 4_C &&
206-
git checkout -b 4_q @^^ && test_commit 4_D &&
207-
git checkout -b 4_r 4_p^ && git merge --no-ff 4_q -m 4_E &&
208-
git checkout -b 4_s 4_p^^ &&
209-
git merge --no-ff 4_r -m 4_F &&
210-
git merge --no-ff 4_p -m 4_G &&
211-
git checkout @^^ && git merge --no-ff 4_s -m 4_H &&
212-
213-
git log --graph --date-order --pretty=tformat:%s | sed "s/ *$//" >actual &&
214-
test_cmp expect actual
215204
'
216205

217206
test_expect_success 'log --graph with octopus merge with column joining its penultimate parent' '
218-
cat >expect <<-\EOF &&
207+
git checkout --orphan 5_p &&
208+
test_commit 5_A &&
209+
git branch 5_q &&
210+
git branch 5_r &&
211+
test_commit 5_B &&
212+
git checkout 5_q && test_commit 5_C &&
213+
git checkout 5_r && test_commit 5_D &&
214+
git checkout 5_p &&
215+
git merge --no-ff 5_q 5_r -m 5_E &&
216+
git checkout 5_q && test_commit 5_F &&
217+
git checkout -b 5_s 5_p^ &&
218+
git merge --no-ff 5_p 5_q -m 5_G &&
219+
git checkout 5_r &&
220+
git merge --no-ff 5_s -m 5_H &&
221+
222+
check_graph <<-\EOF
219223
* 5_H
220224
|\
221225
| *-. 5_G
@@ -234,24 +238,6 @@ test_expect_success 'log --graph with octopus merge with column joining its penu
234238
|/
235239
* 5_A
236240
EOF
237-
238-
git checkout --orphan 5_p &&
239-
test_commit 5_A &&
240-
git branch 5_q &&
241-
git branch 5_r &&
242-
test_commit 5_B &&
243-
git checkout 5_q && test_commit 5_C &&
244-
git checkout 5_r && test_commit 5_D &&
245-
git checkout 5_p &&
246-
git merge --no-ff 5_q 5_r -m 5_E &&
247-
git checkout 5_q && test_commit 5_F &&
248-
git checkout -b 5_s 5_p^ &&
249-
git merge --no-ff 5_p 5_q -m 5_G &&
250-
git checkout 5_r &&
251-
git merge --no-ff 5_s -m 5_H &&
252-
253-
git log --graph --pretty=tformat:%s | sed "s/ *$//" >actual &&
254-
test_cmp expect actual
255241
'
256242

257243
test_done

0 commit comments

Comments
 (0)