Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 2dd4233

Browse files
René Scharfegitster
authored andcommitted
t5000: rationalize unzip tests
Factor out a function for checking the contents of ZIP archives. It extracts their contents and compares them to the original files. This removes some duplicate code. Tests that just create archives can lose their UNZIP prerequisite. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c743c21 commit 2dd4233

File tree

1 file changed

+39
-40
lines changed

1 file changed

+39
-40
lines changed

t/t5000-tar-tree.sh

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ GUNZIP=${GUNZIP:-gzip -d}
3131

3232
SUBSTFORMAT=%H%n
3333

34+
check_zip() {
35+
zipfile=$1.zip
36+
listfile=$1.lst
37+
dir=$1
38+
dir_with_prefix=$dir/$2
39+
40+
test_expect_success UNZIP " extract ZIP archive" "
41+
(mkdir $dir && cd $dir && $UNZIP ../$zipfile)
42+
"
43+
44+
test_expect_success UNZIP " validate filenames" "
45+
(cd ${dir_with_prefix}a && find .) | sort >$listfile &&
46+
test_cmp a.lst $listfile
47+
"
48+
49+
test_expect_success UNZIP " validate file contents" "
50+
diff -r a ${dir_with_prefix}a
51+
"
52+
}
53+
3454
test_expect_success \
3555
'populate workdir' \
3656
'mkdir a b c &&
@@ -181,10 +201,19 @@ test_expect_success \
181201
test_cmp a/substfile2 g/prefix/a/substfile2
182202
'
183203

204+
$UNZIP -v >/dev/null 2>&1
205+
if [ $? -eq 127 ]; then
206+
say "Skipping ZIP tests, because unzip was not found"
207+
else
208+
test_set_prereq UNZIP
209+
fi
210+
184211
test_expect_success \
185212
'git archive --format=zip' \
186213
'git archive --format=zip HEAD >d.zip'
187214

215+
check_zip d
216+
188217
test_expect_success \
189218
'git archive --format=zip in a bare repo' \
190219
'(cd bare.git && git archive --format=zip HEAD) >d1.zip'
@@ -207,55 +236,25 @@ test_expect_success 'git archive with --output, override inferred format' '
207236
test_cmp b.tar d4.zip
208237
'
209238

210-
$UNZIP -v >/dev/null 2>&1
211-
if [ $? -eq 127 ]; then
212-
say "Skipping ZIP tests, because unzip was not found"
213-
else
214-
test_set_prereq UNZIP
215-
fi
216-
217-
test_expect_success UNZIP \
218-
'extract ZIP archive' \
219-
'(mkdir d && cd d && $UNZIP ../d.zip)'
220-
221-
test_expect_success UNZIP \
222-
'validate filenames' \
223-
'(cd d/a && find .) | sort >d.lst &&
224-
test_cmp a.lst d.lst'
225-
226-
test_expect_success UNZIP \
227-
'validate file contents' \
228-
'diff -r a d/a'
229-
230239
test_expect_success \
231240
'git archive --format=zip with prefix' \
232241
'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
233242

234-
test_expect_success UNZIP \
235-
'extract ZIP archive with prefix' \
236-
'(mkdir e && cd e && $UNZIP ../e.zip)'
243+
check_zip e prefix/
237244

238-
test_expect_success UNZIP \
239-
'validate filenames with prefix' \
240-
'(cd e/prefix/a && find .) | sort >e.lst &&
241-
test_cmp a.lst e.lst'
245+
test_expect_success 'git archive -0 --format=zip on large files' '
246+
test_config core.bigfilethreshold 1 &&
247+
git archive -0 --format=zip HEAD >large.zip
248+
'
242249

243-
test_expect_success UNZIP \
244-
'validate file contents with prefix' \
245-
'diff -r a e/prefix/a'
250+
check_zip large
246251

247-
test_expect_success UNZIP 'git archive -0 --format=zip on large files' '
248-
test_config core.bigfilethreshold 1 &&
249-
git archive -0 --format=zip HEAD >large.zip &&
250-
(mkdir large && cd large && $UNZIP ../large.zip)
252+
test_expect_success 'git archive --format=zip on large files' '
253+
test_config core.bigfilethreshold 1 &&
254+
git archive --format=zip HEAD >large-compressed.zip
251255
'
252256

253-
test_expect_success UNZIP 'git archive --format=zip on large files' '
254-
test_config core.bigfilethreshold 1 &&
255-
git archive --format=zip HEAD >large-compressed.zip &&
256-
(mkdir large-compressed && cd large-compressed && $UNZIP ../large-compressed.zip) &&
257-
test_cmp large-compressed/a/bin/sh large/a/bin/sh
258-
'
257+
check_zip large-compressed
259258

260259
test_expect_success \
261260
'git archive --list outside of a git repo' \

0 commit comments

Comments
 (0)