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 <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed May 3, 2012 at 10:52 UTC 2dd42334dea6619c0774511beda9a02642088f67
1 file changed +39 -40
t/t5000-tar-tree.sh
+39 -40
@@ -31,6 +31,26 @@ GUNZIP=${GUNZIP:-gzip -d}
31
32 SUBSTFORMAT=%H%n
33
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 +
54 test_expect_success \
55 'populate workdir' \
56 'mkdir a b c &&
@@ -181,10 +201,19 @@ test_expect_success \
201 test_cmp a/substfile2 g/prefix/a/substfile2
202 '
203
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 +
211 test_expect_success \
212 'git archive --format=zip' \
213 'git archive --format=zip HEAD >d.zip'
214
215 +check_zip d
216 +
217 test_expect_success \
218 'git archive --format=zip in a bare repo' \
219 '(cd bare.git && git archive --format=zip HEAD) >d1.zip'
@@ -207,55 +236,25 @@ test_expect_success 'git archive with --output, override inferred format' '
236 test_cmp b.tar d4.zip
237 '
238
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 -
239 test_expect_success \
240 'git archive --format=zip with prefix' \
241 'git archive --format=zip --prefix=prefix/ HEAD >e.zip'
242
234 -test_expect_success UNZIP \
235 - 'extract ZIP archive with prefix' \
236 - '(mkdir e && cd e && $UNZIP ../e.zip)'
243 +check_zip e prefix/
244
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 +'
249
243 -test_expect_success UNZIP \
244 - 'validate file contents with prefix' \
245 - 'diff -r a e/prefix/a'
250 +check_zip large
251
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
255 '
256
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
258
259 test_expect_success \
260 'git archive --list outside of a git repo' \