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,
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.
24 local x
="local" y
="alsolocal" &&
28 # Check whether the shell supports the "local" keyword. "local" is not
29 # POSIX-standard, but it is very widely supported by POSIX-compliant
30 # shells, and we rely on it within Git's test framework.
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
36 test_expect_success
'verify that the running shell supports "local"' '
39 echo "local alsolocal" >expected1 &&
40 try_local_xy >actual1 &&
41 test_cmp expected1 actual1 &&
42 echo "notlocal alsonotlocal" >expected2 &&
43 echo "$x $y" >actual2 &&
44 test_cmp expected2 actual2
47 ################################################################
48 # git init has been done in an empty repository.
49 # make sure it is empty.
51 test_expect_success
'.git/objects should be empty after git init in an empty repo' '
52 find .git/objects -type f -print >should-be-empty &&
53 test_line_count = 0 should-be-empty
56 # also it should have 2 subdirectories; no fan-out anymore, pack, and info.
57 # 3 is counting "objects" itself
58 test_expect_success
'.git/objects should have 3 subdirectories' '
59 find .git/objects -type d -print >full-of-directories &&
60 test_line_count = 3 full-of-directories
63 ################################################################
65 test_expect_success
'success is reported like this' '
69 _run_sub_test_lib_test_common
() {
70 neg
="$1" name
="$2" descr
="$3" # stdin is the body of the test code
74 # Pretend we're not running under a test harness, whether we
75 # are or not. The test-lib output depends on the setting of
76 # this variable, so we need a stable setting under which to run
78 sane_unset HARNESS_ACTIVE
&&
80 write_script
"$name.sh" "$TEST_SHELL_PATH" <<-EOF &&
81 test_description='$descr (run in sub test-lib)
83 This is run in a sub test-lib so that we do not get incorrect
87 # Tell the framework that we are self-testing to make sure
88 # it yields a stable result.
89 GIT_TEST_FRAMEWORK_SELFTEST=t &&
91 # Point to the t/test-lib.sh, which isn't in ../ as usual
92 . "\$TEST_DIRECTORY"/test-lib.sh
95 export TEST_DIRECTORY
&&
96 TEST_OUTPUT_DIRECTORY
=$
(pwd) &&
97 export TEST_OUTPUT_DIRECTORY
&&
98 sane_unset GIT_TEST_FAIL_PREREQS
&&
101 .
/"$name.sh" "$@" >out
2>err
103 ! .
/"$name.sh" "$@" >out
2>err
108 run_sub_test_lib_test
() {
109 _run_sub_test_lib_test_common
'' "$@"
112 run_sub_test_lib_test_err
() {
113 _run_sub_test_lib_test_common
'!' "$@"
116 check_sub_test_lib_test
() {
117 name
="$1" # stdin is the expected output from the test
120 test_must_be_empty err
&&
121 sed -e 's/^> //' -e 's/Z$//' >expect
&&
126 check_sub_test_lib_test_err
() {
127 name
="$1" # stdin is the expected output from the test
128 # expected error output is in descriptor 3
131 sed -e 's/^> //' -e 's/Z$//' >expect.out
&&
132 test_cmp expect.out out
&&
133 sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err
&&
134 test_cmp expect.err err
138 test_expect_success
'pretend we have a fully passing test suite' "
139 run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF &&
142 test_expect_success \"passing test #\$i\" 'true'
146 check_sub_test_lib_test full-pass <<-\\EOF
147 > ok 1 - passing test #1
148 > ok 2 - passing test #2
149 > ok 3 - passing test #3
150 > # passed all 3 test(s)
155 test_expect_success
'pretend we have a partially passing test suite' "
156 run_sub_test_lib_test_err \
157 partial-pass '2/3 tests passing' <<-\\EOF &&
158 test_expect_success 'passing test #1' 'true'
159 test_expect_success 'failing test #2' 'false'
160 test_expect_success 'passing test #3' 'true'
163 check_sub_test_lib_test partial-pass <<-\\EOF
164 > ok 1 - passing test #1
165 > not ok 2 - failing test #2
167 > ok 3 - passing test #3
168 > # failed 1 among 3 test(s)
173 test_expect_success
'pretend we have a known breakage' "
174 run_sub_test_lib_test failing-todo 'A failing TODO test' <<-\\EOF &&
175 test_expect_success 'passing test' 'true'
176 test_expect_failure 'pretend we have a known breakage' 'false'
179 check_sub_test_lib_test failing-todo <<-\\EOF
180 > ok 1 - passing test
181 > not ok 2 - pretend we have a known breakage # TODO known breakage
182 > # still have 1 known breakage(s)
183 > # passed all remaining 1 test(s)
188 test_expect_success
'pretend we have fixed a known breakage' "
189 run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF &&
190 test_expect_failure 'pretend we have fixed a known breakage' 'true'
193 check_sub_test_lib_test passing-todo <<-\\EOF
194 > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
195 > # 1 known breakage(s) vanished; please update test(s)
200 test_expect_success
'pretend we have fixed one of two known breakages (run in sub test-lib)' "
201 run_sub_test_lib_test partially-passing-todos \
202 '2 TODO tests, one passing' <<-\\EOF &&
203 test_expect_failure 'pretend we have a known breakage' 'false'
204 test_expect_success 'pretend we have a passing test' 'true'
205 test_expect_failure 'pretend we have fixed another known breakage' 'true'
208 check_sub_test_lib_test partially-passing-todos <<-\\EOF
209 > not ok 1 - pretend we have a known breakage # TODO known breakage
210 > ok 2 - pretend we have a passing test
211 > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished
212 > # 1 known breakage(s) vanished; please update test(s)
213 > # still have 1 known breakage(s)
214 > # passed all remaining 1 test(s)
219 test_expect_success
'pretend we have a pass, fail, and known breakage' "
220 run_sub_test_lib_test_err \
221 mixed-results1 'mixed results #1' <<-\\EOF &&
222 test_expect_success 'passing test' 'true'
223 test_expect_success 'failing test' 'false'
224 test_expect_failure 'pretend we have a known breakage' 'false'
227 check_sub_test_lib_test mixed-results1 <<-\\EOF
228 > ok 1 - passing test
229 > not ok 2 - failing test
231 > not ok 3 - pretend we have a known breakage # TODO known breakage
232 > # still have 1 known breakage(s)
233 > # failed 1 among remaining 2 test(s)
238 test_expect_success
'pretend we have a mix of all possible results' "
239 run_sub_test_lib_test_err \
240 mixed-results2 'mixed results #2' <<-\\EOF &&
241 test_expect_success 'passing test' 'true'
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 'failing test' 'false'
246 test_expect_success 'failing test' 'false'
247 test_expect_success 'failing test' 'false'
248 test_expect_failure 'pretend we have a known breakage' 'false'
249 test_expect_failure 'pretend we have a known breakage' 'false'
250 test_expect_failure 'pretend we have fixed a known breakage' 'true'
253 check_sub_test_lib_test mixed-results2 <<-\\EOF
254 > ok 1 - passing test
255 > ok 2 - passing test
256 > ok 3 - passing test
257 > ok 4 - passing test
258 > not ok 5 - failing test
260 > not ok 6 - failing test
262 > not ok 7 - failing test
264 > not ok 8 - pretend we have a known breakage # TODO known breakage
265 > not ok 9 - pretend we have a known breakage # TODO known breakage
266 > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
267 > # 1 known breakage(s) vanished; please update test(s)
268 > # still have 2 known breakage(s)
269 > # failed 3 among remaining 7 test(s)
274 test_expect_success C_LOCALE_OUTPUT
'test --verbose' '
275 run_sub_test_lib_test_err \
276 t1234-verbose "test verbose" --verbose <<-\EOF &&
277 test_expect_success "passing test" true
278 test_expect_success "test with output" "echo foo"
279 test_expect_success "failing test" false
282 mv t1234-verbose/out t1234-verbose/out+ &&
283 grep -v "^Initialized empty" t1234-verbose/out+ >t1234-verbose/out &&
284 check_sub_test_lib_test t1234-verbose <<-\EOF
285 > expecting success of 1234.1 '\''passing test'\'': true
286 > ok 1 - passing test
288 > expecting success of 1234.2 '\''test with output'\'': echo foo
290 > ok 2 - test with output
292 > expecting success of 1234.3 '\''failing test'\'': false
293 > not ok 3 - failing test
296 > # failed 1 among 3 test(s)
301 test_expect_success
'test --verbose-only' '
302 run_sub_test_lib_test_err \
303 t2345-verbose-only-2 "test verbose-only=2" \
304 --verbose-only=2 <<-\EOF &&
305 test_expect_success "passing test" true
306 test_expect_success "test with output" "echo foo"
307 test_expect_success "failing test" false
310 check_sub_test_lib_test t2345-verbose-only-2 <<-\EOF
311 > ok 1 - passing test
313 > expecting success of 2345.2 '\''test with output'\'': echo foo
315 > ok 2 - test with output
317 > not ok 3 - failing test
319 > # failed 1 among 3 test(s)
324 test_expect_success
'GIT_SKIP_TESTS' "
326 GIT_SKIP_TESTS='git.2' && export GIT_SKIP_TESTS &&
327 run_sub_test_lib_test git-skip-tests-basic \
328 'GIT_SKIP_TESTS' <<-\\EOF &&
331 test_expect_success \"passing test #\$i\" 'true'
335 check_sub_test_lib_test git-skip-tests-basic <<-\\EOF
336 > ok 1 - passing test #1
337 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
338 > ok 3 - passing test #3
339 > # passed all 3 test(s)
345 test_expect_success
'GIT_SKIP_TESTS several tests' "
347 GIT_SKIP_TESTS='git.2 git.5' && export GIT_SKIP_TESTS &&
348 run_sub_test_lib_test git-skip-tests-several \
349 'GIT_SKIP_TESTS several tests' <<-\\EOF &&
352 test_expect_success \"passing test #\$i\" 'true'
356 check_sub_test_lib_test git-skip-tests-several <<-\\EOF
357 > ok 1 - passing test #1
358 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
359 > ok 3 - passing test #3
360 > ok 4 - passing test #4
361 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
362 > ok 6 - passing test #6
363 > # passed all 6 test(s)
369 test_expect_success
'GIT_SKIP_TESTS sh pattern' "
371 GIT_SKIP_TESTS='git.[2-5]' && export GIT_SKIP_TESTS &&
372 run_sub_test_lib_test git-skip-tests-sh-pattern \
373 'GIT_SKIP_TESTS sh pattern' <<-\\EOF &&
376 test_expect_success \"passing test #\$i\" 'true'
380 check_sub_test_lib_test git-skip-tests-sh-pattern <<-\\EOF
381 > ok 1 - passing test #1
382 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
383 > ok 3 # skip passing test #3 (GIT_SKIP_TESTS)
384 > ok 4 # skip passing test #4 (GIT_SKIP_TESTS)
385 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
386 > ok 6 - passing test #6
387 > # passed all 6 test(s)
393 test_expect_success
'GIT_SKIP_TESTS entire suite' "
395 GIT_SKIP_TESTS='git' && export GIT_SKIP_TESTS &&
396 run_sub_test_lib_test git-skip-tests-entire-suite \
397 'GIT_SKIP_TESTS entire suite' <<-\\EOF &&
400 test_expect_success \"passing test #\$i\" 'true'
404 check_sub_test_lib_test git-skip-tests-entire-suite <<-\\EOF
405 > 1..0 # SKIP skip all tests in git
410 test_expect_success
'GIT_SKIP_TESTS does not skip unmatched suite' "
412 GIT_SKIP_TESTS='notgit' && export GIT_SKIP_TESTS &&
413 run_sub_test_lib_test git-skip-tests-unmatched-suite \
414 'GIT_SKIP_TESTS does not skip unmatched suite' <<-\\EOF &&
417 test_expect_success \"passing test #\$i\" 'true'
421 check_sub_test_lib_test git-skip-tests-unmatched-suite <<-\\EOF
422 > ok 1 - passing test #1
423 > ok 2 - passing test #2
424 > ok 3 - passing test #3
425 > # passed all 3 test(s)
431 test_expect_success
'--run basic' "
432 run_sub_test_lib_test run-basic \
433 '--run basic' --run='1,3,5' <<-\\EOF &&
436 test_expect_success \"passing test #\$i\" 'true'
440 check_sub_test_lib_test run-basic <<-\\EOF
441 > ok 1 - passing test #1
442 > ok 2 # skip passing test #2 (--run)
443 > ok 3 - passing test #3
444 > ok 4 # skip passing test #4 (--run)
445 > ok 5 - passing test #5
446 > ok 6 # skip passing test #6 (--run)
447 > # passed all 6 test(s)
452 test_expect_success
'--run with a range' "
453 run_sub_test_lib_test run-range \
454 '--run with a range' --run='1-3' <<-\\EOF &&
457 test_expect_success \"passing test #\$i\" 'true'
461 check_sub_test_lib_test run-range <<-\\EOF
462 > ok 1 - passing test #1
463 > ok 2 - passing test #2
464 > ok 3 - passing test #3
465 > ok 4 # skip passing test #4 (--run)
466 > ok 5 # skip passing test #5 (--run)
467 > ok 6 # skip passing test #6 (--run)
468 > # passed all 6 test(s)
473 test_expect_success
'--run with two ranges' "
474 run_sub_test_lib_test run-two-ranges \
475 '--run with two ranges' --run='1-2,5-6' <<-\\EOF &&
478 test_expect_success \"passing test #\$i\" 'true'
482 check_sub_test_lib_test run-two-ranges <<-\\EOF
483 > ok 1 - passing test #1
484 > ok 2 - passing test #2
485 > ok 3 # skip passing test #3 (--run)
486 > ok 4 # skip passing test #4 (--run)
487 > ok 5 - passing test #5
488 > ok 6 - passing test #6
489 > # passed all 6 test(s)
494 test_expect_success
'--run with a left open range' "
495 run_sub_test_lib_test run-left-open-range \
496 '--run with a left open range' --run='-3' <<-\\EOF &&
499 test_expect_success \"passing test #\$i\" 'true'
503 check_sub_test_lib_test run-left-open-range <<-\\EOF
504 > ok 1 - passing test #1
505 > ok 2 - passing test #2
506 > ok 3 - passing test #3
507 > ok 4 # skip passing test #4 (--run)
508 > ok 5 # skip passing test #5 (--run)
509 > ok 6 # skip passing test #6 (--run)
510 > # passed all 6 test(s)
515 test_expect_success
'--run with a right open range' "
516 run_sub_test_lib_test run-right-open-range \
517 '--run with a right open range' --run='4-' <<-\\EOF &&
520 test_expect_success \"passing test #\$i\" 'true'
524 check_sub_test_lib_test run-right-open-range <<-\\EOF
525 > ok 1 # skip passing test #1 (--run)
526 > ok 2 # skip passing test #2 (--run)
527 > ok 3 # skip passing test #3 (--run)
528 > ok 4 - passing test #4
529 > ok 5 - passing test #5
530 > ok 6 - passing test #6
531 > # passed all 6 test(s)
536 test_expect_success
'--run with basic negation' "
537 run_sub_test_lib_test run-basic-neg \
538 '--run with basic negation' --run='"'!3'"' <<-\\EOF &&
541 test_expect_success \"passing test #\$i\" 'true'
545 check_sub_test_lib_test run-basic-neg <<-\\EOF
546 > ok 1 - passing test #1
547 > ok 2 - passing test #2
548 > ok 3 # skip passing test #3 (--run)
549 > ok 4 - passing test #4
550 > ok 5 - passing test #5
551 > ok 6 - passing test #6
552 > # passed all 6 test(s)
557 test_expect_success
'--run with two negations' "
558 run_sub_test_lib_test run-two-neg \
559 '--run with two negations' --run='"'!3,!6'"' <<-\\EOF &&
562 test_expect_success \"passing test #\$i\" 'true'
566 check_sub_test_lib_test run-two-neg <<-\\EOF
567 > ok 1 - passing test #1
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)
578 test_expect_success
'--run a range and negation' "
579 run_sub_test_lib_test run-range-and-neg \
580 '--run a range and negation' --run='"'-4,!2'"' <<-\\EOF &&
583 test_expect_success \"passing test #\$i\" 'true'
587 check_sub_test_lib_test run-range-and-neg <<-\\EOF
588 > ok 1 - passing test #1
589 > ok 2 # skip passing test #2 (--run)
590 > ok 3 - passing test #3
591 > ok 4 - passing test #4
592 > ok 5 # skip passing test #5 (--run)
593 > ok 6 # skip passing test #6 (--run)
594 > # passed all 6 test(s)
599 test_expect_success
'--run range negation' "
600 run_sub_test_lib_test run-range-neg \
601 '--run range negation' --run='"'!1-3'"' <<-\\EOF &&
604 test_expect_success \"passing test #\$i\" 'true'
608 check_sub_test_lib_test run-range-neg <<-\\EOF
609 > ok 1 # skip passing test #1 (--run)
610 > ok 2 # skip passing test #2 (--run)
611 > ok 3 # skip passing test #3 (--run)
612 > ok 4 - passing test #4
613 > ok 5 - passing test #5
614 > ok 6 - passing test #6
615 > # passed all 6 test(s)
620 test_expect_success
'--run include, exclude and include' "
621 run_sub_test_lib_test run-inc-neg-inc \
622 '--run include, exclude and include' \
623 --run='"'1-5,!1-3,2'"' <<-\\EOF &&
626 test_expect_success \"passing test #\$i\" 'true'
630 check_sub_test_lib_test run-inc-neg-inc <<-\\EOF
631 > ok 1 # skip passing test #1 (--run)
632 > ok 2 - passing test #2
633 > ok 3 # skip passing test #3 (--run)
634 > ok 4 - passing test #4
635 > ok 5 - passing test #5
636 > ok 6 # skip passing test #6 (--run)
637 > # passed all 6 test(s)
642 test_expect_success
'--run include, exclude and include, comma separated' "
643 run_sub_test_lib_test run-inc-neg-inc-comma \
644 '--run include, exclude and include, comma separated' \
645 --run=1-5,\!1-3,2 <<-\\EOF &&
648 test_expect_success \"passing test #\$i\" 'true'
652 check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF
653 > ok 1 # skip passing test #1 (--run)
654 > ok 2 - passing test #2
655 > ok 3 # skip passing test #3 (--run)
656 > ok 4 - passing test #4
657 > ok 5 - passing test #5
658 > ok 6 # skip passing test #6 (--run)
659 > # passed all 6 test(s)
664 test_expect_success
'--run exclude and include' "
665 run_sub_test_lib_test run-neg-inc \
666 '--run exclude and include' \
667 --run='"'!3-,5'"' <<-\\EOF &&
670 test_expect_success \"passing test #\$i\" 'true'
674 check_sub_test_lib_test run-neg-inc <<-\\EOF
675 > ok 1 - passing test #1
676 > ok 2 - passing test #2
677 > ok 3 # skip passing test #3 (--run)
678 > ok 4 # skip passing test #4 (--run)
679 > ok 5 - passing test #5
680 > ok 6 # skip passing test #6 (--run)
681 > # passed all 6 test(s)
686 test_expect_success
'--run empty selectors' "
687 run_sub_test_lib_test run-empty-sel \
688 '--run empty selectors' \
689 --run='1,,3,,,5' <<-\\EOF &&
692 test_expect_success \"passing test #\$i\" 'true'
696 check_sub_test_lib_test run-empty-sel <<-\\EOF
697 > ok 1 - passing test #1
698 > ok 2 # skip passing test #2 (--run)
699 > ok 3 - passing test #3
700 > ok 4 # skip passing test #4 (--run)
701 > ok 5 - passing test #5
702 > ok 6 # skip passing test #6 (--run)
703 > # passed all 6 test(s)
708 test_expect_success
'--run substring selector' "
709 run_sub_test_lib_test run-substring-selector \
710 '--run empty selectors' \
711 --run='relevant' <<-\\EOF &&
712 test_expect_success \"relevant test\" 'true'
715 test_expect_success \"other test #\$i\" 'true'
719 check_sub_test_lib_test run-substring-selector <<-\\EOF
720 > ok 1 - relevant test
721 > ok 2 # skip other test #1 (--run)
722 > ok 3 # skip other test #2 (--run)
723 > ok 4 # skip other test #3 (--run)
724 > ok 5 # skip other test #4 (--run)
725 > ok 6 # skip other test #5 (--run)
726 > ok 7 # skip other test #6 (--run)
727 > # passed all 7 test(s)
732 test_expect_success
'--run keyword selection' "
733 run_sub_test_lib_test_err run-inv-range-start \
734 '--run invalid range start' \
735 --run='a-5' <<-\\EOF &&
736 test_expect_success \"passing test #1\" 'true'
739 check_sub_test_lib_test_err run-inv-range-start \
740 <<-\\EOF_OUT 3<<-\\EOF_ERR
741 > FATAL: Unexpected exit with code 1
743 > error: --run: invalid non-numeric in range start: 'a-5'
747 test_expect_success
'--run invalid range end' "
748 run_sub_test_lib_test_err run-inv-range-end \
749 '--run invalid range end' \
750 --run='1-z' <<-\\EOF &&
751 test_expect_success \"passing test #1\" 'true'
754 check_sub_test_lib_test_err run-inv-range-end \
755 <<-\\EOF_OUT 3<<-\\EOF_ERR
756 > FATAL: Unexpected exit with code 1
758 > error: --run: invalid non-numeric in range end: '1-z'
763 test_set_prereq HAVEIT
765 test_expect_success HAVEIT
'test runs if prerequisite is satisfied' '
766 test_have_prereq HAVEIT &&
770 test_expect_success DONTHAVEIT
'unmet prerequisite causes test to be skipped' '
773 if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $haveit$donthaveit != yesyes
775 say
"bug in test framework: prerequisite tags do not work reliably"
779 test_set_prereq HAVETHIS
781 test_expect_success HAVETHIS
,HAVEIT
'test runs if prerequisites are satisfied' '
782 test_have_prereq HAVEIT &&
783 test_have_prereq HAVETHIS &&
787 test_expect_success HAVEIT
,DONTHAVEIT
'unmet prerequisites causes test to be skipped' '
791 test_expect_success DONTHAVEIT
,HAVEIT
'unmet prerequisites causes test to be skipped' '
794 if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $haveit$donthaveit$donthaveiteither != yesyesyes
796 say
"bug in test framework: multiple prerequisite tags do not work reliably"
800 test_lazy_prereq LAZY_TRUE true
802 test_expect_success LAZY_TRUE
'test runs if lazy prereq is satisfied' '
806 test_expect_success
!LAZY_TRUE
'missing lazy prereqs skip tests' '
810 if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a "$havetrue$donthavetrue" != yesyes
812 say
'bug in test framework: lazy prerequisites do not work'
816 test_lazy_prereq LAZY_FALSE false
818 test_expect_success
!LAZY_FALSE
'negative lazy prereqs checked' '
822 test_expect_success LAZY_FALSE
'missing negative lazy prereqs will skip' '
826 if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a "$nothavefalse$havefalse" != yesyes
828 say
'bug in test framework: negative lazy prerequisites do not work'
833 test_expect_success
'tests clean up after themselves' '
834 test_when_finished clean=yes
837 if test -z "$GIT_TEST_FAIL_PREREQS_INTERNAL" -a $clean != yes
839 say
"bug in test framework: basic cleanup command does not work reliably"
843 test_expect_success
'lazy prereqs do not turn off tracing' "
844 run_sub_test_lib_test lazy-prereq-and-tracing \
845 'lazy prereqs and -x' -v -x <<-\\EOF &&
846 test_lazy_prereq LAZY true
848 test_expect_success lazy 'test_have_prereq LAZY && echo trace'
853 grep 'echo trace' lazy-prereq-and-tracing/err
856 test_expect_success
'tests clean up even on failures' "
857 run_sub_test_lib_test_err \
858 failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
859 test_expect_success 'tests clean up even after a failure' '
860 touch clean-after-failure &&
861 test_when_finished rm clean-after-failure &&
864 test_expect_success 'failure to clean up causes the test to fail' '
865 test_when_finished \"(exit 2)\"
869 check_sub_test_lib_test failing-cleanup <<-\\EOF
870 > not ok 1 - tests clean up even after a failure
872 > # touch clean-after-failure &&
873 > # test_when_finished rm clean-after-failure &&
876 > not ok 2 - failure to clean up causes the test to fail
878 > # test_when_finished \"(exit 2)\"
880 > # failed 2 among 2 test(s)
885 test_expect_success
'test_atexit is run' "
886 run_sub_test_lib_test_err \
887 atexit-cleanup 'Run atexit commands' -i <<-\\EOF &&
888 test_expect_success 'tests clean up even after a failure' '
889 > ../../clean-atexit &&
890 test_atexit rm ../../clean-atexit &&
891 > ../../also-clean-atexit &&
892 test_atexit rm ../../also-clean-atexit &&
893 > ../../dont-clean-atexit &&
898 test_path_is_file dont-clean-atexit &&
899 test_path_is_missing clean-atexit &&
900 test_path_is_missing also-clean-atexit
903 test_expect_success
'test_oid provides sane info by default' '
904 test_oid zero >actual &&
905 grep "^00*\$" actual &&
906 rawsz="$(test_oid rawsz)" &&
907 hexsz="$(test_oid hexsz)" &&
908 test "$hexsz" -eq $(wc -c <actual) &&
909 test $(( $rawsz * 2)) -eq "$hexsz"
912 test_expect_success
'test_oid can look up data for SHA-1' '
913 test_when_finished "test_detect_hash" &&
914 test_set_hash sha1 &&
915 test_oid zero >actual &&
916 grep "^00*\$" actual &&
917 rawsz="$(test_oid rawsz)" &&
918 hexsz="$(test_oid hexsz)" &&
919 test $(wc -c <actual) -eq 40 &&
920 test "$rawsz" -eq 20 &&
924 test_expect_success
'test_oid can look up data for SHA-256' '
925 test_when_finished "test_detect_hash" &&
926 test_set_hash sha256 &&
927 test_oid zero >actual &&
928 grep "^00*\$" actual &&
929 rawsz="$(test_oid rawsz)" &&
930 hexsz="$(test_oid hexsz)" &&
931 test $(wc -c <actual) -eq 64 &&
932 test "$rawsz" -eq 32 &&
936 test_expect_success
'test_oid can look up data for a specified algorithm' '
937 rawsz="$(test_oid --hash=sha1 rawsz)" &&
938 hexsz="$(test_oid --hash=sha1 hexsz)" &&
939 test "$rawsz" -eq 20 &&
940 test "$hexsz" -eq 40 &&
941 rawsz="$(test_oid --hash=sha256 rawsz)" &&
942 hexsz="$(test_oid --hash=sha256 hexsz)" &&
943 test "$rawsz" -eq 32 &&
947 test_expect_success
'test_bool_env' '
951 test_bool_env envvar true &&
952 ! test_bool_env envvar false &&
956 ! test_bool_env envvar true &&
957 ! test_bool_env envvar false &&
960 test_bool_env envvar true &&
961 test_bool_env envvar false &&
964 ! test_bool_env envvar true &&
965 ! test_bool_env envvar false &&
968 # When encountering an invalid bool value, test_bool_env
969 # prints its error message to the original stderr of the
970 # test script, hence the redirection of fd 7, and aborts
971 # with "exit 1", hence the subshell.
972 ! ( test_bool_env envvar true ) 7>err &&
973 grep "error: test_bool_env requires bool values" err &&
976 ! ( test_bool_env envvar invalid ) 7>err &&
977 grep "error: test_bool_env requires bool values" err
981 ################################################################
982 # Basics of the basics
984 test_oid_cache
<<\EOF
985 path0f sha1
:f87290f8eb2cbbea7857214459a0739927eab154
986 path0f sha256
:638106af7c38be056f3212cbd7ac65bc1bac74f420ca5a436ff006a9d025d17d
988 path0s sha1
:15a98433ae33114b085f3eb3bb03b832b3180a01
989 path0s sha256
:3a24cc53cf68edddac490bbf94a418a52932130541361f685df685e41dd6c363
991 path2f sha1
:3feff949ed00a62d9f7af97c15cd8a30595e7ac7
992 path2f sha256
:2a7f36571c6fdbaf0e3f62751a0b25a3f4c54d2d1137b3f4af9cb794bb498e5f
994 path2s sha1
:d8ce161addc5173867a3c3c730924388daedbc38
995 path2s sha256
:18fd611b787c2e938ddcc248fabe4d66a150f9364763e9ec133dd01d5bb7c65a
997 path2d sha1
:58a09c23e2ca152193f2786e06986b7b6712bdbe
998 path2d sha256
:00e4b32b96e7e3d65d79112dcbea53238a22715f896933a62b811377e2650c17
1000 path3f sha1
:0aa34cae68d0878578ad119c86ca2b5ed5b28376
1001 path3f sha256
:09f58616b951bd571b8cb9dc76d372fbb09ab99db2393f5ab3189d26c45099ad
1003 path3s sha1
:8599103969b43aff7e430efea79ca4636466794f
1004 path3s sha256
:fce1aed087c053306f3f74c32c1a838c662bbc4551a7ac2420f5d6eb061374d0
1006 path3d sha1
:21ae8269cacbe57ae09138dcc3a2887f904d02b3
1007 path3d sha256
:9b60497be959cb830bf3f0dc82bcc9ad9e925a24e480837ade46b2295e47efe1
1009 subp3f sha1
:00fb5908cb97c2564a9783c0c64087333b3b464f
1010 subp3f sha256
:a1a9e16998c988453f18313d10375ee1d0ddefe757e710dcae0d66aa1e0c58b3
1012 subp3s sha1
:6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
1013 subp3s sha256
:81759d9f5e93c6546ecfcadb560c1ff057314b09f93fe8ec06e2d8610d34ef10
1015 subp3d sha1
:3c5e5399f3a333eddecce7a9b9465b63f65f51e2
1016 subp3d sha256
:76b4ef482d4fa1c754390344cf3851c7f883b27cf9bc999c6547928c46aeafb7
1018 root sha1
:087704a96baf1c2d1c869a8b084481e121c88b5b
1019 root sha256
:9481b52abab1b2ffeedbf9de63ce422b929f179c1b98ff7bee5f8f1bc0710751
1021 simpletree sha1
:7bb943559a305bdd6bdee2cef6e5df2413c3d30a
1022 simpletree sha256
:1710c07a6c86f9a3c7376364df04c47ee39e5a5e221fcdd84b743bc9bb7e2bc5
1025 # updating a new file without --add should fail.
1026 test_expect_success
'git update-index without --add should fail adding' '
1027 test_must_fail git update-index should-be-empty
1030 # and with --add it should succeed, even if it is empty (it used to fail).
1031 test_expect_success
'git update-index with --add should succeed' '
1032 git update-index --add should-be-empty
1035 test_expect_success
'writing tree out with git write-tree' '
1036 tree=$(git write-tree)
1039 # we know the shape and contents of the tree and know the object ID for it.
1040 test_expect_success
'validate object ID of a known tree' '
1041 test "$tree" = "$(test_oid simpletree)"
1045 test_expect_success
'git update-index without --remove should fail removing' '
1046 rm -f should-be-empty full-of-directories &&
1047 test_must_fail git update-index should-be-empty
1050 test_expect_success
'git update-index with --remove should be able to remove' '
1051 git update-index --remove should-be-empty
1054 # Empty tree can be written with recent write-tree.
1055 test_expect_success
'git write-tree should be able to write an empty tree' '
1056 tree=$(git write-tree)
1059 test_expect_success
'validate object ID of a known tree' '
1060 test "$tree" = $EMPTY_TREE
1063 # Various types of objects
1065 test_expect_success
'adding various types of objects with git update-index --add' '
1066 mkdir path2 path3 path3/subp3 &&
1067 paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
1071 echo "hello $p" >$p || exit 1
1072 test_ln_s_add "hello $p" ${p}sym || exit 1
1075 find path* ! -type d -print | xargs git update-index --add
1078 # Show them and see that matches what we expect.
1079 test_expect_success
'showing stage with git ls-files --stage' '
1080 git ls-files --stage >current
1083 test_expect_success
'validate git ls-files output for a known tree' '
1084 cat >expected <<-EOF &&
1085 100644 $(test_oid path0f) 0 path0
1086 120000 $(test_oid path0s) 0 path0sym
1087 100644 $(test_oid path2f) 0 path2/file2
1088 120000 $(test_oid path2s) 0 path2/file2sym
1089 100644 $(test_oid path3f) 0 path3/file3
1090 120000 $(test_oid path3s) 0 path3/file3sym
1091 100644 $(test_oid subp3f) 0 path3/subp3/file3
1092 120000 $(test_oid subp3s) 0 path3/subp3/file3sym
1094 test_cmp expected current
1097 test_expect_success
'writing tree out with git write-tree' '
1098 tree=$(git write-tree)
1101 test_expect_success
'validate object ID for a known tree' '
1102 test "$tree" = "$(test_oid root)"
1105 test_expect_success
'showing tree with git ls-tree' '
1106 git ls-tree $tree >current
1109 test_expect_success
'git ls-tree output for a known tree' '
1110 cat >expected <<-EOF &&
1111 100644 blob $(test_oid path0f) path0
1112 120000 blob $(test_oid path0s) path0sym
1113 040000 tree $(test_oid path2d) path2
1114 040000 tree $(test_oid path3d) path3
1116 test_cmp expected current
1119 # This changed in ls-tree pathspec change -- recursive does
1120 # not show tree nodes anymore.
1121 test_expect_success
'showing tree with git ls-tree -r' '
1122 git ls-tree -r $tree >current
1125 test_expect_success
'git ls-tree -r output for a known tree' '
1126 cat >expected <<-EOF &&
1127 100644 blob $(test_oid path0f) path0
1128 120000 blob $(test_oid path0s) path0sym
1129 100644 blob $(test_oid path2f) path2/file2
1130 120000 blob $(test_oid path2s) path2/file2sym
1131 100644 blob $(test_oid path3f) path3/file3
1132 120000 blob $(test_oid path3s) path3/file3sym
1133 100644 blob $(test_oid subp3f) path3/subp3/file3
1134 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1136 test_cmp expected current
1139 # But with -r -t we can have both.
1140 test_expect_success
'showing tree with git ls-tree -r -t' '
1141 git ls-tree -r -t $tree >current
1144 test_expect_success
'git ls-tree -r output for a known tree' '
1145 cat >expected <<-EOF &&
1146 100644 blob $(test_oid path0f) path0
1147 120000 blob $(test_oid path0s) path0sym
1148 040000 tree $(test_oid path2d) path2
1149 100644 blob $(test_oid path2f) path2/file2
1150 120000 blob $(test_oid path2s) path2/file2sym
1151 040000 tree $(test_oid path3d) path3
1152 100644 blob $(test_oid path3f) path3/file3
1153 120000 blob $(test_oid path3s) path3/file3sym
1154 040000 tree $(test_oid subp3d) path3/subp3
1155 100644 blob $(test_oid subp3f) path3/subp3/file3
1156 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1158 test_cmp expected current
1161 test_expect_success
'writing partial tree out with git write-tree --prefix' '
1162 ptree=$(git write-tree --prefix=path3)
1165 test_expect_success
'validate object ID for a known tree' '
1166 test "$ptree" = $(test_oid path3d)
1169 test_expect_success
'writing partial tree out with git write-tree --prefix' '
1170 ptree=$(git write-tree --prefix=path3/subp3)
1173 test_expect_success
'validate object ID for a known tree' '
1174 test "$ptree" = $(test_oid subp3d)
1177 test_expect_success
'put invalid objects into the index' '
1179 suffix=$(echo $ZERO_OID | sed -e "s/^.//") &&
1180 cat >badobjects <<-EOF &&
1181 100644 blob $(test_oid 001) dir/file1
1182 100644 blob $(test_oid 002) dir/file2
1183 100644 blob $(test_oid 003) dir/file3
1184 100644 blob $(test_oid 004) dir/file4
1185 100644 blob $(test_oid 005) dir/file5
1187 git update-index --index-info <badobjects
1190 test_expect_success
'writing this tree without --missing-ok' '
1191 test_must_fail git write-tree
1194 test_expect_success
'writing this tree with --missing-ok' '
1195 git write-tree --missing-ok
1199 ################################################################
1200 test_expect_success
'git read-tree followed by write-tree should be idempotent' '
1202 git read-tree $tree &&
1203 test_path_is_file .git/index &&
1204 newtree=$(git write-tree) &&
1205 test "$newtree" = "$tree"
1208 test_expect_success
'validate git diff-files output for a know cache/work tree state' '
1209 cat >expected <<EOF &&
1210 :100644 100644 $(test_oid path0f) $ZERO_OID M path0
1211 :120000 120000 $(test_oid path0s) $ZERO_OID M path0sym
1212 :100644 100644 $(test_oid path2f) $ZERO_OID M path2/file2
1213 :120000 120000 $(test_oid path2s) $ZERO_OID M path2/file2sym
1214 :100644 100644 $(test_oid path3f) $ZERO_OID M path3/file3
1215 :120000 120000 $(test_oid path3s) $ZERO_OID M path3/file3sym
1216 :100644 100644 $(test_oid subp3f) $ZERO_OID M path3/subp3/file3
1217 :120000 120000 $(test_oid subp3s) $ZERO_OID M path3/subp3/file3sym
1219 git diff-files >current &&
1220 test_cmp expected current
1223 test_expect_success
'git update-index --refresh should succeed' '
1224 git update-index --refresh
1227 test_expect_success
'no diff after checkout and git update-index --refresh' '
1228 git diff-files >current &&
1229 cmp -s current /dev/null
1232 ################################################################
1235 test_expect_success
'git commit-tree records the correct tree in a commit' '
1236 commit0=$(echo NO | git commit-tree $P) &&
1237 tree=$(git show --pretty=raw $commit0 |
1238 sed -n -e "s/^tree //p" -e "/^author /q") &&
1239 test "z$tree" = "z$P"
1242 test_expect_success
'git commit-tree records the correct parent in a commit' '
1243 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
1244 parent=$(git show --pretty=raw $commit1 |
1245 sed -n -e "s/^parent //p" -e "/^author /q") &&
1246 test "z$commit0" = "z$parent"
1249 test_expect_success
'git commit-tree omits duplicated parent in a commit' '
1250 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
1251 parent=$(git show --pretty=raw $commit2 |
1252 sed -n -e "s/^parent //p" -e "/^author /q" |
1254 test "z$commit0" = "z$parent" &&
1255 numparent=$(git show --pretty=raw $commit2 |
1256 sed -n -e "s/^parent //p" -e "/^author /q" |
1261 test_expect_success
'update-index D/F conflict' '
1265 git update-index --add --replace path2 path0/file2 &&
1266 numpath0=$(git ls-files path0 | wc -l) &&
1270 test_expect_success
'very long name in the index handled sanely' '
1273 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
1274 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
1275 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
1279 git update-index --add path4 &&
1281 git ls-files -s path4 |
1285 ) | git update-index --index-info &&
1286 len=$(git ls-files "a*" | wc -c) &&
1290 test_expect_success
'test_must_fail on a failing git command' '
1291 test_must_fail git notacommand
1294 test_expect_success
'test_must_fail on a failing git command with env' '
1295 test_must_fail env var1=a var2=b git notacommand
1298 test_expect_success
'test_must_fail rejects a non-git command' '
1299 ! test_must_fail grep ^$ notafile 2>err &&
1300 grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
1303 test_expect_success
'test_must_fail rejects a non-git command with env' '
1304 ! test_must_fail env var1=a var2=b grep ^$ notafile 2>err &&
1305 grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err