]>
Commit | Line | Data |
---|---|---|
e1970ce4 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
6 | test_description='Test the very basics part #1. | |
7 | ||
8 | The rest of the test suite does not check the basic operation of git | |
9 | plumbing commands to work very carefully. Their job is to concentrate | |
10 | on tricky features that caused bugs in the past to detect regression. | |
11 | ||
12 | This test runs very basic features, like registering things in cache, | |
13 | writing tree, etc. | |
14 | ||
15 | Note that this test *deliberately* hard-codes many expected object | |
16 | IDs. When object ID computation changes, like in the previous case of | |
17 | swapping compression and hashing order, the person who is making the | |
18 | modification *should* take notice and update the test vectors here. | |
19 | ' | |
eea42069 | 20 | |
e1970ce4 | 21 | . ./test-lib.sh |
866a3014 | 22 | . "$TEST_DIRECTORY"/lib-subtest.sh |
e1970ce4 | 23 | |
8cb79803 DL |
24 | try_local_xy () { |
25 | local x="local" y="alsolocal" && | |
26 | echo "$x $y" | |
01d3a526 MH |
27 | } |
28 | ||
7f0b5908 | 29 | # Check whether the shell supports the "local" keyword. "local" is not |
01d3a526 | 30 | # POSIX-standard, but it is very widely supported by POSIX-compliant |
7f0b5908 | 31 | # shells, and we rely on it within Git's test framework. |
01d3a526 | 32 | # |
7f0b5908 JK |
33 | # If your shell fails this test, the results of other tests may be |
34 | # unreliable. You may wish to report the problem to the Git mailing | |
35 | # list <git@vger.kernel.org>, as it could cause us to reconsider | |
36 | # relying on "local". | |
01d3a526 MH |
37 | test_expect_success 'verify that the running shell supports "local"' ' |
38 | x="notlocal" && | |
8cb79803 DL |
39 | y="alsonotlocal" && |
40 | echo "local alsolocal" >expected1 && | |
41 | try_local_xy >actual1 && | |
01d3a526 | 42 | test_cmp expected1 actual1 && |
8cb79803 DL |
43 | echo "notlocal alsonotlocal" >expected2 && |
44 | echo "$x $y" >actual2 && | |
01d3a526 MH |
45 | test_cmp expected2 actual2 |
46 | ' | |
47 | ||
e1970ce4 | 48 | ################################################################ |
5be60078 | 49 | # git init has been done in an empty repository. |
e1970ce4 JH |
50 | # make sure it is empty. |
51 | ||
1b5b2b64 SL |
52 | test_expect_success '.git/objects should be empty after git init in an empty repo' ' |
53 | find .git/objects -type f -print >should-be-empty && | |
54 | test_line_count = 0 should-be-empty | |
55 | ' | |
e1970ce4 | 56 | |
9106c097 LT |
57 | # also it should have 2 subdirectories; no fan-out anymore, pack, and info. |
58 | # 3 is counting "objects" itself | |
1b5b2b64 SL |
59 | test_expect_success '.git/objects should have 3 subdirectories' ' |
60 | find .git/objects -type d -print >full-of-directories && | |
61 | test_line_count = 3 full-of-directories | |
62 | ' | |
e1970ce4 | 63 | |
41ac414e JH |
64 | ################################################################ |
65 | # Test harness | |
66 | test_expect_success 'success is reported like this' ' | |
1b5b2b64 | 67 | : |
41ac414e | 68 | ' |
7b905119 | 69 | |
c3ff7be6 ÆAB |
70 | test_expect_success 'subtest: 3 passing tests' ' |
71 | write_and_run_sub_test_lib_test full-pass <<-\EOF && | |
5ebf89e8 AS |
72 | for i in 1 2 3 |
73 | do | |
30291525 | 74 | test_expect_success "passing test #$i" "true" |
5ebf89e8 AS |
75 | done |
76 | test_done | |
77 | EOF | |
30291525 | 78 | check_sub_test_lib_test full-pass <<-\EOF |
5ebf89e8 AS |
79 | > ok 1 - passing test #1 |
80 | > ok 2 - passing test #2 | |
81 | > ok 3 - passing test #3 | |
82 | > # passed all 3 test(s) | |
83 | > 1..3 | |
84 | EOF | |
30291525 | 85 | ' |
1b5b2b64 | 86 | |
c3ff7be6 ÆAB |
87 | test_expect_success 'subtest: 2/3 tests passing' ' |
88 | write_and_run_sub_test_lib_test_err partial-pass <<-\EOF && | |
30291525 JK |
89 | test_expect_success "passing test #1" "true" |
90 | test_expect_success "failing test #2" "false" | |
91 | test_expect_success "passing test #3" "true" | |
5ebf89e8 AS |
92 | test_done |
93 | EOF | |
30291525 | 94 | check_sub_test_lib_test partial-pass <<-\EOF |
5ebf89e8 AS |
95 | > ok 1 - passing test #1 |
96 | > not ok 2 - failing test #2 | |
97 | # false | |
98 | > ok 3 - passing test #3 | |
99 | > # failed 1 among 3 test(s) | |
100 | > 1..3 | |
101 | EOF | |
30291525 | 102 | ' |
1b5b2b64 | 103 | |
c3ff7be6 ÆAB |
104 | test_expect_success 'subtest: a failing TODO test' ' |
105 | write_and_run_sub_test_lib_test failing-todo <<-\EOF && | |
30291525 JK |
106 | test_expect_success "passing test" "true" |
107 | test_expect_failure "pretend we have a known breakage" "false" | |
5ebf89e8 AS |
108 | test_done |
109 | EOF | |
30291525 | 110 | check_sub_test_lib_test failing-todo <<-\EOF |
5ebf89e8 AS |
111 | > ok 1 - passing test |
112 | > not ok 2 - pretend we have a known breakage # TODO known breakage | |
113 | > # still have 1 known breakage(s) | |
114 | > # passed all remaining 1 test(s) | |
115 | > 1..2 | |
116 | EOF | |
30291525 | 117 | ' |
1b5b2b64 | 118 | |
c3ff7be6 ÆAB |
119 | test_expect_success 'subtest: a passing TODO test' ' |
120 | write_and_run_sub_test_lib_test passing-todo <<-\EOF && | |
30291525 | 121 | test_expect_failure "pretend we have fixed a known breakage" "true" |
1b5b2b64 SL |
122 | test_done |
123 | EOF | |
30291525 | 124 | check_sub_test_lib_test passing-todo <<-\EOF |
b73d9a23 AS |
125 | > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished |
126 | > # 1 known breakage(s) vanished; please update test(s) | |
1b5b2b64 SL |
127 | > 1..1 |
128 | EOF | |
30291525 | 129 | ' |
565b6fa8 | 130 | |
c3ff7be6 ÆAB |
131 | test_expect_success 'subtest: 2 TODO tests, one passin' ' |
132 | write_and_run_sub_test_lib_test partially-passing-todos <<-\EOF && | |
30291525 JK |
133 | test_expect_failure "pretend we have a known breakage" "false" |
134 | test_expect_success "pretend we have a passing test" "true" | |
135 | test_expect_failure "pretend we have fixed another known breakage" "true" | |
b73d9a23 AS |
136 | test_done |
137 | EOF | |
30291525 | 138 | check_sub_test_lib_test partially-passing-todos <<-\EOF |
b73d9a23 AS |
139 | > not ok 1 - pretend we have a known breakage # TODO known breakage |
140 | > ok 2 - pretend we have a passing test | |
141 | > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished | |
142 | > # 1 known breakage(s) vanished; please update test(s) | |
143 | > # still have 1 known breakage(s) | |
144 | > # passed all remaining 1 test(s) | |
145 | > 1..3 | |
146 | EOF | |
30291525 | 147 | ' |
b73d9a23 | 148 | |
c3ff7be6 ÆAB |
149 | test_expect_success 'subtest: mixed results: pass, failure and a TODO test' ' |
150 | write_and_run_sub_test_lib_test_err mixed-results1 <<-\EOF && | |
30291525 JK |
151 | test_expect_success "passing test" "true" |
152 | test_expect_success "failing test" "false" | |
153 | test_expect_failure "pretend we have a known breakage" "false" | |
5ebf89e8 AS |
154 | test_done |
155 | EOF | |
30291525 | 156 | check_sub_test_lib_test mixed-results1 <<-\EOF |
5ebf89e8 AS |
157 | > ok 1 - passing test |
158 | > not ok 2 - failing test | |
159 | > # false | |
160 | > not ok 3 - pretend we have a known breakage # TODO known breakage | |
161 | > # still have 1 known breakage(s) | |
162 | > # failed 1 among remaining 2 test(s) | |
163 | > 1..3 | |
164 | EOF | |
30291525 | 165 | ' |
5ebf89e8 | 166 | |
c3ff7be6 ÆAB |
167 | test_expect_success 'subtest: mixed results: a mixture of all possible results' ' |
168 | write_and_run_sub_test_lib_test_err mixed-results2 <<-\EOF && | |
30291525 JK |
169 | test_expect_success "passing test" "true" |
170 | test_expect_success "passing test" "true" | |
171 | test_expect_success "passing test" "true" | |
172 | test_expect_success "passing test" "true" | |
173 | test_expect_success "failing test" "false" | |
174 | test_expect_success "failing test" "false" | |
175 | test_expect_success "failing test" "false" | |
176 | test_expect_failure "pretend we have a known breakage" "false" | |
177 | test_expect_failure "pretend we have a known breakage" "false" | |
178 | test_expect_failure "pretend we have fixed a known breakage" "true" | |
179 | test_done | |
180 | EOF | |
181 | check_sub_test_lib_test mixed-results2 <<-\EOF | |
5ebf89e8 AS |
182 | > ok 1 - passing test |
183 | > ok 2 - passing test | |
184 | > ok 3 - passing test | |
185 | > ok 4 - passing test | |
186 | > not ok 5 - failing test | |
187 | > # false | |
188 | > not ok 6 - failing test | |
189 | > # false | |
190 | > not ok 7 - failing test | |
191 | > # false | |
192 | > not ok 8 - pretend we have a known breakage # TODO known breakage | |
193 | > not ok 9 - pretend we have a known breakage # TODO known breakage | |
b73d9a23 AS |
194 | > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished |
195 | > # 1 known breakage(s) vanished; please update test(s) | |
5ebf89e8 | 196 | > # still have 2 known breakage(s) |
b73d9a23 | 197 | > # failed 3 among remaining 7 test(s) |
5ebf89e8 AS |
198 | > 1..10 |
199 | EOF | |
30291525 | 200 | ' |
5ebf89e8 | 201 | |
c3ff7be6 ÆAB |
202 | test_expect_success 'subtest: --verbose option' ' |
203 | write_and_run_sub_test_lib_test_err t1234-verbose --verbose <<-\EOF && | |
517cd55f TR |
204 | test_expect_success "passing test" true |
205 | test_expect_success "test with output" "echo foo" | |
206 | test_expect_success "failing test" false | |
207 | test_done | |
208 | EOF | |
96f3ccc2 SG |
209 | mv t1234-verbose/out t1234-verbose/out+ && |
210 | grep -v "^Initialized empty" t1234-verbose/out+ >t1234-verbose/out && | |
211 | check_sub_test_lib_test t1234-verbose <<-\EOF | |
ffe1afe6 | 212 | > expecting success of 1234.1 '\''passing test'\'': true |
517cd55f TR |
213 | > ok 1 - passing test |
214 | > Z | |
ffe1afe6 | 215 | > expecting success of 1234.2 '\''test with output'\'': echo foo |
517cd55f | 216 | > foo |
517cd55f TR |
217 | > ok 2 - test with output |
218 | > Z | |
ffe1afe6 | 219 | > expecting success of 1234.3 '\''failing test'\'': false |
517cd55f TR |
220 | > not ok 3 - failing test |
221 | > # false | |
222 | > Z | |
223 | > # failed 1 among 3 test(s) | |
224 | > 1..3 | |
225 | EOF | |
226 | ' | |
227 | ||
c3ff7be6 | 228 | test_expect_success 'subtest: --verbose-only option' ' |
77172420 | 229 | run_sub_test_lib_test_err \ |
2e54907e ÆAB |
230 | t1234-verbose \ |
231 | --verbose-only=2 && | |
232 | check_sub_test_lib_test t1234-verbose <<-\EOF | |
ff09af3f TR |
233 | > ok 1 - passing test |
234 | > Z | |
2e54907e | 235 | > expecting success of 1234.2 '\''test with output'\'': echo foo |
ff09af3f | 236 | > foo |
ff09af3f TR |
237 | > ok 2 - test with output |
238 | > Z | |
239 | > not ok 3 - failing test | |
240 | > # false | |
241 | > # failed 1 among 3 test(s) | |
242 | > 1..3 | |
243 | EOF | |
244 | ' | |
245 | ||
c3ff7be6 | 246 | test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' ' |
7e28c16f | 247 | ( |
2e54907e ÆAB |
248 | run_sub_test_lib_test full-pass \ |
249 | --skip="full.2" && | |
250 | check_sub_test_lib_test full-pass <<-\EOF | |
7e28c16f RJ |
251 | > ok 1 - passing test #1 |
252 | > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) | |
253 | > ok 3 - passing test #3 | |
254 | > # passed all 3 test(s) | |
255 | > 1..3 | |
256 | EOF | |
257 | ) | |
30291525 | 258 | ' |
ef2ac68d | 259 | |
c3ff7be6 | 260 | test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' ' |
7e28c16f | 261 | ( |
9f0a4520 | 262 | write_and_run_sub_test_lib_test git-skip-tests-several \ |
ac223c40 | 263 | --skip="git.2 git.5" <<-\EOF && |
7e28c16f RJ |
264 | for i in 1 2 3 4 5 6 |
265 | do | |
30291525 | 266 | test_expect_success "passing test #$i" "true" |
7e28c16f RJ |
267 | done |
268 | test_done | |
269 | EOF | |
30291525 | 270 | check_sub_test_lib_test git-skip-tests-several <<-\EOF |
7e28c16f RJ |
271 | > ok 1 - passing test #1 |
272 | > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) | |
273 | > ok 3 - passing test #3 | |
274 | > ok 4 - passing test #4 | |
275 | > ok 5 # skip passing test #5 (GIT_SKIP_TESTS) | |
276 | > ok 6 - passing test #6 | |
277 | > # passed all 6 test(s) | |
278 | > 1..6 | |
279 | EOF | |
280 | ) | |
30291525 | 281 | ' |
ef2ac68d | 282 | |
c3ff7be6 | 283 | test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' ' |
7e28c16f | 284 | ( |
2e54907e ÆAB |
285 | run_sub_test_lib_test git-skip-tests-several \ |
286 | --skip="git.[2-5]" && | |
287 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
7e28c16f RJ |
288 | > ok 1 - passing test #1 |
289 | > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) | |
290 | > ok 3 # skip passing test #3 (GIT_SKIP_TESTS) | |
291 | > ok 4 # skip passing test #4 (GIT_SKIP_TESTS) | |
292 | > ok 5 # skip passing test #5 (GIT_SKIP_TESTS) | |
293 | > ok 6 - passing test #6 | |
294 | > # passed all 6 test(s) | |
295 | > 1..6 | |
296 | EOF | |
297 | ) | |
30291525 | 298 | ' |
ef2ac68d | 299 | |
c3ff7be6 | 300 | test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' ' |
b05b4093 | 301 | ( |
2e54907e ÆAB |
302 | GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS && |
303 | run_sub_test_lib_test git-skip-tests-several \ | |
304 | --skip="git" && | |
305 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
b05b4093 DL |
306 | > 1..0 # SKIP skip all tests in git |
307 | EOF | |
308 | ) | |
30291525 | 309 | ' |
b05b4093 | 310 | |
c3ff7be6 | 311 | test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' ' |
b05b4093 | 312 | ( |
2e54907e ÆAB |
313 | GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS && |
314 | run_sub_test_lib_test full-pass \ | |
315 | --skip="notfull" && | |
316 | check_sub_test_lib_test full-pass <<-\EOF | |
b05b4093 DL |
317 | > ok 1 - passing test #1 |
318 | > ok 2 - passing test #2 | |
319 | > ok 3 - passing test #3 | |
320 | > # passed all 3 test(s) | |
321 | > 1..3 | |
322 | EOF | |
323 | ) | |
30291525 | 324 | ' |
b05b4093 | 325 | |
c3ff7be6 | 326 | test_expect_success 'subtest: --run basic' ' |
2e54907e ÆAB |
327 | run_sub_test_lib_test git-skip-tests-several --run="1,3,5" && |
328 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
329 | > ok 1 - passing test #1 |
330 | > ok 2 # skip passing test #2 (--run) | |
331 | > ok 3 - passing test #3 | |
332 | > ok 4 # skip passing test #4 (--run) | |
333 | > ok 5 - passing test #5 | |
334 | > ok 6 # skip passing test #6 (--run) | |
335 | > # passed all 6 test(s) | |
336 | > 1..6 | |
337 | EOF | |
30291525 | 338 | ' |
0445e6f0 | 339 | |
c3ff7be6 | 340 | test_expect_success 'subtest: --run with a range' ' |
2e54907e ÆAB |
341 | run_sub_test_lib_test git-skip-tests-several \ |
342 | --run="1-3" && | |
343 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
344 | > ok 1 - passing test #1 |
345 | > ok 2 - passing test #2 | |
346 | > ok 3 - passing test #3 | |
347 | > ok 4 # skip passing test #4 (--run) | |
348 | > ok 5 # skip passing test #5 (--run) | |
349 | > ok 6 # skip passing test #6 (--run) | |
350 | > # passed all 6 test(s) | |
351 | > 1..6 | |
352 | EOF | |
30291525 | 353 | ' |
0445e6f0 | 354 | |
c3ff7be6 | 355 | test_expect_success 'subtest: --run with two ranges' ' |
2e54907e ÆAB |
356 | run_sub_test_lib_test git-skip-tests-several \ |
357 | --run="1-2,5-6" && | |
358 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
359 | > ok 1 - passing test #1 |
360 | > ok 2 - passing test #2 | |
361 | > ok 3 # skip passing test #3 (--run) | |
362 | > ok 4 # skip passing test #4 (--run) | |
363 | > ok 5 - passing test #5 | |
364 | > ok 6 - passing test #6 | |
365 | > # passed all 6 test(s) | |
366 | > 1..6 | |
367 | EOF | |
30291525 | 368 | ' |
0445e6f0 | 369 | |
c3ff7be6 | 370 | test_expect_success 'subtest: --run with a left open range' ' |
2e54907e ÆAB |
371 | run_sub_test_lib_test git-skip-tests-several \ |
372 | --run="-3" && | |
373 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
374 | > ok 1 - passing test #1 |
375 | > ok 2 - passing test #2 | |
376 | > ok 3 - passing test #3 | |
377 | > ok 4 # skip passing test #4 (--run) | |
378 | > ok 5 # skip passing test #5 (--run) | |
379 | > ok 6 # skip passing test #6 (--run) | |
380 | > # passed all 6 test(s) | |
381 | > 1..6 | |
382 | EOF | |
30291525 | 383 | ' |
0445e6f0 | 384 | |
c3ff7be6 | 385 | test_expect_success 'subtest: --run with a right open range' ' |
2e54907e ÆAB |
386 | run_sub_test_lib_test git-skip-tests-several \ |
387 | --run="4-" && | |
388 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
389 | > ok 1 # skip passing test #1 (--run) |
390 | > ok 2 # skip passing test #2 (--run) | |
391 | > ok 3 # skip passing test #3 (--run) | |
392 | > ok 4 - passing test #4 | |
393 | > ok 5 - passing test #5 | |
394 | > ok 6 - passing test #6 | |
395 | > # passed all 6 test(s) | |
396 | > 1..6 | |
397 | EOF | |
30291525 | 398 | ' |
0445e6f0 | 399 | |
c3ff7be6 | 400 | test_expect_success 'subtest: --run with basic negation' ' |
2e54907e ÆAB |
401 | run_sub_test_lib_test git-skip-tests-several \ |
402 | --run="!3" && | |
403 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
404 | > ok 1 - passing test #1 |
405 | > ok 2 - passing test #2 | |
406 | > ok 3 # skip passing test #3 (--run) | |
407 | > ok 4 - passing test #4 | |
408 | > ok 5 - passing test #5 | |
409 | > ok 6 - passing test #6 | |
410 | > # passed all 6 test(s) | |
411 | > 1..6 | |
412 | EOF | |
30291525 | 413 | ' |
0445e6f0 | 414 | |
c3ff7be6 | 415 | test_expect_success 'subtest: --run with two negations' ' |
2e54907e ÆAB |
416 | run_sub_test_lib_test git-skip-tests-several \ |
417 | --run="!3,!6" && | |
418 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
419 | > ok 1 - passing test #1 |
420 | > ok 2 - passing test #2 | |
421 | > ok 3 # skip passing test #3 (--run) | |
422 | > ok 4 - passing test #4 | |
423 | > ok 5 - passing test #5 | |
424 | > ok 6 # skip passing test #6 (--run) | |
425 | > # passed all 6 test(s) | |
426 | > 1..6 | |
427 | EOF | |
30291525 | 428 | ' |
0445e6f0 | 429 | |
c3ff7be6 | 430 | test_expect_success 'subtest: --run a range and negation' ' |
2e54907e ÆAB |
431 | run_sub_test_lib_test git-skip-tests-several \ |
432 | --run="-4,!2" && | |
433 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
434 | > ok 1 - passing test #1 |
435 | > ok 2 # skip passing test #2 (--run) | |
436 | > ok 3 - passing test #3 | |
437 | > ok 4 - passing test #4 | |
438 | > ok 5 # skip passing test #5 (--run) | |
439 | > ok 6 # skip passing test #6 (--run) | |
440 | > # passed all 6 test(s) | |
441 | > 1..6 | |
442 | EOF | |
30291525 | 443 | ' |
0445e6f0 | 444 | |
c3ff7be6 | 445 | test_expect_success 'subtest: --run range negation' ' |
2e54907e ÆAB |
446 | run_sub_test_lib_test git-skip-tests-several \ |
447 | --run="!1-3" && | |
448 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
449 | > ok 1 # skip passing test #1 (--run) |
450 | > ok 2 # skip passing test #2 (--run) | |
451 | > ok 3 # skip passing test #3 (--run) | |
452 | > ok 4 - passing test #4 | |
453 | > ok 5 - passing test #5 | |
454 | > ok 6 - passing test #6 | |
455 | > # passed all 6 test(s) | |
456 | > 1..6 | |
457 | EOF | |
30291525 | 458 | ' |
0445e6f0 | 459 | |
c3ff7be6 | 460 | test_expect_success 'subtest: --run include, exclude and include' ' |
2e54907e ÆAB |
461 | run_sub_test_lib_test git-skip-tests-several \ |
462 | --run="1-5,!1-3,2" && | |
463 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
464 | > ok 1 # skip passing test #1 (--run) |
465 | > ok 2 - passing test #2 | |
466 | > ok 3 # skip passing test #3 (--run) | |
467 | > ok 4 - passing test #4 | |
468 | > ok 5 - passing test #5 | |
469 | > ok 6 # skip passing test #6 (--run) | |
470 | > # passed all 6 test(s) | |
471 | > 1..6 | |
472 | EOF | |
30291525 | 473 | ' |
0445e6f0 | 474 | |
c3ff7be6 | 475 | test_expect_success 'subtest: --run include, exclude and include, comma separated' ' |
2e54907e ÆAB |
476 | run_sub_test_lib_test git-skip-tests-several \ |
477 | --run=1-5,!1-3,2 && | |
478 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
479 | > ok 1 # skip passing test #1 (--run) |
480 | > ok 2 - passing test #2 | |
481 | > ok 3 # skip passing test #3 (--run) | |
482 | > ok 4 - passing test #4 | |
483 | > ok 5 - passing test #5 | |
484 | > ok 6 # skip passing test #6 (--run) | |
485 | > # passed all 6 test(s) | |
486 | > 1..6 | |
487 | EOF | |
30291525 | 488 | ' |
0445e6f0 | 489 | |
c3ff7be6 | 490 | test_expect_success 'subtest: --run exclude and include' ' |
2e54907e ÆAB |
491 | run_sub_test_lib_test git-skip-tests-several \ |
492 | --run="!3-,5" && | |
493 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
494 | > ok 1 - passing test #1 |
495 | > ok 2 - passing test #2 | |
496 | > ok 3 # skip passing test #3 (--run) | |
497 | > ok 4 # skip passing test #4 (--run) | |
498 | > ok 5 - passing test #5 | |
499 | > ok 6 # skip passing test #6 (--run) | |
500 | > # passed all 6 test(s) | |
501 | > 1..6 | |
502 | EOF | |
30291525 | 503 | ' |
0445e6f0 | 504 | |
c3ff7be6 | 505 | test_expect_success 'subtest: --run empty selectors' ' |
2e54907e ÆAB |
506 | run_sub_test_lib_test git-skip-tests-several \ |
507 | --run="1,,3,,,5" && | |
508 | check_sub_test_lib_test git-skip-tests-several <<-\EOF | |
0445e6f0 IB |
509 | > ok 1 - passing test #1 |
510 | > ok 2 # skip passing test #2 (--run) | |
511 | > ok 3 - passing test #3 | |
512 | > ok 4 # skip passing test #4 (--run) | |
513 | > ok 5 - passing test #5 | |
514 | > ok 6 # skip passing test #6 (--run) | |
515 | > # passed all 6 test(s) | |
516 | > 1..6 | |
517 | EOF | |
30291525 | 518 | ' |
0445e6f0 | 519 | |
c3ff7be6 | 520 | test_expect_success 'subtest: --run substring selector' ' |
9f0a4520 | 521 | write_and_run_sub_test_lib_test run-substring-selector \ |
30291525 JK |
522 | --run="relevant" <<-\EOF && |
523 | test_expect_success "relevant test" "true" | |
f21ac368 EN |
524 | for i in 1 2 3 4 5 6 |
525 | do | |
30291525 | 526 | test_expect_success "other test #$i" "true" |
f21ac368 EN |
527 | done |
528 | test_done | |
529 | EOF | |
30291525 | 530 | check_sub_test_lib_test run-substring-selector <<-\EOF |
f21ac368 EN |
531 | > ok 1 - relevant test |
532 | > ok 2 # skip other test #1 (--run) | |
533 | > ok 3 # skip other test #2 (--run) | |
534 | > ok 4 # skip other test #3 (--run) | |
535 | > ok 5 # skip other test #4 (--run) | |
536 | > ok 6 # skip other test #5 (--run) | |
537 | > ok 7 # skip other test #6 (--run) | |
538 | > # passed all 7 test(s) | |
539 | > 1..7 | |
540 | EOF | |
30291525 | 541 | ' |
f21ac368 | 542 | |
c3ff7be6 | 543 | test_expect_success 'subtest: --run keyword selection' ' |
9f0a4520 | 544 | write_and_run_sub_test_lib_test_err run-inv-range-start \ |
30291525 JK |
545 | --run="a-5" <<-\EOF && |
546 | test_expect_success "passing test #1" "true" | |
0445e6f0 IB |
547 | test_done |
548 | EOF | |
549 | check_sub_test_lib_test_err run-inv-range-start \ | |
30291525 | 550 | <<-\EOF_OUT 3<<-EOF_ERR |
0445e6f0 IB |
551 | > FATAL: Unexpected exit with code 1 |
552 | EOF_OUT | |
30291525 | 553 | > error: --run: invalid non-numeric in range start: ${SQ}a-5${SQ} |
0445e6f0 | 554 | EOF_ERR |
30291525 | 555 | ' |
0445e6f0 | 556 | |
c3ff7be6 | 557 | test_expect_success 'subtest: --run invalid range end' ' |
2e54907e ÆAB |
558 | run_sub_test_lib_test_err run-inv-range-start \ |
559 | --run="1-z" && | |
560 | check_sub_test_lib_test_err run-inv-range-start \ | |
30291525 | 561 | <<-\EOF_OUT 3<<-EOF_ERR |
0445e6f0 IB |
562 | > FATAL: Unexpected exit with code 1 |
563 | EOF_OUT | |
30291525 | 564 | > error: --run: invalid non-numeric in range end: ${SQ}1-z${SQ} |
0445e6f0 | 565 | EOF_ERR |
30291525 | 566 | ' |
0445e6f0 | 567 | |
c3ff7be6 ÆAB |
568 | test_expect_success 'subtest: tests respect prerequisites' ' |
569 | write_and_run_sub_test_lib_test prereqs <<-\EOF && | |
0445e6f0 | 570 | |
efd2600e JK |
571 | test_set_prereq HAVEIT |
572 | test_expect_success HAVEIT "prereq is satisfied" "true" | |
573 | test_expect_success "have_prereq works" " | |
574 | test_have_prereq HAVEIT | |
575 | " | |
576 | test_expect_success DONTHAVEIT "prereq not satisfied" "false" | |
bdccd3c1 | 577 | |
efd2600e JK |
578 | test_set_prereq HAVETHIS |
579 | test_expect_success HAVETHIS,HAVEIT "multiple prereqs" "true" | |
580 | test_expect_success HAVEIT,DONTHAVEIT "mixed prereqs (yes,no)" "false" | |
581 | test_expect_success DONTHAVEIT,HAVEIT "mixed prereqs (no,yes)" "false" | |
bdccd3c1 | 582 | |
efd2600e JK |
583 | test_done |
584 | EOF | |
585 | ||
586 | check_sub_test_lib_test prereqs <<-\EOF | |
587 | ok 1 - prereq is satisfied | |
588 | ok 2 - have_prereq works | |
589 | ok 3 # skip prereq not satisfied (missing DONTHAVEIT) | |
590 | ok 4 - multiple prereqs | |
591 | ok 5 # skip mixed prereqs (yes,no) (missing DONTHAVEIT of HAVEIT,DONTHAVEIT) | |
592 | ok 6 # skip mixed prereqs (no,yes) (missing DONTHAVEIT of DONTHAVEIT,HAVEIT) | |
593 | # passed all 6 test(s) | |
594 | 1..6 | |
595 | EOF | |
bdccd3c1 JK |
596 | ' |
597 | ||
c3ff7be6 ÆAB |
598 | test_expect_success 'subtest: tests respect lazy prerequisites' ' |
599 | write_and_run_sub_test_lib_test lazy-prereqs <<-\EOF && | |
bdccd3c1 | 600 | |
efd2600e JK |
601 | test_lazy_prereq LAZY_TRUE true |
602 | test_expect_success LAZY_TRUE "lazy prereq is satisifed" "true" | |
603 | test_expect_success !LAZY_TRUE "negative lazy prereq" "false" | |
604 | ||
605 | test_lazy_prereq LAZY_FALSE false | |
606 | test_expect_success LAZY_FALSE "lazy prereq not satisfied" "false" | |
607 | test_expect_success !LAZY_FALSE "negative false prereq" "true" | |
608 | ||
609 | test_done | |
610 | EOF | |
611 | ||
612 | check_sub_test_lib_test lazy-prereqs <<-\EOF | |
613 | ok 1 - lazy prereq is satisifed | |
614 | ok 2 # skip negative lazy prereq (missing !LAZY_TRUE) | |
615 | ok 3 # skip lazy prereq not satisfied (missing LAZY_FALSE) | |
616 | ok 4 - negative false prereq | |
617 | # passed all 4 test(s) | |
618 | 1..4 | |
619 | EOF | |
53ff3b96 SG |
620 | ' |
621 | ||
c3ff7be6 ÆAB |
622 | test_expect_success 'subtest: nested lazy prerequisites' ' |
623 | write_and_run_sub_test_lib_test nested-lazy <<-\EOF && | |
efd2600e JK |
624 | |
625 | test_lazy_prereq NESTED_INNER " | |
626 | >inner && | |
627 | rm -f outer | |
628 | " | |
629 | test_lazy_prereq NESTED_PREREQ " | |
630 | >outer && | |
631 | test_have_prereq NESTED_INNER && | |
632 | echo can create new file in cwd >file && | |
633 | test_path_is_file outer && | |
634 | test_path_is_missing inner | |
635 | " | |
636 | test_expect_success NESTED_PREREQ "evaluate nested prereq" "true" | |
637 | ||
638 | test_done | |
639 | EOF | |
640 | ||
641 | check_sub_test_lib_test nested-lazy <<-\EOF | |
642 | ok 1 - evaluate nested prereq | |
643 | # passed all 1 test(s) | |
644 | 1..1 | |
645 | EOF | |
646 | ' | |
53ff3b96 | 647 | |
c3ff7be6 | 648 | test_expect_success 'subtest: lazy prereqs do not turn off tracing' ' |
9f0a4520 | 649 | write_and_run_sub_test_lib_test lazy-prereq-and-tracing \ |
c3ff7be6 | 650 | -v -x <<-\EOF && |
477dcadd JS |
651 | test_lazy_prereq LAZY true |
652 | ||
30291525 | 653 | test_expect_success lazy "test_have_prereq LAZY && echo trace" |
477dcadd JS |
654 | |
655 | test_done | |
656 | EOF | |
657 | ||
30291525 JK |
658 | grep "echo trace" lazy-prereq-and-tracing/err |
659 | ' | |
477dcadd | 660 | |
c3ff7be6 ÆAB |
661 | test_expect_success 'subtest: tests clean up after themselves' ' |
662 | write_and_run_sub_test_lib_test cleanup <<-\EOF && | |
080e2952 JK |
663 | clean=no |
664 | test_expect_success "do cleanup" " | |
665 | test_when_finished clean=yes | |
666 | " | |
667 | test_expect_success "cleanup happened" " | |
668 | test $clean = yes | |
669 | " | |
670 | test_done | |
671 | EOF | |
03efadb7 | 672 | |
080e2952 JK |
673 | check_sub_test_lib_test cleanup <<-\EOF |
674 | ok 1 - do cleanup | |
675 | ok 2 - cleanup happened | |
676 | # passed all 2 test(s) | |
677 | 1..2 | |
678 | EOF | |
679 | ' | |
03efadb7 | 680 | |
c3ff7be6 | 681 | test_expect_success 'subtest: tests clean up even on failures' ' |
9f0a4520 | 682 | write_and_run_sub_test_lib_test_err \ |
c3ff7be6 | 683 | failing-cleanup <<-\EOF && |
30291525 | 684 | test_expect_success "tests clean up even after a failure" " |
1b5b2b64 SL |
685 | touch clean-after-failure && |
686 | test_when_finished rm clean-after-failure && | |
687 | (exit 1) | |
30291525 JK |
688 | " |
689 | test_expect_success "failure to clean up causes the test to fail" " | |
1b5b2b64 | 690 | test_when_finished \"(exit 2)\" |
30291525 | 691 | " |
1b5b2b64 | 692 | test_done |
1b5b2b64 | 693 | EOF |
30291525 | 694 | check_sub_test_lib_test failing-cleanup <<-\EOF |
5e5c006e | 695 | > not ok 1 - tests clean up even after a failure |
1b5b2b64 SL |
696 | > # Z |
697 | > # touch clean-after-failure && | |
698 | > # test_when_finished rm clean-after-failure && | |
699 | > # (exit 1) | |
700 | > # Z | |
5e5c006e | 701 | > not ok 2 - failure to clean up causes the test to fail |
1b5b2b64 | 702 | > # Z |
30291525 | 703 | > # test_when_finished "(exit 2)" |
1b5b2b64 SL |
704 | > # Z |
705 | > # failed 2 among 2 test(s) | |
706 | > 1..2 | |
707 | EOF | |
30291525 | 708 | ' |
892e6f7e | 709 | |
c3ff7be6 | 710 | test_expect_success 'subtest: test_atexit is run' ' |
9f0a4520 | 711 | write_and_run_sub_test_lib_test_err \ |
c3ff7be6 | 712 | atexit-cleanup -i <<-\EOF && |
30291525 | 713 | test_expect_success "tests clean up even after a failure" " |
900721e1 JS |
714 | > ../../clean-atexit && |
715 | test_atexit rm ../../clean-atexit && | |
716 | > ../../also-clean-atexit && | |
717 | test_atexit rm ../../also-clean-atexit && | |
718 | > ../../dont-clean-atexit && | |
719 | (exit 1) | |
30291525 | 720 | " |
900721e1 JS |
721 | test_done |
722 | EOF | |
723 | test_path_is_file dont-clean-atexit && | |
724 | test_path_is_missing clean-atexit && | |
725 | test_path_is_missing also-clean-atexit | |
30291525 | 726 | ' |
900721e1 | 727 | |
2c02b110 | 728 | test_expect_success 'test_oid provides sane info by default' ' |
729 | test_oid zero >actual && | |
730 | grep "^00*\$" actual && | |
731 | rawsz="$(test_oid rawsz)" && | |
732 | hexsz="$(test_oid hexsz)" && | |
733 | test "$hexsz" -eq $(wc -c <actual) && | |
734 | test $(( $rawsz * 2)) -eq "$hexsz" | |
735 | ' | |
736 | ||
737 | test_expect_success 'test_oid can look up data for SHA-1' ' | |
738 | test_when_finished "test_detect_hash" && | |
739 | test_set_hash sha1 && | |
740 | test_oid zero >actual && | |
741 | grep "^00*\$" actual && | |
742 | rawsz="$(test_oid rawsz)" && | |
743 | hexsz="$(test_oid hexsz)" && | |
744 | test $(wc -c <actual) -eq 40 && | |
745 | test "$rawsz" -eq 20 && | |
746 | test "$hexsz" -eq 40 | |
747 | ' | |
748 | ||
749 | test_expect_success 'test_oid can look up data for SHA-256' ' | |
750 | test_when_finished "test_detect_hash" && | |
751 | test_set_hash sha256 && | |
752 | test_oid zero >actual && | |
753 | grep "^00*\$" actual && | |
754 | rawsz="$(test_oid rawsz)" && | |
755 | hexsz="$(test_oid hexsz)" && | |
756 | test $(wc -c <actual) -eq 64 && | |
757 | test "$rawsz" -eq 32 && | |
758 | test "$hexsz" -eq 64 | |
759 | ' | |
760 | ||
ceaa4b3a | 761 | test_expect_success 'test_oid can look up data for a specified algorithm' ' |
762 | rawsz="$(test_oid --hash=sha1 rawsz)" && | |
763 | hexsz="$(test_oid --hash=sha1 hexsz)" && | |
764 | test "$rawsz" -eq 20 && | |
765 | test "$hexsz" -eq 40 && | |
766 | rawsz="$(test_oid --hash=sha256 rawsz)" && | |
767 | hexsz="$(test_oid --hash=sha256 hexsz)" && | |
768 | test "$rawsz" -eq 32 && | |
769 | test "$hexsz" -eq 64 | |
770 | ' | |
771 | ||
43a2afee SG |
772 | test_expect_success 'test_bool_env' ' |
773 | ( | |
774 | sane_unset envvar && | |
775 | ||
776 | test_bool_env envvar true && | |
777 | ! test_bool_env envvar false && | |
778 | ||
779 | envvar= && | |
780 | export envvar && | |
781 | ! test_bool_env envvar true && | |
782 | ! test_bool_env envvar false && | |
783 | ||
784 | envvar=true && | |
785 | test_bool_env envvar true && | |
786 | test_bool_env envvar false && | |
787 | ||
788 | envvar=false && | |
789 | ! test_bool_env envvar true && | |
790 | ! test_bool_env envvar false && | |
791 | ||
792 | envvar=invalid && | |
793 | # When encountering an invalid bool value, test_bool_env | |
794 | # prints its error message to the original stderr of the | |
795 | # test script, hence the redirection of fd 7, and aborts | |
796 | # with "exit 1", hence the subshell. | |
797 | ! ( test_bool_env envvar true ) 7>err && | |
798 | grep "error: test_bool_env requires bool values" err && | |
799 | ||
800 | envvar=true && | |
801 | ! ( test_bool_env envvar invalid ) 7>err && | |
802 | grep "error: test_bool_env requires bool values" err | |
803 | ) | |
804 | ' | |
805 | ||
e1970ce4 JH |
806 | ################################################################ |
807 | # Basics of the basics | |
808 | ||
e483e144 | 809 | test_oid_cache <<\EOF |
810 | path0f sha1:f87290f8eb2cbbea7857214459a0739927eab154 | |
811 | path0f sha256:638106af7c38be056f3212cbd7ac65bc1bac74f420ca5a436ff006a9d025d17d | |
812 | ||
813 | path0s sha1:15a98433ae33114b085f3eb3bb03b832b3180a01 | |
814 | path0s sha256:3a24cc53cf68edddac490bbf94a418a52932130541361f685df685e41dd6c363 | |
815 | ||
816 | path2f sha1:3feff949ed00a62d9f7af97c15cd8a30595e7ac7 | |
817 | path2f sha256:2a7f36571c6fdbaf0e3f62751a0b25a3f4c54d2d1137b3f4af9cb794bb498e5f | |
818 | ||
819 | path2s sha1:d8ce161addc5173867a3c3c730924388daedbc38 | |
820 | path2s sha256:18fd611b787c2e938ddcc248fabe4d66a150f9364763e9ec133dd01d5bb7c65a | |
821 | ||
822 | path2d sha1:58a09c23e2ca152193f2786e06986b7b6712bdbe | |
823 | path2d sha256:00e4b32b96e7e3d65d79112dcbea53238a22715f896933a62b811377e2650c17 | |
824 | ||
825 | path3f sha1:0aa34cae68d0878578ad119c86ca2b5ed5b28376 | |
826 | path3f sha256:09f58616b951bd571b8cb9dc76d372fbb09ab99db2393f5ab3189d26c45099ad | |
827 | ||
828 | path3s sha1:8599103969b43aff7e430efea79ca4636466794f | |
829 | path3s sha256:fce1aed087c053306f3f74c32c1a838c662bbc4551a7ac2420f5d6eb061374d0 | |
830 | ||
831 | path3d sha1:21ae8269cacbe57ae09138dcc3a2887f904d02b3 | |
832 | path3d sha256:9b60497be959cb830bf3f0dc82bcc9ad9e925a24e480837ade46b2295e47efe1 | |
833 | ||
834 | subp3f sha1:00fb5908cb97c2564a9783c0c64087333b3b464f | |
835 | subp3f sha256:a1a9e16998c988453f18313d10375ee1d0ddefe757e710dcae0d66aa1e0c58b3 | |
836 | ||
837 | subp3s sha1:6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c | |
838 | subp3s sha256:81759d9f5e93c6546ecfcadb560c1ff057314b09f93fe8ec06e2d8610d34ef10 | |
839 | ||
840 | subp3d sha1:3c5e5399f3a333eddecce7a9b9465b63f65f51e2 | |
841 | subp3d sha256:76b4ef482d4fa1c754390344cf3851c7f883b27cf9bc999c6547928c46aeafb7 | |
842 | ||
843 | root sha1:087704a96baf1c2d1c869a8b084481e121c88b5b | |
844 | root sha256:9481b52abab1b2ffeedbf9de63ce422b929f179c1b98ff7bee5f8f1bc0710751 | |
845 | ||
846 | simpletree sha1:7bb943559a305bdd6bdee2cef6e5df2413c3d30a | |
847 | simpletree sha256:1710c07a6c86f9a3c7376364df04c47ee39e5a5e221fcdd84b743bc9bb7e2bc5 | |
848 | EOF | |
849 | ||
e1970ce4 | 850 | # updating a new file without --add should fail. |
1b5b2b64 SL |
851 | test_expect_success 'git update-index without --add should fail adding' ' |
852 | test_must_fail git update-index should-be-empty | |
41ac414e | 853 | ' |
e1970ce4 JH |
854 | |
855 | # and with --add it should succeed, even if it is empty (it used to fail). | |
1b5b2b64 SL |
856 | test_expect_success 'git update-index with --add should succeed' ' |
857 | git update-index --add should-be-empty | |
858 | ' | |
e1970ce4 | 859 | |
1b5b2b64 SL |
860 | test_expect_success 'writing tree out with git write-tree' ' |
861 | tree=$(git write-tree) | |
862 | ' | |
e1970ce4 JH |
863 | |
864 | # we know the shape and contents of the tree and know the object ID for it. | |
e483e144 | 865 | test_expect_success 'validate object ID of a known tree' ' |
866 | test "$tree" = "$(test_oid simpletree)" | |
1b5b2b64 | 867 | ' |
e1970ce4 JH |
868 | |
869 | # Removing paths. | |
1b5b2b64 SL |
870 | test_expect_success 'git update-index without --remove should fail removing' ' |
871 | rm -f should-be-empty full-of-directories && | |
872 | test_must_fail git update-index should-be-empty | |
41ac414e | 873 | ' |
e1970ce4 | 874 | |
1b5b2b64 SL |
875 | test_expect_success 'git update-index with --remove should be able to remove' ' |
876 | git update-index --remove should-be-empty | |
877 | ' | |
e1970ce4 JH |
878 | |
879 | # Empty tree can be written with recent write-tree. | |
1b5b2b64 SL |
880 | test_expect_success 'git write-tree should be able to write an empty tree' ' |
881 | tree=$(git write-tree) | |
882 | ' | |
e1970ce4 | 883 | |
1b5b2b64 | 884 | test_expect_success 'validate object ID of a known tree' ' |
f9e7d9f8 | 885 | test "$tree" = $EMPTY_TREE |
1b5b2b64 | 886 | ' |
e1970ce4 JH |
887 | |
888 | # Various types of objects | |
1b5b2b64 | 889 | |
1b5b2b64 SL |
890 | test_expect_success 'adding various types of objects with git update-index --add' ' |
891 | mkdir path2 path3 path3/subp3 && | |
892 | paths="path0 path2/file2 path3/file3 path3/subp3/file3" && | |
893 | ( | |
894 | for p in $paths | |
895 | do | |
896 | echo "hello $p" >$p || exit 1 | |
c723a76d | 897 | test_ln_s_add "hello $p" ${p}sym || exit 1 |
1b5b2b64 SL |
898 | done |
899 | ) && | |
900 | find path* ! -type d -print | xargs git update-index --add | |
901 | ' | |
e1970ce4 JH |
902 | |
903 | # Show them and see that matches what we expect. | |
1b5b2b64 SL |
904 | test_expect_success 'showing stage with git ls-files --stage' ' |
905 | git ls-files --stage >current | |
906 | ' | |
907 | ||
e483e144 | 908 | test_expect_success 'validate git ls-files output for a known tree' ' |
909 | cat >expected <<-EOF && | |
910 | 100644 $(test_oid path0f) 0 path0 | |
911 | 120000 $(test_oid path0s) 0 path0sym | |
912 | 100644 $(test_oid path2f) 0 path2/file2 | |
913 | 120000 $(test_oid path2s) 0 path2/file2sym | |
914 | 100644 $(test_oid path3f) 0 path3/file3 | |
915 | 120000 $(test_oid path3s) 0 path3/file3sym | |
916 | 100644 $(test_oid subp3f) 0 path3/subp3/file3 | |
917 | 120000 $(test_oid subp3s) 0 path3/subp3/file3sym | |
1b5b2b64 SL |
918 | EOF |
919 | test_cmp expected current | |
920 | ' | |
921 | ||
922 | test_expect_success 'writing tree out with git write-tree' ' | |
923 | tree=$(git write-tree) | |
924 | ' | |
925 | ||
e483e144 | 926 | test_expect_success 'validate object ID for a known tree' ' |
927 | test "$tree" = "$(test_oid root)" | |
1b5b2b64 SL |
928 | ' |
929 | ||
930 | test_expect_success 'showing tree with git ls-tree' ' | |
931 | git ls-tree $tree >current | |
932 | ' | |
933 | ||
e483e144 | 934 | test_expect_success 'git ls-tree output for a known tree' ' |
935 | cat >expected <<-EOF && | |
936 | 100644 blob $(test_oid path0f) path0 | |
937 | 120000 blob $(test_oid path0s) path0sym | |
938 | 040000 tree $(test_oid path2d) path2 | |
939 | 040000 tree $(test_oid path3d) path3 | |
1b5b2b64 SL |
940 | EOF |
941 | test_cmp expected current | |
942 | ' | |
e1970ce4 | 943 | |
246cc52f JH |
944 | # This changed in ls-tree pathspec change -- recursive does |
945 | # not show tree nodes anymore. | |
1b5b2b64 SL |
946 | test_expect_success 'showing tree with git ls-tree -r' ' |
947 | git ls-tree -r $tree >current | |
948 | ' | |
949 | ||
e483e144 | 950 | test_expect_success 'git ls-tree -r output for a known tree' ' |
951 | cat >expected <<-EOF && | |
952 | 100644 blob $(test_oid path0f) path0 | |
953 | 120000 blob $(test_oid path0s) path0sym | |
954 | 100644 blob $(test_oid path2f) path2/file2 | |
955 | 120000 blob $(test_oid path2s) path2/file2sym | |
956 | 100644 blob $(test_oid path3f) path3/file3 | |
957 | 120000 blob $(test_oid path3s) path3/file3sym | |
958 | 100644 blob $(test_oid subp3f) path3/subp3/file3 | |
959 | 120000 blob $(test_oid subp3s) path3/subp3/file3sym | |
1b5b2b64 SL |
960 | EOF |
961 | test_cmp expected current | |
962 | ' | |
e1970ce4 | 963 | |
fdeb6bf5 | 964 | # But with -r -t we can have both. |
1b5b2b64 SL |
965 | test_expect_success 'showing tree with git ls-tree -r -t' ' |
966 | git ls-tree -r -t $tree >current | |
967 | ' | |
3d12d0cf | 968 | |
e483e144 | 969 | test_expect_success 'git ls-tree -r output for a known tree' ' |
970 | cat >expected <<-EOF && | |
971 | 100644 blob $(test_oid path0f) path0 | |
972 | 120000 blob $(test_oid path0s) path0sym | |
973 | 040000 tree $(test_oid path2d) path2 | |
974 | 100644 blob $(test_oid path2f) path2/file2 | |
975 | 120000 blob $(test_oid path2s) path2/file2sym | |
976 | 040000 tree $(test_oid path3d) path3 | |
977 | 100644 blob $(test_oid path3f) path3/file3 | |
978 | 120000 blob $(test_oid path3s) path3/file3sym | |
979 | 040000 tree $(test_oid subp3d) path3/subp3 | |
980 | 100644 blob $(test_oid subp3f) path3/subp3/file3 | |
981 | 120000 blob $(test_oid subp3s) path3/subp3/file3sym | |
1b5b2b64 SL |
982 | EOF |
983 | test_cmp expected current | |
984 | ' | |
3d12d0cf | 985 | |
1b5b2b64 SL |
986 | test_expect_success 'writing partial tree out with git write-tree --prefix' ' |
987 | ptree=$(git write-tree --prefix=path3) | |
41ac414e | 988 | ' |
3d12d0cf | 989 | |
e483e144 | 990 | test_expect_success 'validate object ID for a known tree' ' |
991 | test "$ptree" = $(test_oid path3d) | |
1b5b2b64 SL |
992 | ' |
993 | ||
994 | test_expect_success 'writing partial tree out with git write-tree --prefix' ' | |
995 | ptree=$(git write-tree --prefix=path3/subp3) | |
996 | ' | |
997 | ||
e483e144 | 998 | test_expect_success 'validate object ID for a known tree' ' |
999 | test "$ptree" = $(test_oid subp3d) | |
1b5b2b64 SL |
1000 | ' |
1001 | ||
1002 | test_expect_success 'put invalid objects into the index' ' | |
1003 | rm -f .git/index && | |
cdd1e17f | 1004 | suffix=$(echo $ZERO_OID | sed -e "s/^.//") && |
1005 | cat >badobjects <<-EOF && | |
1006 | 100644 blob $(test_oid 001) dir/file1 | |
1007 | 100644 blob $(test_oid 002) dir/file2 | |
1008 | 100644 blob $(test_oid 003) dir/file3 | |
1009 | 100644 blob $(test_oid 004) dir/file4 | |
1010 | 100644 blob $(test_oid 005) dir/file5 | |
1b5b2b64 SL |
1011 | EOF |
1012 | git update-index --index-info <badobjects | |
1013 | ' | |
1014 | ||
1015 | test_expect_success 'writing this tree without --missing-ok' ' | |
1016 | test_must_fail git write-tree | |
1017 | ' | |
1018 | ||
1019 | test_expect_success 'writing this tree with --missing-ok' ' | |
1020 | git write-tree --missing-ok | |
1021 | ' | |
3d12d0cf JS |
1022 | |
1023 | ||
e1970ce4 | 1024 | ################################################################ |
1b5b2b64 | 1025 | test_expect_success 'git read-tree followed by write-tree should be idempotent' ' |
99094a7a | 1026 | rm -f .git/index && |
1b5b2b64 | 1027 | git read-tree $tree && |
ac9b5475 | 1028 | test_path_is_file .git/index && |
1b5b2b64 SL |
1029 | newtree=$(git write-tree) && |
1030 | test "$newtree" = "$tree" | |
1031 | ' | |
1032 | ||
e483e144 | 1033 | test_expect_success 'validate git diff-files output for a know cache/work tree state' ' |
1034 | cat >expected <<EOF && | |
1035 | :100644 100644 $(test_oid path0f) $ZERO_OID M path0 | |
1036 | :120000 120000 $(test_oid path0s) $ZERO_OID M path0sym | |
1037 | :100644 100644 $(test_oid path2f) $ZERO_OID M path2/file2 | |
1038 | :120000 120000 $(test_oid path2s) $ZERO_OID M path2/file2sym | |
1039 | :100644 100644 $(test_oid path3f) $ZERO_OID M path3/file3 | |
1040 | :120000 120000 $(test_oid path3s) $ZERO_OID M path3/file3sym | |
1041 | :100644 100644 $(test_oid subp3f) $ZERO_OID M path3/subp3/file3 | |
1042 | :120000 120000 $(test_oid subp3s) $ZERO_OID M path3/subp3/file3sym | |
e1970ce4 | 1043 | EOF |
1b5b2b64 | 1044 | git diff-files >current && |
dcbaa0b3 | 1045 | test_cmp expected current |
1b5b2b64 | 1046 | ' |
e1970ce4 | 1047 | |
1b5b2b64 SL |
1048 | test_expect_success 'git update-index --refresh should succeed' ' |
1049 | git update-index --refresh | |
1050 | ' | |
e1970ce4 | 1051 | |
1b5b2b64 SL |
1052 | test_expect_success 'no diff after checkout and git update-index --refresh' ' |
1053 | git diff-files >current && | |
1054 | cmp -s current /dev/null | |
1055 | ' | |
e1970ce4 | 1056 | |
9af0b8db | 1057 | ################################################################ |
e483e144 | 1058 | P=$(test_oid root) |
1b5b2b64 | 1059 | |
e483e144 | 1060 | test_expect_success 'git commit-tree records the correct tree in a commit' ' |
1b5b2b64 | 1061 | commit0=$(echo NO | git commit-tree $P) && |
66c0c44d CMAB |
1062 | git show --pretty=raw $commit0 >out && |
1063 | tree=$(sed -n -e "s/^tree //p" -e "/^author /q" out) && | |
1b5b2b64 SL |
1064 | test "z$tree" = "z$P" |
1065 | ' | |
1066 | ||
e483e144 | 1067 | test_expect_success 'git commit-tree records the correct parent in a commit' ' |
1b5b2b64 | 1068 | commit1=$(echo NO | git commit-tree $P -p $commit0) && |
66c0c44d CMAB |
1069 | git show --pretty=raw $commit1 >out && |
1070 | parent=$(sed -n -e "s/^parent //p" -e "/^author /q" out) && | |
1b5b2b64 SL |
1071 | test "z$commit0" = "z$parent" |
1072 | ' | |
1073 | ||
e483e144 | 1074 | test_expect_success 'git commit-tree omits duplicated parent in a commit' ' |
1b5b2b64 | 1075 | commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) && |
66c0c44d CMAB |
1076 | git show --pretty=raw $commit2 >out && |
1077 | cat >match.sed <<-\EOF && | |
1078 | s/^parent //p | |
1079 | /^author /q | |
1080 | EOF | |
1081 | parent=$(sed -n -f match.sed out | sort -u) && | |
1b5b2b64 | 1082 | test "z$commit0" = "z$parent" && |
66c0c44d CMAB |
1083 | git show --pretty=raw $commit2 >out && |
1084 | test_stdout_line_count = 1 sed -n -f match.sed out | |
1b5b2b64 | 1085 | ' |
9af0b8db | 1086 | |
81a361be JH |
1087 | test_expect_success 'update-index D/F conflict' ' |
1088 | mv path0 tmp && | |
1089 | mv path2 path0 && | |
1090 | mv tmp path2 && | |
1091 | git update-index --add --replace path2 path0/file2 && | |
9b6d1fc4 SM |
1092 | git ls-files path0 >tmp && |
1093 | numpath0=$(wc -l <tmp) && | |
81a361be JH |
1094 | test $numpath0 = 1 |
1095 | ' | |
1096 | ||
7fec10b7 JH |
1097 | test_expect_success 'very long name in the index handled sanely' ' |
1098 | ||
1099 | a=a && # 1 | |
1100 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16 | |
1101 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256 | |
1102 | a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096 | |
1103 | a=${a}q && | |
1104 | ||
1105 | >path4 && | |
1106 | git update-index --add path4 && | |
9b6d1fc4 | 1107 | git ls-files -s path4 >tmp && |
7fec10b7 | 1108 | ( |
9b6d1fc4 | 1109 | sed -e "s/ .*/ /" tmp | |
75651fd7 | 1110 | tr -d "\012" && |
7fec10b7 JH |
1111 | echo "$a" |
1112 | ) | git update-index --index-info && | |
9b6d1fc4 SM |
1113 | git ls-files "a*" >tmp && |
1114 | len=$(wc -c <tmp) && | |
7fec10b7 JH |
1115 | test $len = 4098 |
1116 | ' | |
1117 | ||
6a67c759 DL |
1118 | test_expect_success 'test_must_fail on a failing git command' ' |
1119 | test_must_fail git notacommand | |
1120 | ' | |
1121 | ||
1122 | test_expect_success 'test_must_fail on a failing git command with env' ' | |
1123 | test_must_fail env var1=a var2=b git notacommand | |
1124 | ' | |
1125 | ||
1126 | test_expect_success 'test_must_fail rejects a non-git command' ' | |
1127 | ! test_must_fail grep ^$ notafile 2>err && | |
1128 | grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err | |
1129 | ' | |
1130 | ||
1131 | test_expect_success 'test_must_fail rejects a non-git command with env' ' | |
1132 | ! test_must_fail env var1=a var2=b grep ^$ notafile 2>err && | |
1133 | grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err | |
1134 | ' | |
1135 | ||
e1970ce4 | 1136 | test_done |