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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Jan 24, 2020 at 21:19 UTC
522e6417487cc5c3f2f6d49c8f63554af63d8eda
1 file changed
+22
-95
t/t1091-sparse-checkout-builtin.sh
+22
-95
@@ -12,6 +12,13 @@ list_files() {
12
(cd "$1" && printf '%s\n' *)
13
}
14
15
+check_files() {
16
+ list_files "$1" >actual &&
17
+ shift &&
18
+ printf "%s\n" $@ >expect &&
19
+ test_cmp expect actual
20
+}
21
+
22
test_expect_success 'setup' '
23
git init repo &&
24
(
@@ -58,9 +65,7 @@ test_expect_success 'git sparse-checkout init' '
65
EOF
66
test_cmp expect repo/.git/info/sparse-checkout &&
67
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
69
'
70
71
test_expect_success 'git sparse-checkout list after init' '
@@ -81,13 +86,7 @@ test_expect_success 'init with existing sparse-checkout' '
86
*folder*
87
EOF
88
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
90
'
91
92
test_expect_success 'clone --sparse' '
@@ -98,9 +97,7 @@ test_expect_success 'clone --sparse' '
97
!/*/
98
EOF
99
test_cmp expect actual &&
101
- list_files clone >dir &&
102
- echo a >expect &&
103
- test_cmp expect dir
100
+ check_files clone a
101
'
102
103
test_expect_success 'set enables config' '
@@ -127,13 +124,7 @@ test_expect_success 'set sparse-checkout using builtin' '
124
git -C repo sparse-checkout list >actual &&
125
test_cmp expect actual &&
126
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
128
'
129
130
test_expect_success 'set sparse-checkout using --stdin' '
@@ -147,13 +138,7 @@ test_expect_success 'set sparse-checkout using --stdin' '
138
git -C repo sparse-checkout list >actual &&
139
test_cmp expect actual &&
140
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"
142
'
143
144
test_expect_success 'cone mode: match patterns' '
@@ -162,13 +147,7 @@ test_expect_success 'cone mode: match patterns' '
147
git -C repo read-tree -mu HEAD 2>err &&
148
test_i18ngrep ! "disabling cone patterns" err &&
149
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
151
'
152
153
test_expect_success 'cone mode: warn on bad pattern' '
@@ -185,14 +164,7 @@ test_expect_success 'sparse-checkout disable' '
164
test_path_is_file repo/.git/info/sparse-checkout &&
165
git -C repo config --list >config &&
166
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
168
'
169
170
test_expect_success 'cone mode: init and set' '
@@ -204,24 +176,9 @@ test_expect_success 'cone mode: init and set' '
176
test_cmp expect dir &&
177
git -C repo sparse-checkout set deep/deeper1/deepest/ 2>err &&
178
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 &&
182
cat >expect <<-EOF &&
183
/*
184
!/*/
@@ -237,13 +194,7 @@ test_expect_success 'cone mode: init and set' '
194
folder2
195
EOF
196
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
198
'
199
200
test_expect_success 'cone mode: list' '
@@ -275,13 +226,7 @@ test_expect_success 'revert to old sparse-checkout on bad update' '
226
test_must_fail git -C repo sparse-checkout set deep/deeper1 2>err &&
227
test_i18ngrep "cannot set sparse-checkout patterns" err &&
228
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
230
'
231
232
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' '
277
/folder1/
278
EOF
279
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
281
'
282
283
test_expect_success 'interaction with submodules' '
@@ -351,21 +291,8 @@ test_expect_success 'interaction with submodules' '
291
git sparse-checkout init --cone &&
292
git sparse-checkout set folder1
293
) &&
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
296
'
297
298
test_done