Skip to content

Commit

Permalink
t5000: rationalize unzip tests
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed May 3, 2012
1 parent c743c21 commit 2dd4233
Showing 1 changed file with 39 additions and 40 deletions.
79 changes: 39 additions & 40 deletions t/t5000-tar-tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ GUNZIP=${GUNZIP:-gzip -d}

SUBSTFORMAT=%H%n

check_zip() {
zipfile=$1.zip
listfile=$1.lst
dir=$1
dir_with_prefix=$dir/$2

test_expect_success UNZIP " extract ZIP archive" "
(mkdir $dir && cd $dir && $UNZIP ../$zipfile)
"

test_expect_success UNZIP " validate filenames" "
(cd ${dir_with_prefix}a && find .) | sort >$listfile &&
test_cmp a.lst $listfile
"

test_expect_success UNZIP " validate file contents" "
diff -r a ${dir_with_prefix}a
"
}

test_expect_success \
'populate workdir' \
'mkdir a b c &&
Expand Down Expand Up @@ -181,10 +201,19 @@ test_expect_success \
test_cmp a/substfile2 g/prefix/a/substfile2
'

$UNZIP -v >/dev/null 2>&1
if [ $? -eq 127 ]; then
say "Skipping ZIP tests, because unzip was not found"
else
test_set_prereq UNZIP
fi

test_expect_success \
'git archive --format=zip' \
'git archive --format=zip HEAD >d.zip'

check_zip d

test_expect_success \
'git archive --format=zip in a bare repo' \
'(cd bare.git && git archive --format=zip HEAD) >d1.zip'
Expand All @@ -207,55 +236,25 @@ test_expect_success 'git archive with --output, override inferred format' '
test_cmp b.tar d4.zip
'

$UNZIP -v >/dev/null 2>&1
if [ $? -eq 127 ]; then
say "Skipping ZIP tests, because unzip was not found"
else
test_set_prereq UNZIP
fi

test_expect_success UNZIP \
'extract ZIP archive' \
'(mkdir d && cd d && $UNZIP ../d.zip)'

test_expect_success UNZIP \
'validate filenames' \
'(cd d/a && find .) | sort >d.lst &&
test_cmp a.lst d.lst'

test_expect_success UNZIP \
'validate file contents' \
'diff -r a d/a'

test_expect_success \
'git archive --format=zip with prefix' \
'git archive --format=zip --prefix=prefix/ HEAD >e.zip'

test_expect_success UNZIP \
'extract ZIP archive with prefix' \
'(mkdir e && cd e && $UNZIP ../e.zip)'
check_zip e prefix/

test_expect_success UNZIP \
'validate filenames with prefix' \
'(cd e/prefix/a && find .) | sort >e.lst &&
test_cmp a.lst e.lst'
test_expect_success 'git archive -0 --format=zip on large files' '
test_config core.bigfilethreshold 1 &&
git archive -0 --format=zip HEAD >large.zip
'

test_expect_success UNZIP \
'validate file contents with prefix' \
'diff -r a e/prefix/a'
check_zip large

test_expect_success UNZIP 'git archive -0 --format=zip on large files' '
test_config core.bigfilethreshold 1 &&
git archive -0 --format=zip HEAD >large.zip &&
(mkdir large && cd large && $UNZIP ../large.zip)
test_expect_success 'git archive --format=zip on large files' '
test_config core.bigfilethreshold 1 &&
git archive --format=zip HEAD >large-compressed.zip
'

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

test_expect_success \
'git archive --list outside of a git repo' \
Expand Down

0 comments on commit 2dd4233

Please sign in to comment.