Skip to content

Commit 522e641

Browse files
derrickstoleegitster
authored andcommitted
t1091: use check_files to reduce boilerplate
When testing the sparse-checkout feature, we need to compare the contents of the working-directory against some expected output. Using here-docs was useful in the beginning, but became repetetive as the test script grew. Create a check_files helper to make the tests simpler and easier to extend. It also reduces instances of bad here-doc whitespace. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4fd683b commit 522e641

File tree

1 file changed

+22
-95
lines changed

1 file changed

+22
-95
lines changed

t/t1091-sparse-checkout-builtin.sh

Lines changed: 22 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ list_files() {
1212
(cd "$1" && printf '%s\n' *)
1313
}
1414

15+
check_files() {
16+
list_files "$1" >actual &&
17+
shift &&
18+
printf "%s\n" $@ >expect &&
19+
test_cmp expect actual
20+
}
21+
1522
test_expect_success 'setup' '
1623
git init repo &&
1724
(
@@ -58,9 +65,7 @@ test_expect_success 'git sparse-checkout init' '
5865
EOF
5966
test_cmp expect repo/.git/info/sparse-checkout &&
6067
test_cmp_config -C repo true core.sparsecheckout &&
61-
list_files repo >dir &&
62-
echo a >expect &&
63-
test_cmp expect dir
68+
check_files repo a
6469
'
6570

6671
test_expect_success 'git sparse-checkout list after init' '
@@ -81,13 +86,7 @@ test_expect_success 'init with existing sparse-checkout' '
8186
*folder*
8287
EOF
8388
test_cmp expect repo/.git/info/sparse-checkout &&
84-
list_files repo >dir &&
85-
cat >expect <<-EOF &&
86-
a
87-
folder1
88-
folder2
89-
EOF
90-
test_cmp expect dir
89+
check_files repo a folder1 folder2
9190
'
9291

9392
test_expect_success 'clone --sparse' '
@@ -98,9 +97,7 @@ test_expect_success 'clone --sparse' '
9897
!/*/
9998
EOF
10099
test_cmp expect actual &&
101-
list_files clone >dir &&
102-
echo a >expect &&
103-
test_cmp expect dir
100+
check_files clone a
104101
'
105102

106103
test_expect_success 'set enables config' '
@@ -127,13 +124,7 @@ test_expect_success 'set sparse-checkout using builtin' '
127124
git -C repo sparse-checkout list >actual &&
128125
test_cmp expect actual &&
129126
test_cmp expect repo/.git/info/sparse-checkout &&
130-
list_files repo >dir &&
131-
cat >expect <<-EOF &&
132-
a
133-
folder1
134-
folder2
135-
EOF
136-
test_cmp expect dir
127+
check_files repo a folder1 folder2
137128
'
138129

139130
test_expect_success 'set sparse-checkout using --stdin' '
@@ -147,13 +138,7 @@ test_expect_success 'set sparse-checkout using --stdin' '
147138
git -C repo sparse-checkout list >actual &&
148139
test_cmp expect actual &&
149140
test_cmp expect repo/.git/info/sparse-checkout &&
150-
list_files repo >dir &&
151-
cat >expect <<-EOF &&
152-
a
153-
folder1
154-
folder2
155-
EOF
156-
test_cmp expect dir
141+
check_files repo "a folder1 folder2"
157142
'
158143

159144
test_expect_success 'cone mode: match patterns' '
@@ -162,13 +147,7 @@ test_expect_success 'cone mode: match patterns' '
162147
git -C repo read-tree -mu HEAD 2>err &&
163148
test_i18ngrep ! "disabling cone patterns" err &&
164149
git -C repo reset --hard &&
165-
list_files repo >dir &&
166-
cat >expect <<-EOF &&
167-
a
168-
folder1
169-
folder2
170-
EOF
171-
test_cmp expect dir
150+
check_files repo a folder1 folder2
172151
'
173152

174153
test_expect_success 'cone mode: warn on bad pattern' '
@@ -185,14 +164,7 @@ test_expect_success 'sparse-checkout disable' '
185164
test_path_is_file repo/.git/info/sparse-checkout &&
186165
git -C repo config --list >config &&
187166
test_must_fail git config core.sparseCheckout &&
188-
list_files repo >dir &&
189-
cat >expect <<-EOF &&
190-
a
191-
deep
192-
folder1
193-
folder2
194-
EOF
195-
test_cmp expect dir
167+
check_files repo a deep folder1 folder2
196168
'
197169

198170
test_expect_success 'cone mode: init and set' '
@@ -204,24 +176,9 @@ test_expect_success 'cone mode: init and set' '
204176
test_cmp expect dir &&
205177
git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
206178
test_must_be_empty err &&
207-
list_files repo >dir &&
208-
cat >expect <<-EOF &&
209-
a
210-
deep
211-
EOF
212-
test_cmp expect dir &&
213-
list_files repo/deep >dir &&
214-
cat >expect <<-EOF &&
215-
a
216-
deeper1
217-
EOF
218-
test_cmp expect dir &&
219-
list_files repo/deep/deeper1 >dir &&
220-
cat >expect <<-EOF &&
221-
a
222-
deepest
223-
EOF
224-
test_cmp expect dir &&
179+
check_files repo a deep &&
180+
check_files repo/deep a deeper1 &&
181+
check_files repo/deep/deeper1 a deepest &&
225182
cat >expect <<-EOF &&
226183
/*
227184
!/*/
@@ -237,13 +194,7 @@ test_expect_success 'cone mode: init and set' '
237194
folder2
238195
EOF
239196
test_must_be_empty err &&
240-
cat >expect <<-EOF &&
241-
a
242-
folder1
243-
folder2
244-
EOF
245-
list_files repo >dir &&
246-
test_cmp expect dir
197+
check_files repo a folder1 folder2
247198
'
248199

249200
test_expect_success 'cone mode: list' '
@@ -275,13 +226,7 @@ test_expect_success 'revert to old sparse-checkout on bad update' '
275226
test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err &&
276227
test_i18ngrep "cannot set sparse-checkout patterns" err &&
277228
test_cmp repo/.git/info/sparse-checkout expect &&
278-
list_files repo/deep >dir &&
279-
cat >expect <<-EOF &&
280-
a
281-
deeper1
282-
deeper2
283-
EOF
284-
test_cmp dir expect
229+
check_files repo/deep a deeper1 deeper2
285230
'
286231

287232
test_expect_success 'revert to old sparse-checkout on empty update' '
@@ -332,12 +277,7 @@ test_expect_success 'cone mode: set with core.ignoreCase=true' '
332277
/folder1/
333278
EOF
334279
test_cmp expect repo/.git/info/sparse-checkout &&
335-
list_files repo >dir &&
336-
cat >expect <<-EOF &&
337-
a
338-
folder1
339-
EOF
340-
test_cmp expect dir
280+
check_files repo a folder1
341281
'
342282

343283
test_expect_success 'interaction with submodules' '
@@ -351,21 +291,8 @@ test_expect_success 'interaction with submodules' '
351291
git sparse-checkout init --cone &&
352292
git sparse-checkout set folder1
353293
) &&
354-
list_files super >dir &&
355-
cat >expect <<-\EOF &&
356-
a
357-
folder1
358-
modules
359-
EOF
360-
test_cmp expect dir &&
361-
list_files super/modules/child >dir &&
362-
cat >expect <<-\EOF &&
363-
a
364-
deep
365-
folder1
366-
folder2
367-
EOF
368-
test_cmp expect dir
294+
check_files super a folder1 modules &&
295+
check_files super/modules/child a deep folder1 folder2
369296
'
370297

371298
test_done

0 commit comments

Comments
 (0)