Skip to content

Commit 5489899

Browse files
peffgitster
authored andcommitted
t5300: modernize basic tests
The first set of tests in t5300 goes back to 2005, and doesn't use some of our customary style and tools these days. In preparation for touching them, let's modernize a few things: - titles go on the line with test_expect_success, with a hanging open-quote to start the test body - test bodies should be indented with tabs - opening braces for shell blocks in &&-chains go on their own line - no space between redirect operators and files (">foo", not "> foo") - avoid doing work outside of test blocks; in this case, we can stick the setup of ".git2" into the appropriate blocks - avoid modifying and then cleaning up the environment or current directory by using subshells and "git -C" - this test does a curious thing when testing the unpacking: it sets GIT_OBJECT_DIRECTORY, and then does a "git init" in the _original_ directory, creating a weird mixed situation. Instead, it's much simpler to just "git init --bare" a new repository to unpack into, and check the results there. I renamed this "git2" instead of ".git2" to make it more clear it's a separate repo. - we can observe that the bodies of the no-delta, ref_delta, and ofs_delta cases are all virtually identical except for the pack creation, and factor out shared helper functions. I collapsed "do the unpack" and "check the results of the unpack" into a single test, since that makes the expected lifetime of the "git2" temporary directory more clear (that also lets us use test_when_finished to clean it up). This does make the "-v" output slightly less useful, but the improvement in reading the actual test code makes it worth it. - I dropped the "pwd" calls from some tests. These don't do anything functional, and I suspect may have been an aid for debugging when the script was more cavalier about leaving the working directory changed between tests. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e39198 commit 5489899

File tree

1 file changed

+85
-158
lines changed

1 file changed

+85
-158
lines changed

t/t5300-pack-object.sh

Lines changed: 85 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -8,125 +8,74 @@ test_description='git pack-object
88
'
99
. ./test-lib.sh
1010

11-
TRASH=$(pwd)
12-
13-
test_expect_success \
14-
'setup' \
15-
'rm -f .git/index* &&
16-
perl -e "print \"a\" x 4096;" > a &&
17-
perl -e "print \"b\" x 4096;" > b &&
18-
perl -e "print \"c\" x 4096;" > c &&
19-
test-tool genrandom "seed a" 2097152 > a_big &&
20-
test-tool genrandom "seed b" 2097152 > b_big &&
21-
git update-index --add a a_big b b_big c &&
22-
cat c >d && echo foo >>d && git update-index --add d &&
23-
tree=$(git write-tree) &&
24-
commit=$(git commit-tree $tree </dev/null) && {
25-
echo $tree &&
26-
echo $commit &&
27-
git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
28-
} >obj-list && {
29-
git diff-tree --root -p $commit &&
30-
while read object
31-
do
32-
t=$(git cat-file -t $object) &&
33-
git cat-file $t $object || return 1
34-
done <obj-list
35-
} >expect'
36-
37-
test_expect_success \
38-
'pack without delta' \
39-
'packname_1=$(git pack-objects --window=0 test-1 <obj-list)'
40-
41-
test_expect_success \
42-
'pack-objects with bogus arguments' \
43-
'test_must_fail git pack-objects --window=0 test-1 blah blah <obj-list'
44-
45-
rm -fr .git2
46-
mkdir .git2
47-
48-
test_expect_success \
49-
'unpack without delta' \
50-
"GIT_OBJECT_DIRECTORY=.git2/objects &&
51-
export GIT_OBJECT_DIRECTORY &&
52-
git init &&
53-
git unpack-objects -n <test-1-${packname_1}.pack &&
54-
git unpack-objects <test-1-${packname_1}.pack"
55-
56-
unset GIT_OBJECT_DIRECTORY
57-
cd "$TRASH/.git2"
11+
test_expect_success 'setup' '
12+
rm -f .git/index* &&
13+
perl -e "print \"a\" x 4096;" >a &&
14+
perl -e "print \"b\" x 4096;" >b &&
15+
perl -e "print \"c\" x 4096;" >c &&
16+
test-tool genrandom "seed a" 2097152 >a_big &&
17+
test-tool genrandom "seed b" 2097152 >b_big &&
18+
git update-index --add a a_big b b_big c &&
19+
cat c >d && echo foo >>d && git update-index --add d &&
20+
tree=$(git write-tree) &&
21+
commit=$(git commit-tree $tree </dev/null) &&
22+
{
23+
echo $tree &&
24+
echo $commit &&
25+
git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/"
26+
} >obj-list &&
27+
{
28+
git diff-tree --root -p $commit &&
29+
while read object
30+
do
31+
t=$(git cat-file -t $object) &&
32+
git cat-file $t $object || return 1
33+
done <obj-list
34+
} >expect
35+
'
5836

59-
test_expect_success \
60-
'check unpack without delta' \
61-
'(cd ../.git && find objects -type f -print) |
62-
while read path
63-
do
64-
cmp $path ../.git/$path || {
65-
echo $path differs.
66-
return 1
67-
}
68-
done'
69-
cd "$TRASH"
37+
test_expect_success 'pack without delta' '
38+
packname_1=$(git pack-objects --window=0 test-1 <obj-list)
39+
'
7040

71-
test_expect_success \
72-
'pack with REF_DELTA' \
73-
'pwd &&
74-
packname_2=$(git pack-objects test-2 <obj-list)'
41+
test_expect_success 'pack-objects with bogus arguments' '
42+
test_must_fail git pack-objects --window=0 test-1 blah blah <obj-list
43+
'
7544

76-
rm -fr .git2
77-
mkdir .git2
45+
check_unpack () {
46+
test_when_finished "rm -rf git2" &&
47+
git init --bare git2 &&
48+
git -C git2 unpack-objects -n <"$1".pack &&
49+
git -C git2 unpack-objects <"$1".pack &&
50+
(cd .git && find objects -type f -print) |
51+
while read path
52+
do
53+
cmp git2/$path .git/$path || {
54+
echo $path differs.
55+
return 1
56+
}
57+
done
58+
}
59+
60+
test_expect_success 'unpack without delta' '
61+
check_unpack test-1-${packname_1}
62+
'
7863

79-
test_expect_success \
80-
'unpack with REF_DELTA' \
81-
'GIT_OBJECT_DIRECTORY=.git2/objects &&
82-
export GIT_OBJECT_DIRECTORY &&
83-
git init &&
84-
git unpack-objects -n <test-2-${packname_2}.pack &&
85-
git unpack-objects <test-2-${packname_2}.pack'
86-
87-
unset GIT_OBJECT_DIRECTORY
88-
cd "$TRASH/.git2"
89-
test_expect_success \
90-
'check unpack with REF_DELTA' \
91-
'(cd ../.git && find objects -type f -print) |
92-
while read path
93-
do
94-
cmp $path ../.git/$path || {
95-
echo $path differs.
96-
return 1
97-
}
98-
done'
99-
cd "$TRASH"
64+
test_expect_success 'pack with REF_DELTA' '
65+
packname_2=$(git pack-objects test-2 <obj-list)
66+
'
10067

101-
test_expect_success \
102-
'pack with OFS_DELTA' \
103-
'pwd &&
104-
packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)'
68+
test_expect_success 'unpack with REF_DELTA' '
69+
check_unpack test-2-${packname_2}
70+
'
10571

106-
rm -fr .git2
107-
mkdir .git2
72+
test_expect_success 'pack with OFS_DELTA' '
73+
packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)
74+
'
10875

109-
test_expect_success \
110-
'unpack with OFS_DELTA' \
111-
'GIT_OBJECT_DIRECTORY=.git2/objects &&
112-
export GIT_OBJECT_DIRECTORY &&
113-
git init &&
114-
git unpack-objects -n <test-3-${packname_3}.pack &&
115-
git unpack-objects <test-3-${packname_3}.pack'
116-
117-
unset GIT_OBJECT_DIRECTORY
118-
cd "$TRASH/.git2"
119-
test_expect_success \
120-
'check unpack with OFS_DELTA' \
121-
'(cd ../.git && find objects -type f -print) |
122-
while read path
123-
do
124-
cmp $path ../.git/$path || {
125-
echo $path differs.
126-
return 1
127-
}
128-
done'
129-
cd "$TRASH"
76+
test_expect_success 'unpack with OFS_DELTA' '
77+
check_unpack test-3-${packname_3}
78+
'
13079

13180
test_expect_success 'compare delta flavors' '
13281
perl -e '\''
@@ -135,55 +84,33 @@ test_expect_success 'compare delta flavors' '
13584
'\'' test-2-$packname_2.pack test-3-$packname_3.pack
13685
'
13786

138-
rm -fr .git2
139-
mkdir .git2
87+
check_use_objects () {
88+
test_when_finished "rm -rf git2" &&
89+
git init --bare git2 &&
90+
cp "$1".pack "$1".idx git2/objects/pack &&
91+
(
92+
cd git2 &&
93+
git diff-tree --root -p $commit &&
94+
while read object
95+
do
96+
t=$(git cat-file -t $object) &&
97+
git cat-file $t $object || exit 1
98+
done
99+
) <obj-list >current &&
100+
cmp expect current
101+
}
140102

141-
test_expect_success \
142-
'use packed objects' \
143-
'GIT_OBJECT_DIRECTORY=.git2/objects &&
144-
export GIT_OBJECT_DIRECTORY &&
145-
git init &&
146-
cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
147-
git diff-tree --root -p $commit &&
148-
while read object
149-
do
150-
t=$(git cat-file -t $object) &&
151-
git cat-file $t $object || return 1
152-
done <obj-list
153-
} >current &&
154-
cmp expect current'
103+
test_expect_success 'use packed objects' '
104+
check_use_objects test-1-${packname_1}
105+
'
155106

156-
test_expect_success \
157-
'use packed deltified (REF_DELTA) objects' \
158-
'GIT_OBJECT_DIRECTORY=.git2/objects &&
159-
export GIT_OBJECT_DIRECTORY &&
160-
rm -f .git2/objects/pack/test-* &&
161-
cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && {
162-
git diff-tree --root -p $commit &&
163-
while read object
164-
do
165-
t=$(git cat-file -t $object) &&
166-
git cat-file $t $object || return 1
167-
done <obj-list
168-
} >current &&
169-
cmp expect current'
107+
test_expect_success 'use packed deltified (REF_DELTA) objects' '
108+
check_use_objects test-2-${packname_2}
109+
'
170110

171-
test_expect_success \
172-
'use packed deltified (OFS_DELTA) objects' \
173-
'GIT_OBJECT_DIRECTORY=.git2/objects &&
174-
export GIT_OBJECT_DIRECTORY &&
175-
rm -f .git2/objects/pack/test-* &&
176-
cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && {
177-
git diff-tree --root -p $commit &&
178-
while read object
179-
do
180-
t=$(git cat-file -t $object) &&
181-
git cat-file $t $object || return 1
182-
done <obj-list
183-
} >current &&
184-
cmp expect current'
185-
186-
unset GIT_OBJECT_DIRECTORY
111+
test_expect_success 'use packed deltified (OFS_DELTA) objects' '
112+
check_use_objects test-3-${packname_3}
113+
'
187114

188115
test_expect_success 'survive missing objects/pack directory' '
189116
(

0 commit comments

Comments
 (0)