Interested in helping open source friends on HP-UX?
[git/mjg.git] / t / t0000-basic.sh
blobf10ba4a01e7e9468b9656ee54486209151ecfd4f
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Test the very basics part #1.
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.
12 This test runs very basic features, like registering things in cache,
13 writing tree, etc.
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.
21 . ./test-lib.sh
23 ################################################################
24 # git init has been done in an empty repository.
25 # make sure it is empty.
27 test_expect_success '.git/objects should be empty after git init in an empty repo' '
28 find .git/objects -type f -print >should-be-empty &&
29 test_line_count = 0 should-be-empty
32 # also it should have 2 subdirectories; no fan-out anymore, pack, and info.
33 # 3 is counting "objects" itself
34 test_expect_success '.git/objects should have 3 subdirectories' '
35 find .git/objects -type d -print >full-of-directories &&
36 test_line_count = 3 full-of-directories
39 ################################################################
40 # Test harness
41 test_expect_success 'success is reported like this' '
45 _run_sub_test_lib_test_common () {
46 neg="$1" name="$2" descr="$3" # stdin is the body of the test code
47 shift 3
48 mkdir "$name" &&
50 # Pretend we're not running under a test harness, whether we
51 # are or not. The test-lib output depends on the setting of
52 # this variable, so we need a stable setting under which to run
53 # the sub-test.
54 sane_unset HARNESS_ACTIVE &&
55 cd "$name" &&
56 cat >"$name.sh" <<-EOF &&
57 #!$SHELL_PATH
59 test_description='$descr (run in sub test-lib)
61 This is run in a sub test-lib so that we do not get incorrect
62 passing metrics
65 # Point to the t/test-lib.sh, which isn't in ../ as usual
66 . "\$TEST_DIRECTORY"/test-lib.sh
67 EOF
68 cat >>"$name.sh" &&
69 chmod +x "$name.sh" &&
70 export TEST_DIRECTORY &&
71 TEST_OUTPUT_DIRECTORY=$(pwd) &&
72 export TEST_OUTPUT_DIRECTORY &&
73 if test -z "$neg"
74 then
75 ./"$name.sh" "$@" >out 2>err
76 else
77 ! ./"$name.sh" "$@" >out 2>err
82 run_sub_test_lib_test () {
83 _run_sub_test_lib_test_common '' "$@"
86 run_sub_test_lib_test_err () {
87 _run_sub_test_lib_test_common '!' "$@"
90 check_sub_test_lib_test () {
91 name="$1" # stdin is the expected output from the test
93 cd "$name" &&
94 ! test -s err &&
95 sed -e 's/^> //' -e 's/Z$//' >expect &&
96 test_cmp expect out
100 check_sub_test_lib_test_err () {
101 name="$1" # stdin is the expected output output from the test
102 # expected error output is in descriptior 3
104 cd "$name" &&
105 sed -e 's/^> //' -e 's/Z$//' >expect.out &&
106 test_cmp expect.out out &&
107 sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err &&
108 test_cmp expect.err err
112 test_expect_success 'pretend we have a fully passing test suite' "
113 run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF &&
114 for i in 1 2 3
116 test_expect_success \"passing test #\$i\" 'true'
117 done
118 test_done
120 check_sub_test_lib_test full-pass <<-\\EOF
121 > ok 1 - passing test #1
122 > ok 2 - passing test #2
123 > ok 3 - passing test #3
124 > # passed all 3 test(s)
125 > 1..3
129 test_expect_success 'pretend we have a partially passing test suite' "
130 test_must_fail run_sub_test_lib_test \
131 partial-pass '2/3 tests passing' <<-\\EOF &&
132 test_expect_success 'passing test #1' 'true'
133 test_expect_success 'failing test #2' 'false'
134 test_expect_success 'passing test #3' 'true'
135 test_done
137 check_sub_test_lib_test partial-pass <<-\\EOF
138 > ok 1 - passing test #1
139 > not ok 2 - failing test #2
140 # false
141 > ok 3 - passing test #3
142 > # failed 1 among 3 test(s)
143 > 1..3
147 test_expect_success 'pretend we have a known breakage' "
148 run_sub_test_lib_test failing-todo 'A failing TODO test' <<-\\EOF &&
149 test_expect_success 'passing test' 'true'
150 test_expect_failure 'pretend we have a known breakage' 'false'
151 test_done
153 check_sub_test_lib_test failing-todo <<-\\EOF
154 > ok 1 - passing test
155 > not ok 2 - pretend we have a known breakage # TODO known breakage
156 > # still have 1 known breakage(s)
157 > # passed all remaining 1 test(s)
158 > 1..2
162 test_expect_success 'pretend we have fixed a known breakage' "
163 run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF &&
164 test_expect_failure 'pretend we have fixed a known breakage' 'true'
165 test_done
167 check_sub_test_lib_test passing-todo <<-\\EOF
168 > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
169 > # 1 known breakage(s) vanished; please update test(s)
170 > 1..1
174 test_expect_success 'pretend we have fixed one of two known breakages (run in sub test-lib)' "
175 run_sub_test_lib_test partially-passing-todos \
176 '2 TODO tests, one passing' <<-\\EOF &&
177 test_expect_failure 'pretend we have a known breakage' 'false'
178 test_expect_success 'pretend we have a passing test' 'true'
179 test_expect_failure 'pretend we have fixed another known breakage' 'true'
180 test_done
182 check_sub_test_lib_test partially-passing-todos <<-\\EOF
183 > not ok 1 - pretend we have a known breakage # TODO known breakage
184 > ok 2 - pretend we have a passing test
185 > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished
186 > # 1 known breakage(s) vanished; please update test(s)
187 > # still have 1 known breakage(s)
188 > # passed all remaining 1 test(s)
189 > 1..3
193 test_expect_success 'pretend we have a pass, fail, and known breakage' "
194 test_must_fail run_sub_test_lib_test \
195 mixed-results1 'mixed results #1' <<-\\EOF &&
196 test_expect_success 'passing test' 'true'
197 test_expect_success 'failing test' 'false'
198 test_expect_failure 'pretend we have a known breakage' 'false'
199 test_done
201 check_sub_test_lib_test mixed-results1 <<-\\EOF
202 > ok 1 - passing test
203 > not ok 2 - failing test
204 > # false
205 > not ok 3 - pretend we have a known breakage # TODO known breakage
206 > # still have 1 known breakage(s)
207 > # failed 1 among remaining 2 test(s)
208 > 1..3
212 test_expect_success 'pretend we have a mix of all possible results' "
213 test_must_fail run_sub_test_lib_test \
214 mixed-results2 'mixed results #2' <<-\\EOF &&
215 test_expect_success 'passing test' 'true'
216 test_expect_success 'passing test' 'true'
217 test_expect_success 'passing test' 'true'
218 test_expect_success 'passing test' 'true'
219 test_expect_success 'failing test' 'false'
220 test_expect_success 'failing test' 'false'
221 test_expect_success 'failing test' 'false'
222 test_expect_failure 'pretend we have a known breakage' 'false'
223 test_expect_failure 'pretend we have a known breakage' 'false'
224 test_expect_failure 'pretend we have fixed a known breakage' 'true'
225 test_done
227 check_sub_test_lib_test mixed-results2 <<-\\EOF
228 > ok 1 - passing test
229 > ok 2 - passing test
230 > ok 3 - passing test
231 > ok 4 - passing test
232 > not ok 5 - failing test
233 > # false
234 > not ok 6 - failing test
235 > # false
236 > not ok 7 - failing test
237 > # false
238 > not ok 8 - pretend we have a known breakage # TODO known breakage
239 > not ok 9 - pretend we have a known breakage # TODO known breakage
240 > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
241 > # 1 known breakage(s) vanished; please update test(s)
242 > # still have 2 known breakage(s)
243 > # failed 3 among remaining 7 test(s)
244 > 1..10
248 test_expect_success 'test --verbose' '
249 test_must_fail run_sub_test_lib_test \
250 test-verbose "test verbose" --verbose <<-\EOF &&
251 test_expect_success "passing test" true
252 test_expect_success "test with output" "echo foo"
253 test_expect_success "failing test" false
254 test_done
256 mv test-verbose/out test-verbose/out+
257 grep -v "^Initialized empty" test-verbose/out+ >test-verbose/out &&
258 check_sub_test_lib_test test-verbose <<-\EOF
259 > expecting success: true
260 > ok 1 - passing test
262 > expecting success: echo foo
263 > foo
264 > ok 2 - test with output
266 > expecting success: false
267 > not ok 3 - failing test
268 > # false
270 > # failed 1 among 3 test(s)
271 > 1..3
275 test_expect_success 'test --verbose-only' '
276 test_must_fail run_sub_test_lib_test \
277 test-verbose-only-2 "test verbose-only=2" \
278 --verbose-only=2 <<-\EOF &&
279 test_expect_success "passing test" true
280 test_expect_success "test with output" "echo foo"
281 test_expect_success "failing test" false
282 test_done
284 check_sub_test_lib_test test-verbose-only-2 <<-\EOF
285 > ok 1 - passing test
287 > expecting success: echo foo
288 > foo
289 > ok 2 - test with output
291 > not ok 3 - failing test
292 > # false
293 > # failed 1 among 3 test(s)
294 > 1..3
298 test_expect_success 'GIT_SKIP_TESTS' "
300 GIT_SKIP_TESTS='git.2' && export GIT_SKIP_TESTS &&
301 run_sub_test_lib_test git-skip-tests-basic \
302 'GIT_SKIP_TESTS' <<-\\EOF &&
303 for i in 1 2 3
305 test_expect_success \"passing test #\$i\" 'true'
306 done
307 test_done
309 check_sub_test_lib_test git-skip-tests-basic <<-\\EOF
310 > ok 1 - passing test #1
311 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
312 > ok 3 - passing test #3
313 > # passed all 3 test(s)
314 > 1..3
319 test_expect_success 'GIT_SKIP_TESTS several tests' "
321 GIT_SKIP_TESTS='git.2 git.5' && export GIT_SKIP_TESTS &&
322 run_sub_test_lib_test git-skip-tests-several \
323 'GIT_SKIP_TESTS several tests' <<-\\EOF &&
324 for i in 1 2 3 4 5 6
326 test_expect_success \"passing test #\$i\" 'true'
327 done
328 test_done
330 check_sub_test_lib_test git-skip-tests-several <<-\\EOF
331 > ok 1 - passing test #1
332 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
333 > ok 3 - passing test #3
334 > ok 4 - passing test #4
335 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
336 > ok 6 - passing test #6
337 > # passed all 6 test(s)
338 > 1..6
343 test_expect_success 'GIT_SKIP_TESTS sh pattern' "
345 GIT_SKIP_TESTS='git.[2-5]' && export GIT_SKIP_TESTS &&
346 run_sub_test_lib_test git-skip-tests-sh-pattern \
347 'GIT_SKIP_TESTS sh pattern' <<-\\EOF &&
348 for i in 1 2 3 4 5 6
350 test_expect_success \"passing test #\$i\" 'true'
351 done
352 test_done
354 check_sub_test_lib_test git-skip-tests-sh-pattern <<-\\EOF
355 > ok 1 - passing test #1
356 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
357 > ok 3 # skip passing test #3 (GIT_SKIP_TESTS)
358 > ok 4 # skip passing test #4 (GIT_SKIP_TESTS)
359 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
360 > ok 6 - passing test #6
361 > # passed all 6 test(s)
362 > 1..6
367 test_expect_success '--run basic' "
368 run_sub_test_lib_test run-basic \
369 '--run basic' --run='1 3 5' <<-\\EOF &&
370 for i in 1 2 3 4 5 6
372 test_expect_success \"passing test #\$i\" 'true'
373 done
374 test_done
376 check_sub_test_lib_test run-basic <<-\\EOF
377 > ok 1 - passing test #1
378 > ok 2 # skip passing test #2 (--run)
379 > ok 3 - passing test #3
380 > ok 4 # skip passing test #4 (--run)
381 > ok 5 - passing test #5
382 > ok 6 # skip passing test #6 (--run)
383 > # passed all 6 test(s)
384 > 1..6
388 test_expect_success '--run with a range' "
389 run_sub_test_lib_test run-range \
390 '--run with a range' --run='1-3' <<-\\EOF &&
391 for i in 1 2 3 4 5 6
393 test_expect_success \"passing test #\$i\" 'true'
394 done
395 test_done
397 check_sub_test_lib_test run-range <<-\\EOF
398 > ok 1 - passing test #1
399 > ok 2 - passing test #2
400 > ok 3 - passing test #3
401 > ok 4 # skip passing test #4 (--run)
402 > ok 5 # skip passing test #5 (--run)
403 > ok 6 # skip passing test #6 (--run)
404 > # passed all 6 test(s)
405 > 1..6
409 test_expect_success '--run with two ranges' "
410 run_sub_test_lib_test run-two-ranges \
411 '--run with two ranges' --run='1-2 5-6' <<-\\EOF &&
412 for i in 1 2 3 4 5 6
414 test_expect_success \"passing test #\$i\" 'true'
415 done
416 test_done
418 check_sub_test_lib_test run-two-ranges <<-\\EOF
419 > ok 1 - passing test #1
420 > ok 2 - passing test #2
421 > ok 3 # skip passing test #3 (--run)
422 > ok 4 # skip passing test #4 (--run)
423 > ok 5 - passing test #5
424 > ok 6 - passing test #6
425 > # passed all 6 test(s)
426 > 1..6
430 test_expect_success '--run with a left open range' "
431 run_sub_test_lib_test run-left-open-range \
432 '--run with a left open range' --run='-3' <<-\\EOF &&
433 for i in 1 2 3 4 5 6
435 test_expect_success \"passing test #\$i\" 'true'
436 done
437 test_done
439 check_sub_test_lib_test run-left-open-range <<-\\EOF
440 > ok 1 - passing test #1
441 > ok 2 - passing test #2
442 > ok 3 - passing test #3
443 > ok 4 # skip passing test #4 (--run)
444 > ok 5 # skip passing test #5 (--run)
445 > ok 6 # skip passing test #6 (--run)
446 > # passed all 6 test(s)
447 > 1..6
451 test_expect_success '--run with a right open range' "
452 run_sub_test_lib_test run-right-open-range \
453 '--run with a right open range' --run='4-' <<-\\EOF &&
454 for i in 1 2 3 4 5 6
456 test_expect_success \"passing test #\$i\" 'true'
457 done
458 test_done
460 check_sub_test_lib_test run-right-open-range <<-\\EOF
461 > ok 1 # skip passing test #1 (--run)
462 > ok 2 # skip passing test #2 (--run)
463 > ok 3 # skip passing test #3 (--run)
464 > ok 4 - passing test #4
465 > ok 5 - passing test #5
466 > ok 6 - passing test #6
467 > # passed all 6 test(s)
468 > 1..6
472 test_expect_success '--run with basic negation' "
473 run_sub_test_lib_test run-basic-neg \
474 '--run with basic negation' --run='"'!3'"' <<-\\EOF &&
475 for i in 1 2 3 4 5 6
477 test_expect_success \"passing test #\$i\" 'true'
478 done
479 test_done
481 check_sub_test_lib_test run-basic-neg <<-\\EOF
482 > ok 1 - passing test #1
483 > ok 2 - passing test #2
484 > ok 3 # skip passing test #3 (--run)
485 > ok 4 - passing test #4
486 > ok 5 - passing test #5
487 > ok 6 - passing test #6
488 > # passed all 6 test(s)
489 > 1..6
493 test_expect_success '--run with two negations' "
494 run_sub_test_lib_test run-two-neg \
495 '--run with two negations' --run='"'!3 !6'"' <<-\\EOF &&
496 for i in 1 2 3 4 5 6
498 test_expect_success \"passing test #\$i\" 'true'
499 done
500 test_done
502 check_sub_test_lib_test run-two-neg <<-\\EOF
503 > ok 1 - passing test #1
504 > ok 2 - passing test #2
505 > ok 3 # skip passing test #3 (--run)
506 > ok 4 - passing test #4
507 > ok 5 - passing test #5
508 > ok 6 # skip passing test #6 (--run)
509 > # passed all 6 test(s)
510 > 1..6
514 test_expect_success '--run a range and negation' "
515 run_sub_test_lib_test run-range-and-neg \
516 '--run a range and negation' --run='"'-4 !2'"' <<-\\EOF &&
517 for i in 1 2 3 4 5 6
519 test_expect_success \"passing test #\$i\" 'true'
520 done
521 test_done
523 check_sub_test_lib_test run-range-and-neg <<-\\EOF
524 > ok 1 - passing test #1
525 > ok 2 # skip passing test #2 (--run)
526 > ok 3 - passing test #3
527 > ok 4 - passing test #4
528 > ok 5 # skip passing test #5 (--run)
529 > ok 6 # skip passing test #6 (--run)
530 > # passed all 6 test(s)
531 > 1..6
535 test_expect_success '--run range negation' "
536 run_sub_test_lib_test run-range-neg \
537 '--run range negation' --run='"'!1-3'"' <<-\\EOF &&
538 for i in 1 2 3 4 5 6
540 test_expect_success \"passing test #\$i\" 'true'
541 done
542 test_done
544 check_sub_test_lib_test run-range-neg <<-\\EOF
545 > ok 1 # skip passing test #1 (--run)
546 > ok 2 # skip passing test #2 (--run)
547 > ok 3 # skip passing test #3 (--run)
548 > ok 4 - passing test #4
549 > ok 5 - passing test #5
550 > ok 6 - passing test #6
551 > # passed all 6 test(s)
552 > 1..6
556 test_expect_success '--run include, exclude and include' "
557 run_sub_test_lib_test run-inc-neg-inc \
558 '--run include, exclude and include' \
559 --run='"'1-5 !1-3 2'"' <<-\\EOF &&
560 for i in 1 2 3 4 5 6
562 test_expect_success \"passing test #\$i\" 'true'
563 done
564 test_done
566 check_sub_test_lib_test run-inc-neg-inc <<-\\EOF
567 > ok 1 # skip passing test #1 (--run)
568 > ok 2 - passing test #2
569 > ok 3 # skip passing test #3 (--run)
570 > ok 4 - passing test #4
571 > ok 5 - passing test #5
572 > ok 6 # skip passing test #6 (--run)
573 > # passed all 6 test(s)
574 > 1..6
578 test_expect_success '--run include, exclude and include, comma separated' "
579 run_sub_test_lib_test run-inc-neg-inc-comma \
580 '--run include, exclude and include, comma separated' \
581 --run=1-5,\!1-3,2 <<-\\EOF &&
582 for i in 1 2 3 4 5 6
584 test_expect_success \"passing test #\$i\" 'true'
585 done
586 test_done
588 check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF
589 > ok 1 # skip passing test #1 (--run)
590 > ok 2 - passing test #2
591 > ok 3 # skip passing test #3 (--run)
592 > ok 4 - passing test #4
593 > ok 5 - passing test #5
594 > ok 6 # skip passing test #6 (--run)
595 > # passed all 6 test(s)
596 > 1..6
600 test_expect_success '--run exclude and include' "
601 run_sub_test_lib_test run-neg-inc \
602 '--run exclude and include' \
603 --run='"'!3- 5'"' <<-\\EOF &&
604 for i in 1 2 3 4 5 6
606 test_expect_success \"passing test #\$i\" 'true'
607 done
608 test_done
610 check_sub_test_lib_test run-neg-inc <<-\\EOF
611 > ok 1 - passing test #1
612 > ok 2 - passing test #2
613 > ok 3 # skip passing test #3 (--run)
614 > ok 4 # skip passing test #4 (--run)
615 > ok 5 - passing test #5
616 > ok 6 # skip passing test #6 (--run)
617 > # passed all 6 test(s)
618 > 1..6
622 test_expect_success '--run empty selectors' "
623 run_sub_test_lib_test run-empty-sel \
624 '--run empty selectors' \
625 --run='1,,3,,,5' <<-\\EOF &&
626 for i in 1 2 3 4 5 6
628 test_expect_success \"passing test #\$i\" 'true'
629 done
630 test_done
632 check_sub_test_lib_test run-empty-sel <<-\\EOF
633 > ok 1 - passing test #1
634 > ok 2 # skip passing test #2 (--run)
635 > ok 3 - passing test #3
636 > ok 4 # skip passing test #4 (--run)
637 > ok 5 - passing test #5
638 > ok 6 # skip passing test #6 (--run)
639 > # passed all 6 test(s)
640 > 1..6
644 test_expect_success '--run invalid range start' "
645 run_sub_test_lib_test_err run-inv-range-start \
646 '--run invalid range start' \
647 --run='a-5' <<-\\EOF &&
648 test_expect_success \"passing test #1\" 'true'
649 test_done
651 check_sub_test_lib_test_err run-inv-range-start \
652 <<-\\EOF_OUT 3<<-\\EOF_ERR
653 > FATAL: Unexpected exit with code 1
654 EOF_OUT
655 > error: --run: invalid non-numeric in range start: 'a-5'
656 EOF_ERR
659 test_expect_success '--run invalid range end' "
660 run_sub_test_lib_test_err run-inv-range-end \
661 '--run invalid range end' \
662 --run='1-z' <<-\\EOF &&
663 test_expect_success \"passing test #1\" 'true'
664 test_done
666 check_sub_test_lib_test_err run-inv-range-end \
667 <<-\\EOF_OUT 3<<-\\EOF_ERR
668 > FATAL: Unexpected exit with code 1
669 EOF_OUT
670 > error: --run: invalid non-numeric in range end: '1-z'
671 EOF_ERR
674 test_expect_success '--run invalid selector' "
675 run_sub_test_lib_test_err run-inv-selector \
676 '--run invalid selector' \
677 --run='1?' <<-\\EOF &&
678 test_expect_success \"passing test #1\" 'true'
679 test_done
681 check_sub_test_lib_test_err run-inv-selector \
682 <<-\\EOF_OUT 3<<-\\EOF_ERR
683 > FATAL: Unexpected exit with code 1
684 EOF_OUT
685 > error: --run: invalid non-numeric in test selector: '1?'
686 EOF_ERR
690 test_set_prereq HAVEIT
691 haveit=no
692 test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
693 test_have_prereq HAVEIT &&
694 haveit=yes
696 donthaveit=yes
697 test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' '
698 donthaveit=no
700 if test $haveit$donthaveit != yesyes
701 then
702 say "bug in test framework: prerequisite tags do not work reliably"
703 exit 1
706 test_set_prereq HAVETHIS
707 haveit=no
708 test_expect_success HAVETHIS,HAVEIT 'test runs if prerequisites are satisfied' '
709 test_have_prereq HAVEIT &&
710 test_have_prereq HAVETHIS &&
711 haveit=yes
713 donthaveit=yes
714 test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' '
715 donthaveit=no
717 donthaveiteither=yes
718 test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' '
719 donthaveiteither=no
721 if test $haveit$donthaveit$donthaveiteither != yesyesyes
722 then
723 say "bug in test framework: multiple prerequisite tags do not work reliably"
724 exit 1
727 test_lazy_prereq LAZY_TRUE true
728 havetrue=no
729 test_expect_success LAZY_TRUE 'test runs if lazy prereq is satisfied' '
730 havetrue=yes
732 donthavetrue=yes
733 test_expect_success !LAZY_TRUE 'missing lazy prereqs skip tests' '
734 donthavetrue=no
737 if test "$havetrue$donthavetrue" != yesyes
738 then
739 say 'bug in test framework: lazy prerequisites do not work'
740 exit 1
743 test_lazy_prereq LAZY_FALSE false
744 nothavefalse=no
745 test_expect_success !LAZY_FALSE 'negative lazy prereqs checked' '
746 nothavefalse=yes
748 havefalse=yes
749 test_expect_success LAZY_FALSE 'missing negative lazy prereqs will skip' '
750 havefalse=no
753 if test "$nothavefalse$havefalse" != yesyes
754 then
755 say 'bug in test framework: negative lazy prerequisites do not work'
756 exit 1
759 clean=no
760 test_expect_success 'tests clean up after themselves' '
761 test_when_finished clean=yes
764 if test $clean != yes
765 then
766 say "bug in test framework: basic cleanup command does not work reliably"
767 exit 1
770 test_expect_success 'tests clean up even on failures' "
771 test_must_fail run_sub_test_lib_test \
772 failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
773 test_expect_success 'tests clean up even after a failure' '
774 touch clean-after-failure &&
775 test_when_finished rm clean-after-failure &&
776 (exit 1)
778 test_expect_success 'failure to clean up causes the test to fail' '
779 test_when_finished \"(exit 2)\"
781 test_done
783 check_sub_test_lib_test failing-cleanup <<-\\EOF
784 > not ok 1 - tests clean up even after a failure
785 > # Z
786 > # touch clean-after-failure &&
787 > # test_when_finished rm clean-after-failure &&
788 > # (exit 1)
789 > # Z
790 > not ok 2 - failure to clean up causes the test to fail
791 > # Z
792 > # test_when_finished \"(exit 2)\"
793 > # Z
794 > # failed 2 among 2 test(s)
795 > 1..2
799 ################################################################
800 # Basics of the basics
802 # updating a new file without --add should fail.
803 test_expect_success 'git update-index without --add should fail adding' '
804 test_must_fail git update-index should-be-empty
807 # and with --add it should succeed, even if it is empty (it used to fail).
808 test_expect_success 'git update-index with --add should succeed' '
809 git update-index --add should-be-empty
812 test_expect_success 'writing tree out with git write-tree' '
813 tree=$(git write-tree)
816 # we know the shape and contents of the tree and know the object ID for it.
817 test_expect_success 'validate object ID of a known tree' '
818 test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a
821 # Removing paths.
822 test_expect_success 'git update-index without --remove should fail removing' '
823 rm -f should-be-empty full-of-directories &&
824 test_must_fail git update-index should-be-empty
827 test_expect_success 'git update-index with --remove should be able to remove' '
828 git update-index --remove should-be-empty
831 # Empty tree can be written with recent write-tree.
832 test_expect_success 'git write-tree should be able to write an empty tree' '
833 tree=$(git write-tree)
836 test_expect_success 'validate object ID of a known tree' '
837 test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904
840 # Various types of objects
842 test_expect_success 'adding various types of objects with git update-index --add' '
843 mkdir path2 path3 path3/subp3 &&
844 paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
846 for p in $paths
848 echo "hello $p" >$p || exit 1
849 test_ln_s_add "hello $p" ${p}sym || exit 1
850 done
851 ) &&
852 find path* ! -type d -print | xargs git update-index --add
855 # Show them and see that matches what we expect.
856 test_expect_success 'showing stage with git ls-files --stage' '
857 git ls-files --stage >current
860 test_expect_success 'validate git ls-files output for a known tree' '
861 cat >expected <<-\EOF &&
862 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
863 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
864 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
865 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
866 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
867 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
868 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
869 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
871 test_cmp expected current
874 test_expect_success 'writing tree out with git write-tree' '
875 tree=$(git write-tree)
878 test_expect_success 'validate object ID for a known tree' '
879 test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b
882 test_expect_success 'showing tree with git ls-tree' '
883 git ls-tree $tree >current
886 test_expect_success 'git ls-tree output for a known tree' '
887 cat >expected <<-\EOF &&
888 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
889 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
890 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
891 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
893 test_cmp expected current
896 # This changed in ls-tree pathspec change -- recursive does
897 # not show tree nodes anymore.
898 test_expect_success 'showing tree with git ls-tree -r' '
899 git ls-tree -r $tree >current
902 test_expect_success 'git ls-tree -r output for a known tree' '
903 cat >expected <<-\EOF &&
904 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
905 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
906 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
907 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
908 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
909 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
910 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
911 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
913 test_cmp expected current
916 # But with -r -t we can have both.
917 test_expect_success 'showing tree with git ls-tree -r -t' '
918 git ls-tree -r -t $tree >current
921 test_expect_success 'git ls-tree -r output for a known tree' '
922 cat >expected <<-\EOF &&
923 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
924 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
925 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
926 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
927 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
928 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
929 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
930 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
931 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
932 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
933 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
935 test_cmp expected current
938 test_expect_success 'writing partial tree out with git write-tree --prefix' '
939 ptree=$(git write-tree --prefix=path3)
942 test_expect_success 'validate object ID for a known tree' '
943 test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3
946 test_expect_success 'writing partial tree out with git write-tree --prefix' '
947 ptree=$(git write-tree --prefix=path3/subp3)
950 test_expect_success 'validate object ID for a known tree' '
951 test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2
954 test_expect_success 'put invalid objects into the index' '
955 rm -f .git/index &&
956 cat >badobjects <<-\EOF &&
957 100644 blob 1000000000000000000000000000000000000000 dir/file1
958 100644 blob 2000000000000000000000000000000000000000 dir/file2
959 100644 blob 3000000000000000000000000000000000000000 dir/file3
960 100644 blob 4000000000000000000000000000000000000000 dir/file4
961 100644 blob 5000000000000000000000000000000000000000 dir/file5
963 git update-index --index-info <badobjects
966 test_expect_success 'writing this tree without --missing-ok' '
967 test_must_fail git write-tree
970 test_expect_success 'writing this tree with --missing-ok' '
971 git write-tree --missing-ok
975 ################################################################
976 test_expect_success 'git read-tree followed by write-tree should be idempotent' '
977 rm -f .git/index
978 git read-tree $tree &&
979 test -f .git/index &&
980 newtree=$(git write-tree) &&
981 test "$newtree" = "$tree"
984 test_expect_success 'validate git diff-files output for a know cache/work tree state' '
985 cat >expected <<\EOF &&
986 :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
987 :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
988 :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
989 :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym
990 :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3
991 :120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym
992 :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
993 :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
995 git diff-files >current &&
996 test_cmp current expected
999 test_expect_success 'git update-index --refresh should succeed' '
1000 git update-index --refresh
1003 test_expect_success 'no diff after checkout and git update-index --refresh' '
1004 git diff-files >current &&
1005 cmp -s current /dev/null
1008 ################################################################
1009 P=087704a96baf1c2d1c869a8b084481e121c88b5b
1011 test_expect_success 'git commit-tree records the correct tree in a commit' '
1012 commit0=$(echo NO | git commit-tree $P) &&
1013 tree=$(git show --pretty=raw $commit0 |
1014 sed -n -e "s/^tree //p" -e "/^author /q") &&
1015 test "z$tree" = "z$P"
1018 test_expect_success 'git commit-tree records the correct parent in a commit' '
1019 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
1020 parent=$(git show --pretty=raw $commit1 |
1021 sed -n -e "s/^parent //p" -e "/^author /q") &&
1022 test "z$commit0" = "z$parent"
1025 test_expect_success 'git commit-tree omits duplicated parent in a commit' '
1026 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
1027 parent=$(git show --pretty=raw $commit2 |
1028 sed -n -e "s/^parent //p" -e "/^author /q" |
1029 sort -u) &&
1030 test "z$commit0" = "z$parent" &&
1031 numparent=$(git show --pretty=raw $commit2 |
1032 sed -n -e "s/^parent //p" -e "/^author /q" |
1033 wc -l) &&
1034 test $numparent = 1
1037 test_expect_success 'update-index D/F conflict' '
1038 mv path0 tmp &&
1039 mv path2 path0 &&
1040 mv tmp path2 &&
1041 git update-index --add --replace path2 path0/file2 &&
1042 numpath0=$(git ls-files path0 | wc -l) &&
1043 test $numpath0 = 1
1046 test_expect_success 'very long name in the index handled sanely' '
1048 a=a && # 1
1049 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
1050 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
1051 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
1052 a=${a}q &&
1054 >path4 &&
1055 git update-index --add path4 &&
1057 git ls-files -s path4 |
1058 sed -e "s/ .*/ /" |
1059 tr -d "\012"
1060 echo "$a"
1061 ) | git update-index --index-info &&
1062 len=$(git ls-files "a*" | wc -c) &&
1063 test $len = 4098
1066 test_done