t/t0000-basic: make sure subtests also use TEST_SHELL_PATH
[git.git] / t / t0000-basic.sh
bloba221f9faf518179fd7f70f7ed1927b0506aee42b
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 try_local_x () {
24 local x="local" &&
25 echo "$x"
28 # This test is an experiment to check whether any Git users are using
29 # Shells that don't support the "local" keyword. "local" is not
30 # POSIX-standard, but it is very widely supported by POSIX-compliant
31 # shells, and if it doesn't cause problems for people, we would like
32 # to be able to use it in Git code.
34 # For now, this is the only test that requires "local". If your shell
35 # fails this test, you can ignore the failure, but please report the
36 # problem to the Git mailing list <git@vger.kernel.org>, as it might
37 # convince us to continue avoiding the use of "local".
38 test_expect_success 'verify that the running shell supports "local"' '
39 x="notlocal" &&
40 echo "local" >expected1 &&
41 try_local_x >actual1 &&
42 test_cmp expected1 actual1 &&
43 echo "notlocal" >expected2 &&
44 echo "$x" >actual2 &&
45 test_cmp expected2 actual2
48 ################################################################
49 # git init has been done in an empty repository.
50 # make sure it is empty.
52 test_expect_success '.git/objects should be empty after git init in an empty repo' '
53 find .git/objects -type f -print >should-be-empty &&
54 test_line_count = 0 should-be-empty
57 # also it should have 2 subdirectories; no fan-out anymore, pack, and info.
58 # 3 is counting "objects" itself
59 test_expect_success '.git/objects should have 3 subdirectories' '
60 find .git/objects -type d -print >full-of-directories &&
61 test_line_count = 3 full-of-directories
64 ################################################################
65 # Test harness
66 test_expect_success 'success is reported like this' '
70 _run_sub_test_lib_test_common () {
71 neg="$1" name="$2" descr="$3" # stdin is the body of the test code
72 shift 3
73 mkdir "$name" &&
75 # Pretend we're not running under a test harness, whether we
76 # are or not. The test-lib output depends on the setting of
77 # this variable, so we need a stable setting under which to run
78 # the sub-test.
79 sane_unset HARNESS_ACTIVE &&
80 cd "$name" &&
81 write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF &&
82 test_description='$descr (run in sub test-lib)
84 This is run in a sub test-lib so that we do not get incorrect
85 passing metrics
88 # Tell the framework that we are self-testing to make sure
89 # it yields a stable result.
90 GIT_TEST_FRAMEWORK_SELFTEST=t &&
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 export TEST_DIRECTORY &&
97 TEST_OUTPUT_DIRECTORY=$(pwd) &&
98 export TEST_OUTPUT_DIRECTORY &&
99 if test -z "$neg"
100 then
101 ./"$name.sh" "$@" >out 2>err
102 else
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
119 cd "$name" &&
120 test_must_be_empty err &&
121 sed -e 's/^> //' -e 's/Z$//' >expect &&
122 test_cmp expect out
126 check_sub_test_lib_test_err () {
127 name="$1" # stdin is the expected output from the test
128 # expected error output is in descriptior 3
130 cd "$name" &&
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 &&
140 for i in 1 2 3
142 test_expect_success \"passing test #\$i\" 'true'
143 done
144 test_done
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)
151 > 1..3
155 test_expect_success 'pretend we have a partially passing test suite' "
156 test_must_fail run_sub_test_lib_test \
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'
161 test_done
163 check_sub_test_lib_test partial-pass <<-\\EOF
164 > ok 1 - passing test #1
165 > not ok 2 - failing test #2
166 # false
167 > ok 3 - passing test #3
168 > # failed 1 among 3 test(s)
169 > 1..3
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'
177 test_done
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)
184 > 1..2
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'
191 test_done
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)
196 > 1..1
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'
206 test_done
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)
215 > 1..3
219 test_expect_success 'pretend we have a pass, fail, and known breakage' "
220 test_must_fail run_sub_test_lib_test \
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'
225 test_done
227 check_sub_test_lib_test mixed-results1 <<-\\EOF
228 > ok 1 - passing test
229 > not ok 2 - failing test
230 > # false
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)
234 > 1..3
238 test_expect_success 'pretend we have a mix of all possible results' "
239 test_must_fail run_sub_test_lib_test \
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'
251 test_done
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
259 > # false
260 > not ok 6 - failing test
261 > # false
262 > not ok 7 - failing test
263 > # false
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)
270 > 1..10
274 test_expect_success C_LOCALE_OUTPUT 'test --verbose' '
275 test_must_fail run_sub_test_lib_test \
276 test-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
280 test_done
282 mv test-verbose/out test-verbose/out+ &&
283 grep -v "^Initialized empty" test-verbose/out+ >test-verbose/out &&
284 check_sub_test_lib_test test-verbose <<-\EOF
285 > expecting success: true
286 > ok 1 - passing test
288 > expecting success: echo foo
289 > foo
290 > ok 2 - test with output
292 > expecting success: false
293 > not ok 3 - failing test
294 > # false
296 > # failed 1 among 3 test(s)
297 > 1..3
301 test_expect_success 'test --verbose-only' '
302 test_must_fail run_sub_test_lib_test \
303 test-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
308 test_done
310 check_sub_test_lib_test test-verbose-only-2 <<-\EOF
311 > ok 1 - passing test
313 > expecting success: echo foo
314 > foo
315 > ok 2 - test with output
317 > not ok 3 - failing test
318 > # false
319 > # failed 1 among 3 test(s)
320 > 1..3
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 &&
329 for i in 1 2 3
331 test_expect_success \"passing test #\$i\" 'true'
332 done
333 test_done
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)
340 > 1..3
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 &&
350 for i in 1 2 3 4 5 6
352 test_expect_success \"passing test #\$i\" 'true'
353 done
354 test_done
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)
364 > 1..6
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 &&
374 for i in 1 2 3 4 5 6
376 test_expect_success \"passing test #\$i\" 'true'
377 done
378 test_done
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)
388 > 1..6
393 test_expect_success '--run basic' "
394 run_sub_test_lib_test run-basic \
395 '--run basic' --run='1 3 5' <<-\\EOF &&
396 for i in 1 2 3 4 5 6
398 test_expect_success \"passing test #\$i\" 'true'
399 done
400 test_done
402 check_sub_test_lib_test run-basic <<-\\EOF
403 > ok 1 - passing test #1
404 > ok 2 # skip passing test #2 (--run)
405 > ok 3 - passing test #3
406 > ok 4 # skip passing test #4 (--run)
407 > ok 5 - passing test #5
408 > ok 6 # skip passing test #6 (--run)
409 > # passed all 6 test(s)
410 > 1..6
414 test_expect_success '--run with a range' "
415 run_sub_test_lib_test run-range \
416 '--run with a range' --run='1-3' <<-\\EOF &&
417 for i in 1 2 3 4 5 6
419 test_expect_success \"passing test #\$i\" 'true'
420 done
421 test_done
423 check_sub_test_lib_test run-range <<-\\EOF
424 > ok 1 - passing test #1
425 > ok 2 - passing test #2
426 > ok 3 - passing test #3
427 > ok 4 # skip passing test #4 (--run)
428 > ok 5 # skip passing test #5 (--run)
429 > ok 6 # skip passing test #6 (--run)
430 > # passed all 6 test(s)
431 > 1..6
435 test_expect_success '--run with two ranges' "
436 run_sub_test_lib_test run-two-ranges \
437 '--run with two ranges' --run='1-2 5-6' <<-\\EOF &&
438 for i in 1 2 3 4 5 6
440 test_expect_success \"passing test #\$i\" 'true'
441 done
442 test_done
444 check_sub_test_lib_test run-two-ranges <<-\\EOF
445 > ok 1 - passing test #1
446 > ok 2 - passing test #2
447 > ok 3 # skip passing test #3 (--run)
448 > ok 4 # skip passing test #4 (--run)
449 > ok 5 - passing test #5
450 > ok 6 - passing test #6
451 > # passed all 6 test(s)
452 > 1..6
456 test_expect_success '--run with a left open range' "
457 run_sub_test_lib_test run-left-open-range \
458 '--run with a left open range' --run='-3' <<-\\EOF &&
459 for i in 1 2 3 4 5 6
461 test_expect_success \"passing test #\$i\" 'true'
462 done
463 test_done
465 check_sub_test_lib_test run-left-open-range <<-\\EOF
466 > ok 1 - passing test #1
467 > ok 2 - passing test #2
468 > ok 3 - passing test #3
469 > ok 4 # skip passing test #4 (--run)
470 > ok 5 # skip passing test #5 (--run)
471 > ok 6 # skip passing test #6 (--run)
472 > # passed all 6 test(s)
473 > 1..6
477 test_expect_success '--run with a right open range' "
478 run_sub_test_lib_test run-right-open-range \
479 '--run with a right open range' --run='4-' <<-\\EOF &&
480 for i in 1 2 3 4 5 6
482 test_expect_success \"passing test #\$i\" 'true'
483 done
484 test_done
486 check_sub_test_lib_test run-right-open-range <<-\\EOF
487 > ok 1 # skip passing test #1 (--run)
488 > ok 2 # skip passing test #2 (--run)
489 > ok 3 # skip passing test #3 (--run)
490 > ok 4 - passing test #4
491 > ok 5 - passing test #5
492 > ok 6 - passing test #6
493 > # passed all 6 test(s)
494 > 1..6
498 test_expect_success '--run with basic negation' "
499 run_sub_test_lib_test run-basic-neg \
500 '--run with basic negation' --run='"'!3'"' <<-\\EOF &&
501 for i in 1 2 3 4 5 6
503 test_expect_success \"passing test #\$i\" 'true'
504 done
505 test_done
507 check_sub_test_lib_test run-basic-neg <<-\\EOF
508 > ok 1 - passing test #1
509 > ok 2 - passing test #2
510 > ok 3 # skip passing test #3 (--run)
511 > ok 4 - passing test #4
512 > ok 5 - passing test #5
513 > ok 6 - passing test #6
514 > # passed all 6 test(s)
515 > 1..6
519 test_expect_success '--run with two negations' "
520 run_sub_test_lib_test run-two-neg \
521 '--run with two negations' --run='"'!3 !6'"' <<-\\EOF &&
522 for i in 1 2 3 4 5 6
524 test_expect_success \"passing test #\$i\" 'true'
525 done
526 test_done
528 check_sub_test_lib_test run-two-neg <<-\\EOF
529 > ok 1 - passing test #1
530 > ok 2 - passing test #2
531 > ok 3 # skip passing test #3 (--run)
532 > ok 4 - passing test #4
533 > ok 5 - passing test #5
534 > ok 6 # skip passing test #6 (--run)
535 > # passed all 6 test(s)
536 > 1..6
540 test_expect_success '--run a range and negation' "
541 run_sub_test_lib_test run-range-and-neg \
542 '--run a range and negation' --run='"'-4 !2'"' <<-\\EOF &&
543 for i in 1 2 3 4 5 6
545 test_expect_success \"passing test #\$i\" 'true'
546 done
547 test_done
549 check_sub_test_lib_test run-range-and-neg <<-\\EOF
550 > ok 1 - passing test #1
551 > ok 2 # skip passing test #2 (--run)
552 > ok 3 - passing test #3
553 > ok 4 - passing test #4
554 > ok 5 # skip passing test #5 (--run)
555 > ok 6 # skip passing test #6 (--run)
556 > # passed all 6 test(s)
557 > 1..6
561 test_expect_success '--run range negation' "
562 run_sub_test_lib_test run-range-neg \
563 '--run range negation' --run='"'!1-3'"' <<-\\EOF &&
564 for i in 1 2 3 4 5 6
566 test_expect_success \"passing test #\$i\" 'true'
567 done
568 test_done
570 check_sub_test_lib_test run-range-neg <<-\\EOF
571 > ok 1 # skip passing test #1 (--run)
572 > ok 2 # skip passing test #2 (--run)
573 > ok 3 # skip passing test #3 (--run)
574 > ok 4 - passing test #4
575 > ok 5 - passing test #5
576 > ok 6 - passing test #6
577 > # passed all 6 test(s)
578 > 1..6
582 test_expect_success '--run include, exclude and include' "
583 run_sub_test_lib_test run-inc-neg-inc \
584 '--run include, exclude and include' \
585 --run='"'1-5 !1-3 2'"' <<-\\EOF &&
586 for i in 1 2 3 4 5 6
588 test_expect_success \"passing test #\$i\" 'true'
589 done
590 test_done
592 check_sub_test_lib_test run-inc-neg-inc <<-\\EOF
593 > ok 1 # skip passing test #1 (--run)
594 > ok 2 - passing test #2
595 > ok 3 # skip passing test #3 (--run)
596 > ok 4 - passing test #4
597 > ok 5 - passing test #5
598 > ok 6 # skip passing test #6 (--run)
599 > # passed all 6 test(s)
600 > 1..6
604 test_expect_success '--run include, exclude and include, comma separated' "
605 run_sub_test_lib_test run-inc-neg-inc-comma \
606 '--run include, exclude and include, comma separated' \
607 --run=1-5,\!1-3,2 <<-\\EOF &&
608 for i in 1 2 3 4 5 6
610 test_expect_success \"passing test #\$i\" 'true'
611 done
612 test_done
614 check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF
615 > ok 1 # skip passing test #1 (--run)
616 > ok 2 - passing test #2
617 > ok 3 # skip passing test #3 (--run)
618 > ok 4 - passing test #4
619 > ok 5 - passing test #5
620 > ok 6 # skip passing test #6 (--run)
621 > # passed all 6 test(s)
622 > 1..6
626 test_expect_success '--run exclude and include' "
627 run_sub_test_lib_test run-neg-inc \
628 '--run exclude and include' \
629 --run='"'!3- 5'"' <<-\\EOF &&
630 for i in 1 2 3 4 5 6
632 test_expect_success \"passing test #\$i\" 'true'
633 done
634 test_done
636 check_sub_test_lib_test run-neg-inc <<-\\EOF
637 > ok 1 - passing test #1
638 > ok 2 - passing test #2
639 > ok 3 # skip passing test #3 (--run)
640 > ok 4 # skip passing test #4 (--run)
641 > ok 5 - passing test #5
642 > ok 6 # skip passing test #6 (--run)
643 > # passed all 6 test(s)
644 > 1..6
648 test_expect_success '--run empty selectors' "
649 run_sub_test_lib_test run-empty-sel \
650 '--run empty selectors' \
651 --run='1,,3,,,5' <<-\\EOF &&
652 for i in 1 2 3 4 5 6
654 test_expect_success \"passing test #\$i\" 'true'
655 done
656 test_done
658 check_sub_test_lib_test run-empty-sel <<-\\EOF
659 > ok 1 - passing test #1
660 > ok 2 # skip passing test #2 (--run)
661 > ok 3 - passing test #3
662 > ok 4 # skip passing test #4 (--run)
663 > ok 5 - passing test #5
664 > ok 6 # skip passing test #6 (--run)
665 > # passed all 6 test(s)
666 > 1..6
670 test_expect_success '--run invalid range start' "
671 run_sub_test_lib_test_err run-inv-range-start \
672 '--run invalid range start' \
673 --run='a-5' <<-\\EOF &&
674 test_expect_success \"passing test #1\" 'true'
675 test_done
677 check_sub_test_lib_test_err run-inv-range-start \
678 <<-\\EOF_OUT 3<<-\\EOF_ERR
679 > FATAL: Unexpected exit with code 1
680 EOF_OUT
681 > error: --run: invalid non-numeric in range start: 'a-5'
682 EOF_ERR
685 test_expect_success '--run invalid range end' "
686 run_sub_test_lib_test_err run-inv-range-end \
687 '--run invalid range end' \
688 --run='1-z' <<-\\EOF &&
689 test_expect_success \"passing test #1\" 'true'
690 test_done
692 check_sub_test_lib_test_err run-inv-range-end \
693 <<-\\EOF_OUT 3<<-\\EOF_ERR
694 > FATAL: Unexpected exit with code 1
695 EOF_OUT
696 > error: --run: invalid non-numeric in range end: '1-z'
697 EOF_ERR
700 test_expect_success '--run invalid selector' "
701 run_sub_test_lib_test_err run-inv-selector \
702 '--run invalid selector' \
703 --run='1?' <<-\\EOF &&
704 test_expect_success \"passing test #1\" 'true'
705 test_done
707 check_sub_test_lib_test_err run-inv-selector \
708 <<-\\EOF_OUT 3<<-\\EOF_ERR
709 > FATAL: Unexpected exit with code 1
710 EOF_OUT
711 > error: --run: invalid non-numeric in test selector: '1?'
712 EOF_ERR
716 test_set_prereq HAVEIT
717 haveit=no
718 test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
719 test_have_prereq HAVEIT &&
720 haveit=yes
722 donthaveit=yes
723 test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' '
724 donthaveit=no
726 if test $haveit$donthaveit != yesyes
727 then
728 say "bug in test framework: prerequisite tags do not work reliably"
729 exit 1
732 test_set_prereq HAVETHIS
733 haveit=no
734 test_expect_success HAVETHIS,HAVEIT 'test runs if prerequisites are satisfied' '
735 test_have_prereq HAVEIT &&
736 test_have_prereq HAVETHIS &&
737 haveit=yes
739 donthaveit=yes
740 test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' '
741 donthaveit=no
743 donthaveiteither=yes
744 test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' '
745 donthaveiteither=no
747 if test $haveit$donthaveit$donthaveiteither != yesyesyes
748 then
749 say "bug in test framework: multiple prerequisite tags do not work reliably"
750 exit 1
753 test_lazy_prereq LAZY_TRUE true
754 havetrue=no
755 test_expect_success LAZY_TRUE 'test runs if lazy prereq is satisfied' '
756 havetrue=yes
758 donthavetrue=yes
759 test_expect_success !LAZY_TRUE 'missing lazy prereqs skip tests' '
760 donthavetrue=no
763 if test "$havetrue$donthavetrue" != yesyes
764 then
765 say 'bug in test framework: lazy prerequisites do not work'
766 exit 1
769 test_lazy_prereq LAZY_FALSE false
770 nothavefalse=no
771 test_expect_success !LAZY_FALSE 'negative lazy prereqs checked' '
772 nothavefalse=yes
774 havefalse=yes
775 test_expect_success LAZY_FALSE 'missing negative lazy prereqs will skip' '
776 havefalse=no
779 if test "$nothavefalse$havefalse" != yesyes
780 then
781 say 'bug in test framework: negative lazy prerequisites do not work'
782 exit 1
785 clean=no
786 test_expect_success 'tests clean up after themselves' '
787 test_when_finished clean=yes
790 if test $clean != yes
791 then
792 say "bug in test framework: basic cleanup command does not work reliably"
793 exit 1
796 test_expect_success 'tests clean up even on failures' "
797 test_must_fail run_sub_test_lib_test \
798 failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
799 test_expect_success 'tests clean up even after a failure' '
800 touch clean-after-failure &&
801 test_when_finished rm clean-after-failure &&
802 (exit 1)
804 test_expect_success 'failure to clean up causes the test to fail' '
805 test_when_finished \"(exit 2)\"
807 test_done
809 check_sub_test_lib_test failing-cleanup <<-\\EOF
810 > not ok 1 - tests clean up even after a failure
811 > # Z
812 > # touch clean-after-failure &&
813 > # test_when_finished rm clean-after-failure &&
814 > # (exit 1)
815 > # Z
816 > not ok 2 - failure to clean up causes the test to fail
817 > # Z
818 > # test_when_finished \"(exit 2)\"
819 > # Z
820 > # failed 2 among 2 test(s)
821 > 1..2
825 test_expect_success 'test_oid setup' '
826 test_oid_init
829 test_expect_success 'test_oid provides sane info by default' '
830 test_oid zero >actual &&
831 grep "^00*\$" actual &&
832 rawsz="$(test_oid rawsz)" &&
833 hexsz="$(test_oid hexsz)" &&
834 test "$hexsz" -eq $(wc -c <actual) &&
835 test $(( $rawsz * 2)) -eq "$hexsz"
838 test_expect_success 'test_oid can look up data for SHA-1' '
839 test_when_finished "test_detect_hash" &&
840 test_set_hash sha1 &&
841 test_oid zero >actual &&
842 grep "^00*\$" actual &&
843 rawsz="$(test_oid rawsz)" &&
844 hexsz="$(test_oid hexsz)" &&
845 test $(wc -c <actual) -eq 40 &&
846 test "$rawsz" -eq 20 &&
847 test "$hexsz" -eq 40
850 test_expect_success 'test_oid can look up data for SHA-256' '
851 test_when_finished "test_detect_hash" &&
852 test_set_hash sha256 &&
853 test_oid zero >actual &&
854 grep "^00*\$" actual &&
855 rawsz="$(test_oid rawsz)" &&
856 hexsz="$(test_oid hexsz)" &&
857 test $(wc -c <actual) -eq 64 &&
858 test "$rawsz" -eq 32 &&
859 test "$hexsz" -eq 64
862 ################################################################
863 # Basics of the basics
865 test_oid_cache <<\EOF
866 path0f sha1:f87290f8eb2cbbea7857214459a0739927eab154
867 path0f sha256:638106af7c38be056f3212cbd7ac65bc1bac74f420ca5a436ff006a9d025d17d
869 path0s sha1:15a98433ae33114b085f3eb3bb03b832b3180a01
870 path0s sha256:3a24cc53cf68edddac490bbf94a418a52932130541361f685df685e41dd6c363
872 path2f sha1:3feff949ed00a62d9f7af97c15cd8a30595e7ac7
873 path2f sha256:2a7f36571c6fdbaf0e3f62751a0b25a3f4c54d2d1137b3f4af9cb794bb498e5f
875 path2s sha1:d8ce161addc5173867a3c3c730924388daedbc38
876 path2s sha256:18fd611b787c2e938ddcc248fabe4d66a150f9364763e9ec133dd01d5bb7c65a
878 path2d sha1:58a09c23e2ca152193f2786e06986b7b6712bdbe
879 path2d sha256:00e4b32b96e7e3d65d79112dcbea53238a22715f896933a62b811377e2650c17
881 path3f sha1:0aa34cae68d0878578ad119c86ca2b5ed5b28376
882 path3f sha256:09f58616b951bd571b8cb9dc76d372fbb09ab99db2393f5ab3189d26c45099ad
884 path3s sha1:8599103969b43aff7e430efea79ca4636466794f
885 path3s sha256:fce1aed087c053306f3f74c32c1a838c662bbc4551a7ac2420f5d6eb061374d0
887 path3d sha1:21ae8269cacbe57ae09138dcc3a2887f904d02b3
888 path3d sha256:9b60497be959cb830bf3f0dc82bcc9ad9e925a24e480837ade46b2295e47efe1
890 subp3f sha1:00fb5908cb97c2564a9783c0c64087333b3b464f
891 subp3f sha256:a1a9e16998c988453f18313d10375ee1d0ddefe757e710dcae0d66aa1e0c58b3
893 subp3s sha1:6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
894 subp3s sha256:81759d9f5e93c6546ecfcadb560c1ff057314b09f93fe8ec06e2d8610d34ef10
896 subp3d sha1:3c5e5399f3a333eddecce7a9b9465b63f65f51e2
897 subp3d sha256:76b4ef482d4fa1c754390344cf3851c7f883b27cf9bc999c6547928c46aeafb7
899 root sha1:087704a96baf1c2d1c869a8b084481e121c88b5b
900 root sha256:9481b52abab1b2ffeedbf9de63ce422b929f179c1b98ff7bee5f8f1bc0710751
902 simpletree sha1:7bb943559a305bdd6bdee2cef6e5df2413c3d30a
903 simpletree sha256:1710c07a6c86f9a3c7376364df04c47ee39e5a5e221fcdd84b743bc9bb7e2bc5
906 # updating a new file without --add should fail.
907 test_expect_success 'git update-index without --add should fail adding' '
908 test_must_fail git update-index should-be-empty
911 # and with --add it should succeed, even if it is empty (it used to fail).
912 test_expect_success 'git update-index with --add should succeed' '
913 git update-index --add should-be-empty
916 test_expect_success 'writing tree out with git write-tree' '
917 tree=$(git write-tree)
920 # we know the shape and contents of the tree and know the object ID for it.
921 test_expect_success 'validate object ID of a known tree' '
922 test "$tree" = "$(test_oid simpletree)"
925 # Removing paths.
926 test_expect_success 'git update-index without --remove should fail removing' '
927 rm -f should-be-empty full-of-directories &&
928 test_must_fail git update-index should-be-empty
931 test_expect_success 'git update-index with --remove should be able to remove' '
932 git update-index --remove should-be-empty
935 # Empty tree can be written with recent write-tree.
936 test_expect_success 'git write-tree should be able to write an empty tree' '
937 tree=$(git write-tree)
940 test_expect_success 'validate object ID of a known tree' '
941 test "$tree" = $EMPTY_TREE
944 # Various types of objects
946 test_expect_success 'adding various types of objects with git update-index --add' '
947 mkdir path2 path3 path3/subp3 &&
948 paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
950 for p in $paths
952 echo "hello $p" >$p || exit 1
953 test_ln_s_add "hello $p" ${p}sym || exit 1
954 done
955 ) &&
956 find path* ! -type d -print | xargs git update-index --add
959 # Show them and see that matches what we expect.
960 test_expect_success 'showing stage with git ls-files --stage' '
961 git ls-files --stage >current
964 test_expect_success 'validate git ls-files output for a known tree' '
965 cat >expected <<-EOF &&
966 100644 $(test_oid path0f) 0 path0
967 120000 $(test_oid path0s) 0 path0sym
968 100644 $(test_oid path2f) 0 path2/file2
969 120000 $(test_oid path2s) 0 path2/file2sym
970 100644 $(test_oid path3f) 0 path3/file3
971 120000 $(test_oid path3s) 0 path3/file3sym
972 100644 $(test_oid subp3f) 0 path3/subp3/file3
973 120000 $(test_oid subp3s) 0 path3/subp3/file3sym
975 test_cmp expected current
978 test_expect_success 'writing tree out with git write-tree' '
979 tree=$(git write-tree)
982 test_expect_success 'validate object ID for a known tree' '
983 test "$tree" = "$(test_oid root)"
986 test_expect_success 'showing tree with git ls-tree' '
987 git ls-tree $tree >current
990 test_expect_success 'git ls-tree output for a known tree' '
991 cat >expected <<-EOF &&
992 100644 blob $(test_oid path0f) path0
993 120000 blob $(test_oid path0s) path0sym
994 040000 tree $(test_oid path2d) path2
995 040000 tree $(test_oid path3d) path3
997 test_cmp expected current
1000 # This changed in ls-tree pathspec change -- recursive does
1001 # not show tree nodes anymore.
1002 test_expect_success 'showing tree with git ls-tree -r' '
1003 git ls-tree -r $tree >current
1006 test_expect_success 'git ls-tree -r output for a known tree' '
1007 cat >expected <<-EOF &&
1008 100644 blob $(test_oid path0f) path0
1009 120000 blob $(test_oid path0s) path0sym
1010 100644 blob $(test_oid path2f) path2/file2
1011 120000 blob $(test_oid path2s) path2/file2sym
1012 100644 blob $(test_oid path3f) path3/file3
1013 120000 blob $(test_oid path3s) path3/file3sym
1014 100644 blob $(test_oid subp3f) path3/subp3/file3
1015 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1017 test_cmp expected current
1020 # But with -r -t we can have both.
1021 test_expect_success 'showing tree with git ls-tree -r -t' '
1022 git ls-tree -r -t $tree >current
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 040000 tree $(test_oid path2d) path2
1030 100644 blob $(test_oid path2f) path2/file2
1031 120000 blob $(test_oid path2s) path2/file2sym
1032 040000 tree $(test_oid path3d) path3
1033 100644 blob $(test_oid path3f) path3/file3
1034 120000 blob $(test_oid path3s) path3/file3sym
1035 040000 tree $(test_oid subp3d) path3/subp3
1036 100644 blob $(test_oid subp3f) path3/subp3/file3
1037 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1039 test_cmp expected current
1042 test_expect_success 'writing partial tree out with git write-tree --prefix' '
1043 ptree=$(git write-tree --prefix=path3)
1046 test_expect_success 'validate object ID for a known tree' '
1047 test "$ptree" = $(test_oid path3d)
1050 test_expect_success 'writing partial tree out with git write-tree --prefix' '
1051 ptree=$(git write-tree --prefix=path3/subp3)
1054 test_expect_success 'validate object ID for a known tree' '
1055 test "$ptree" = $(test_oid subp3d)
1058 test_expect_success 'put invalid objects into the index' '
1059 rm -f .git/index &&
1060 suffix=$(echo $ZERO_OID | sed -e "s/^.//") &&
1061 cat >badobjects <<-EOF &&
1062 100644 blob $(test_oid 001) dir/file1
1063 100644 blob $(test_oid 002) dir/file2
1064 100644 blob $(test_oid 003) dir/file3
1065 100644 blob $(test_oid 004) dir/file4
1066 100644 blob $(test_oid 005) dir/file5
1068 git update-index --index-info <badobjects
1071 test_expect_success 'writing this tree without --missing-ok' '
1072 test_must_fail git write-tree
1075 test_expect_success 'writing this tree with --missing-ok' '
1076 git write-tree --missing-ok
1080 ################################################################
1081 test_expect_success 'git read-tree followed by write-tree should be idempotent' '
1082 rm -f .git/index &&
1083 git read-tree $tree &&
1084 test -f .git/index &&
1085 newtree=$(git write-tree) &&
1086 test "$newtree" = "$tree"
1089 test_expect_success 'validate git diff-files output for a know cache/work tree state' '
1090 cat >expected <<EOF &&
1091 :100644 100644 $(test_oid path0f) $ZERO_OID M path0
1092 :120000 120000 $(test_oid path0s) $ZERO_OID M path0sym
1093 :100644 100644 $(test_oid path2f) $ZERO_OID M path2/file2
1094 :120000 120000 $(test_oid path2s) $ZERO_OID M path2/file2sym
1095 :100644 100644 $(test_oid path3f) $ZERO_OID M path3/file3
1096 :120000 120000 $(test_oid path3s) $ZERO_OID M path3/file3sym
1097 :100644 100644 $(test_oid subp3f) $ZERO_OID M path3/subp3/file3
1098 :120000 120000 $(test_oid subp3s) $ZERO_OID M path3/subp3/file3sym
1100 git diff-files >current &&
1101 test_cmp expected current
1104 test_expect_success 'git update-index --refresh should succeed' '
1105 git update-index --refresh
1108 test_expect_success 'no diff after checkout and git update-index --refresh' '
1109 git diff-files >current &&
1110 cmp -s current /dev/null
1113 ################################################################
1114 P=$(test_oid root)
1116 test_expect_success 'git commit-tree records the correct tree in a commit' '
1117 commit0=$(echo NO | git commit-tree $P) &&
1118 tree=$(git show --pretty=raw $commit0 |
1119 sed -n -e "s/^tree //p" -e "/^author /q") &&
1120 test "z$tree" = "z$P"
1123 test_expect_success 'git commit-tree records the correct parent in a commit' '
1124 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
1125 parent=$(git show --pretty=raw $commit1 |
1126 sed -n -e "s/^parent //p" -e "/^author /q") &&
1127 test "z$commit0" = "z$parent"
1130 test_expect_success 'git commit-tree omits duplicated parent in a commit' '
1131 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
1132 parent=$(git show --pretty=raw $commit2 |
1133 sed -n -e "s/^parent //p" -e "/^author /q" |
1134 sort -u) &&
1135 test "z$commit0" = "z$parent" &&
1136 numparent=$(git show --pretty=raw $commit2 |
1137 sed -n -e "s/^parent //p" -e "/^author /q" |
1138 wc -l) &&
1139 test $numparent = 1
1142 test_expect_success 'update-index D/F conflict' '
1143 mv path0 tmp &&
1144 mv path2 path0 &&
1145 mv tmp path2 &&
1146 git update-index --add --replace path2 path0/file2 &&
1147 numpath0=$(git ls-files path0 | wc -l) &&
1148 test $numpath0 = 1
1151 test_expect_success 'very long name in the index handled sanely' '
1153 a=a && # 1
1154 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
1155 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
1156 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
1157 a=${a}q &&
1159 >path4 &&
1160 git update-index --add path4 &&
1162 git ls-files -s path4 |
1163 sed -e "s/ .*/ /" |
1164 tr -d "\012" &&
1165 echo "$a"
1166 ) | git update-index --index-info &&
1167 len=$(git ls-files "a*" | wc -c) &&
1168 test $len = 4098
1171 test_done