@matheusbsbs / matheus-bagliano / commits / 3902985a58
Fork 0

t5500: Modernize test style

Code outside of the test harness was emitting "Initializing..." from git-init. Fixup this test to be more modern: - test_expect_object_count() and count_objects() are unused - use grep directly instead of test "..." = $(grep ...) - end the test_expect_success line with a single-quote and put the test on a new line - put as much code inside the test harness as possible - no_strict_count_check is unused and duplicates the test "new object count" - use && whenever possible to catch errors early - use test_tick instead of GIT_AUTHOR_DATE=$sec - remove debugging aid log.txt - use subshells instead of cd-ing around Also merge the pull test into one large test. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stephen Boyd committed May 25, 2009 at 23:17 UTC 3902985a58d5b5f42406f11f1c8b9b87a98c7e3c
1 file changed +149 -127
t/t5500-fetch-pack.sh
+149 -127
@@ -3,9 +3,8 @@
3 # Copyright (c) 2005 Johannes Schindelin
4 #
5
6 -test_description='Testing multi_ack pack fetching
6 +test_description='Testing multi_ack pack fetching'
7
8 -'
8 . ./test-lib.sh
9
10 # Test fetch-pack/upload-pack pair.
@@ -13,77 +12,60 @@ test_description='Testing multi_ack pack fetching
12 # Some convenience functions
13
14 add () {
16 - name=$1
17 - text="$@"
18 - branch=`echo $name | sed -e 's/^\(.\).*$/\1/'`
19 - parents=""
15 + name=$1 &&
16 + text="$@" &&
17 + branch=`echo $name | sed -e 's/^\(.\).*$/\1/'` &&
18 + parents="" &&
19
21 - shift
20 + shift &&
21 while test $1; do
23 - parents="$parents -p $1"
22 + parents="$parents -p $1" &&
23 shift
25 - done
24 + done &&
25
27 - echo "$text" > test.txt
28 - git update-index --add test.txt
29 - tree=$(git write-tree)
26 + echo "$text" > test.txt &&
27 + git update-index --add test.txt &&
28 + tree=$(git write-tree) &&
29 # make sure timestamps are in correct order
31 - sec=$(($sec+1))
32 - commit=$(echo "$text" | GIT_AUTHOR_DATE=$sec \
33 - git commit-tree $tree $parents 2>>log2.txt)
34 - eval "$name=$commit; export $name"
35 - echo $commit > .git/refs/heads/$branch
30 + test_tick &&
31 + commit=$(echo "$text" | git commit-tree $tree $parents) &&
32 + eval "$name=$commit; export $name" &&
33 + echo $commit > .git/refs/heads/$branch &&
34 eval ${branch}TIP=$commit
35 }
36
39 -count_objects () {
40 - ls .git/objects/??/* 2>>log2.txt | wc -l | tr -d " "
41 -}
42 -
43 -test_expect_object_count () {
44 - message=$1
45 - count=$2
46 -
47 - output="$(count_objects)"
48 - test_expect_success \
49 - "new object count $message" \
50 - "test $count = $output"
51 -}
52 -
37 pull_to_client () {
54 - number=$1
55 - heads=$2
56 - count=$3
57 - no_strict_count_check=$4
58 -
59 - cd client
60 - test_expect_success "$number pull" \
61 - "git fetch-pack -k -v .. $heads"
62 - case "$heads" in *A*) echo $ATIP > .git/refs/heads/A;; esac
63 - case "$heads" in *B*) echo $BTIP > .git/refs/heads/B;; esac
64 - git symbolic-ref HEAD refs/heads/`echo $heads | sed -e 's/^\(.\).*$/\1/'`
65 -
66 - test_expect_success "fsck" 'git fsck --full > fsck.txt 2>&1'
67 -
68 - test_expect_success 'check downloaded results' \
69 - 'mv .git/objects/pack/pack-* . &&
70 - p=`ls -1 pack-*.pack` &&
71 - git unpack-objects <$p &&
72 - git fsck --full'
73 -
74 - test_expect_success "new object count after $number pull" \
75 - 'idx=`echo pack-*.idx` &&
76 - pack_count=`git show-index <$idx | wc -l` &&
77 - test $pack_count = $count'
78 - test -z "$pack_count" && pack_count=0
79 - if [ -z "$no_strict_count_check" ]; then
80 - test_expect_success "minimal count" "test $count = $pack_count"
81 - else
82 - test $count != $pack_count && \
83 - echo "WARNING: $pack_count objects transmitted, only $count of which were needed"
84 - fi
85 - rm -f pack-*
86 - cd ..
38 + number=$1 &&
39 + heads=$2 &&
40 + count=$3 &&
41 + test_expect_success "$number pull" '
42 + (
43 + cd client &&
44 + git fetch-pack -k -v .. $heads &&
45 +
46 + case "$heads" in
47 + *A*)
48 + echo $ATIP > .git/refs/heads/A;;
49 + esac &&
50 + case "$heads" in *B*)
51 + echo $BTIP > .git/refs/heads/B;;
52 + esac &&
53 + git symbolic-ref HEAD refs/heads/`echo $heads \
54 + | sed -e "s/^\(.\).*$/\1/"` &&
55 +
56 + git fsck --full &&
57 +
58 + mv .git/objects/pack/pack-* . &&
59 + p=`ls -1 pack-*.pack` &&
60 + git unpack-objects <$p &&
61 + git fsck --full &&
62 +
63 + idx=`echo pack-*.idx` &&
64 + pack_count=`git show-index <$idx | wc -l` &&
65 + test $pack_count = $count &&
66 + rm -f pack-*
67 + )
68 + '
69 }
70
71 # Here begins the actual testing
@@ -94,89 +76,129 @@ pull_to_client () {
76
77 # client pulls A20, B1. Then tracks only B. Then pulls A.
78
97 -(
79 +test_expect_success 'setup' '
80 mkdir client &&
99 - cd client &&
100 - git init 2>> log2.txt &&
101 - git config transfer.unpacklimit 0
102 -)
103 -
104 -add A1
105 -
106 -prev=1; cur=2; while [ $cur -le 10 ]; do
107 - add A$cur $(eval echo \$A$prev)
108 - prev=$cur
109 - cur=$(($cur+1))
110 -done
111 -
112 -add B1 $A1
113 -
114 -echo $ATIP > .git/refs/heads/A
115 -echo $BTIP > .git/refs/heads/B
116 -git symbolic-ref HEAD refs/heads/B
81 + (
82 + cd client &&
83 + git init &&
84 + git config transfer.unpacklimit 0
85 + ) &&
86 + add A1 &&
87 + prev=1 &&
88 + cur=2 &&
89 + while [ $cur -le 10 ]; do
90 + add A$cur $(eval echo \$A$prev) &&
91 + prev=$cur &&
92 + cur=$(($cur+1))
93 + done &&
94 + add B1 $A1
95 + echo $ATIP > .git/refs/heads/A &&
96 + echo $BTIP > .git/refs/heads/B &&
97 + git symbolic-ref HEAD refs/heads/B
98 +'
99
100 pull_to_client 1st "B A" $((11*3))
101
120 -add A11 $A10
121 -
122 -prev=1; cur=2; while [ $cur -le 65 ]; do
123 - add B$cur $(eval echo \$B$prev)
124 - prev=$cur
125 - cur=$(($cur+1))
126 -done
102 +test_expect_success 'post 1st pull setup' '
103 + add A11 $A10 &&
104 + prev=1 &&
105 + cur=2 &&
106 + while [ $cur -le 65 ]; do
107 + add B$cur $(eval echo \$B$prev) &&
108 + prev=$cur &&
109 + cur=$(($cur+1))
110 + done
111 +'
112
113 pull_to_client 2nd "B" $((64*3))
114
130 -pull_to_client 3rd "A" $((1*3)) # old fails
131 -
132 -test_expect_success "clone shallow" 'git clone --depth 2 "file://$(pwd)/." shallow'
115 +pull_to_client 3rd "A" $((1*3))
116
134 -(cd shallow; git count-objects -v) > count.shallow
135 -
136 -test_expect_success "clone shallow object count" \
137 - "test \"in-pack: 18\" = \"$(grep in-pack count.shallow)\""
138 -
139 -count_output () {
140 - sed -e '/^in-pack:/d' -e '/^packs:/d' -e '/^size-pack:/d' -e '/: 0$/d' "$1"
141 -}
117 +test_expect_success 'clone shallow' '
118 + git clone --depth 2 "file://$(pwd)/." shallow
119 +'
120
143 -test_expect_success "clone shallow object count (part 2)" '
144 - test -z "$(count_output count.shallow)"
121 +test_expect_success 'clone shallow object count' '
122 + (
123 + cd shallow &&
124 + git count-objects -v
125 + ) > count.shallow &&
126 + grep "^in-pack: 18" count.shallow
127 '
128
147 -test_expect_success "fsck in shallow repo" \
148 - "(cd shallow; git fsck --full)"
129 +test_expect_success 'clone shallow object count (part 2)' '
130 + sed -e "/^in-pack:/d" -e "/^packs:/d" -e "/^size-pack:/d" \
131 + -e "/: 0$/d" count.shallow > count_output &&
132 + ! test -s count_output
133 +'
134
150 -#test_done; exit
135 +test_expect_success 'fsck in shallow repo' '
136 + (
137 + cd shallow &&
138 + git fsck --full
139 + )
140 +'
141
152 -add B66 $B65
153 -add B67 $B66
142 +test_expect_success 'add two more' '
143 + add B66 $B65 &&
144 + add B67 $B66
145 +'
146
155 -test_expect_success "pull in shallow repo" \
156 - "(cd shallow; git pull .. B)"
147 +test_expect_success 'pull in shallow repo' '
148 + (
149 + cd shallow &&
150 + git pull .. B
151 + )
152 +'
153
158 -(cd shallow; git count-objects -v) > count.shallow
159 -test_expect_success "clone shallow object count" \
160 - "test \"count: 6\" = \"$(grep count count.shallow)\""
154 +test_expect_success 'clone shallow object count' '
155 + (
156 + cd shallow &&
157 + git count-objects -v
158 + ) > count.shallow &&
159 + grep "^count: 6" count.shallow
160 +'
161
162 -add B68 $B67
163 -add B69 $B68
162 +test_expect_success 'add two more (part 2)' '
163 + add B68 $B67 &&
164 + add B69 $B68
165 +'
166
165 -test_expect_success "deepening pull in shallow repo" \
166 - "(cd shallow; git pull --depth 4 .. B)"
167 +test_expect_success 'deepening pull in shallow repo' '
168 + (
169 + cd shallow &&
170 + git pull --depth 4 .. B
171 + )
172 +'
173
168 -(cd shallow; git count-objects -v) > count.shallow
169 -test_expect_success "clone shallow object count" \
170 - "test \"count: 12\" = \"$(grep count count.shallow)\""
174 +test_expect_success 'clone shallow object count' '
175 + (
176 + cd shallow &&
177 + git count-objects -v
178 + ) > count.shallow &&
179 + grep "^count: 12" count.shallow
180 +'
181
172 -test_expect_success "deepening fetch in shallow repo" \
173 - "(cd shallow; git fetch --depth 4 .. A:A)"
182 +test_expect_success 'deepening fetch in shallow repo' '
183 + (
184 + cd shallow &&
185 + git fetch --depth 4 .. A:A
186 + )
187 +'
188
175 -(cd shallow; git count-objects -v) > count.shallow
176 -test_expect_success "clone shallow object count" \
177 - "test \"count: 18\" = \"$(grep count count.shallow)\""
189 +test_expect_success 'clone shallow object count' '
190 + (
191 + cd shallow &&
192 + git count-objects -v
193 + ) > count.shallow &&
194 + grep "^count: 18" count.shallow
195 +'
196
179 -test_expect_success "pull in shallow repo with missing merge base" \
180 - "(cd shallow && test_must_fail git pull --depth 4 .. A)"
197 +test_expect_success 'pull in shallow repo with missing merge base' '
198 + (
199 + cd shallow &&
200 + test_must_fail git pull --depth 4 .. A
201 + )
202 +'
203
204 test_done