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