pkt-line.[ch]: remove unused packet_buf_write_len()
[alt-git.git] / t / t0000-basic.sh
blob5c342de713a99b1c971760aee561f6ec5518ae63
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_xy () {
24 local x="local" y="alsolocal" &&
25 echo "$x $y"
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
35 # relying on "local".
36 test_expect_success 'verify that the running shell supports "local"' '
37 x="notlocal" &&
38 y="alsonotlocal" &&
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 ################################################################
64 # Test harness
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
71 shift 3
73 # intercept pseudo-options at the front of the argument list that we
74 # will not pass to child script
75 skip=
76 while test $# -gt 0
78 case "$1" in
79 --skip=*)
80 skip=${1#--*=}
81 shift
84 break
86 esac
87 done
89 mkdir "$name" &&
91 # Pretend we're not running under a test harness, whether we
92 # are or not. The test-lib output depends on the setting of
93 # this variable, so we need a stable setting under which to run
94 # the sub-test.
95 sane_unset HARNESS_ACTIVE &&
96 cd "$name" &&
97 write_script "$name.sh" "$TEST_SHELL_PATH" <<-EOF &&
98 test_description='$descr (run in sub test-lib)
100 This is run in a sub test-lib so that we do not get incorrect
101 passing metrics
104 # Point to the t/test-lib.sh, which isn't in ../ as usual
105 . "\$TEST_DIRECTORY"/test-lib.sh
107 cat >>"$name.sh" &&
108 export TEST_DIRECTORY &&
109 # The child test re-sources GIT-BUILD-OPTIONS and may thus
110 # override the test output directory. We thus pass it as an
111 # explicit override to the child.
112 TEST_OUTPUT_DIRECTORY_OVERRIDE=$(pwd) &&
113 export TEST_OUTPUT_DIRECTORY_OVERRIDE &&
114 GIT_SKIP_TESTS=$skip &&
115 export GIT_SKIP_TESTS &&
116 sane_unset GIT_TEST_FAIL_PREREQS &&
117 if test -z "$neg"
118 then
119 ./"$name.sh" "$@" >out 2>err
120 else
121 ! ./"$name.sh" "$@" >out 2>err
126 run_sub_test_lib_test () {
127 _run_sub_test_lib_test_common '' "$@"
130 run_sub_test_lib_test_err () {
131 _run_sub_test_lib_test_common '!' "$@"
134 check_sub_test_lib_test () {
135 name="$1" # stdin is the expected output from the test
137 cd "$name" &&
138 test_must_be_empty err &&
139 sed -e 's/^> //' -e 's/Z$//' >expect &&
140 test_cmp expect out
144 check_sub_test_lib_test_err () {
145 name="$1" # stdin is the expected output from the test
146 # expected error output is in descriptor 3
148 cd "$name" &&
149 sed -e 's/^> //' -e 's/Z$//' >expect.out &&
150 test_cmp expect.out out &&
151 sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err &&
152 test_cmp expect.err err
156 test_expect_success 'pretend we have a fully passing test suite' '
157 run_sub_test_lib_test full-pass "3 passing tests" <<-\EOF &&
158 for i in 1 2 3
160 test_expect_success "passing test #$i" "true"
161 done
162 test_done
164 check_sub_test_lib_test full-pass <<-\EOF
165 > ok 1 - passing test #1
166 > ok 2 - passing test #2
167 > ok 3 - passing test #3
168 > # passed all 3 test(s)
169 > 1..3
173 test_expect_success 'pretend we have a partially passing test suite' '
174 run_sub_test_lib_test_err \
175 partial-pass "2/3 tests passing" <<-\EOF &&
176 test_expect_success "passing test #1" "true"
177 test_expect_success "failing test #2" "false"
178 test_expect_success "passing test #3" "true"
179 test_done
181 check_sub_test_lib_test partial-pass <<-\EOF
182 > ok 1 - passing test #1
183 > not ok 2 - failing test #2
184 # false
185 > ok 3 - passing test #3
186 > # failed 1 among 3 test(s)
187 > 1..3
191 test_expect_success 'pretend we have a known breakage' '
192 run_sub_test_lib_test failing-todo "A failing TODO test" <<-\EOF &&
193 test_expect_success "passing test" "true"
194 test_expect_failure "pretend we have a known breakage" "false"
195 test_done
197 check_sub_test_lib_test failing-todo <<-\EOF
198 > ok 1 - passing test
199 > not ok 2 - pretend we have a known breakage # TODO known breakage
200 > # still have 1 known breakage(s)
201 > # passed all remaining 1 test(s)
202 > 1..2
206 test_expect_success 'pretend we have fixed a known breakage' '
207 run_sub_test_lib_test passing-todo "A passing TODO test" <<-\EOF &&
208 test_expect_failure "pretend we have fixed a known breakage" "true"
209 test_done
211 check_sub_test_lib_test passing-todo <<-\EOF
212 > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
213 > # 1 known breakage(s) vanished; please update test(s)
214 > 1..1
218 test_expect_success 'pretend we have fixed one of two known breakages (run in sub test-lib)' '
219 run_sub_test_lib_test partially-passing-todos \
220 "2 TODO tests, one passing" <<-\EOF &&
221 test_expect_failure "pretend we have a known breakage" "false"
222 test_expect_success "pretend we have a passing test" "true"
223 test_expect_failure "pretend we have fixed another known breakage" "true"
224 test_done
226 check_sub_test_lib_test partially-passing-todos <<-\EOF
227 > not ok 1 - pretend we have a known breakage # TODO known breakage
228 > ok 2 - pretend we have a passing test
229 > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished
230 > # 1 known breakage(s) vanished; please update test(s)
231 > # still have 1 known breakage(s)
232 > # passed all remaining 1 test(s)
233 > 1..3
237 test_expect_success 'pretend we have a pass, fail, and known breakage' '
238 run_sub_test_lib_test_err \
239 mixed-results1 "mixed results #1" <<-\EOF &&
240 test_expect_success "passing test" "true"
241 test_expect_success "failing test" "false"
242 test_expect_failure "pretend we have a known breakage" "false"
243 test_done
245 check_sub_test_lib_test mixed-results1 <<-\EOF
246 > ok 1 - passing test
247 > not ok 2 - failing test
248 > # false
249 > not ok 3 - pretend we have a known breakage # TODO known breakage
250 > # still have 1 known breakage(s)
251 > # failed 1 among remaining 2 test(s)
252 > 1..3
256 test_expect_success 'pretend we have a mix of all possible results' '
257 run_sub_test_lib_test_err \
258 mixed-results2 "mixed results #2" <<-\EOF &&
259 test_expect_success "passing test" "true"
260 test_expect_success "passing test" "true"
261 test_expect_success "passing test" "true"
262 test_expect_success "passing test" "true"
263 test_expect_success "failing test" "false"
264 test_expect_success "failing test" "false"
265 test_expect_success "failing test" "false"
266 test_expect_failure "pretend we have a known breakage" "false"
267 test_expect_failure "pretend we have a known breakage" "false"
268 test_expect_failure "pretend we have fixed a known breakage" "true"
269 test_done
271 check_sub_test_lib_test mixed-results2 <<-\EOF
272 > ok 1 - passing test
273 > ok 2 - passing test
274 > ok 3 - passing test
275 > ok 4 - passing test
276 > not ok 5 - failing test
277 > # false
278 > not ok 6 - failing test
279 > # false
280 > not ok 7 - failing test
281 > # false
282 > not ok 8 - pretend we have a known breakage # TODO known breakage
283 > not ok 9 - pretend we have a known breakage # TODO known breakage
284 > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
285 > # 1 known breakage(s) vanished; please update test(s)
286 > # still have 2 known breakage(s)
287 > # failed 3 among remaining 7 test(s)
288 > 1..10
292 test_expect_success 'test --verbose' '
293 run_sub_test_lib_test_err \
294 t1234-verbose "test verbose" --verbose <<-\EOF &&
295 test_expect_success "passing test" true
296 test_expect_success "test with output" "echo foo"
297 test_expect_success "failing test" false
298 test_done
300 mv t1234-verbose/out t1234-verbose/out+ &&
301 grep -v "^Initialized empty" t1234-verbose/out+ >t1234-verbose/out &&
302 check_sub_test_lib_test t1234-verbose <<-\EOF
303 > expecting success of 1234.1 '\''passing test'\'': true
304 > ok 1 - passing test
306 > expecting success of 1234.2 '\''test with output'\'': echo foo
307 > foo
308 > ok 2 - test with output
310 > expecting success of 1234.3 '\''failing test'\'': false
311 > not ok 3 - failing test
312 > # false
314 > # failed 1 among 3 test(s)
315 > 1..3
319 test_expect_success 'test --verbose-only' '
320 run_sub_test_lib_test_err \
321 t2345-verbose-only-2 "test verbose-only=2" \
322 --verbose-only=2 <<-\EOF &&
323 test_expect_success "passing test" true
324 test_expect_success "test with output" "echo foo"
325 test_expect_success "failing test" false
326 test_done
328 check_sub_test_lib_test t2345-verbose-only-2 <<-\EOF
329 > ok 1 - passing test
331 > expecting success of 2345.2 '\''test with output'\'': echo foo
332 > foo
333 > ok 2 - test with output
335 > not ok 3 - failing test
336 > # false
337 > # failed 1 among 3 test(s)
338 > 1..3
342 test_expect_success 'GIT_SKIP_TESTS' '
344 run_sub_test_lib_test git-skip-tests-basic \
345 "GIT_SKIP_TESTS" \
346 --skip="git.2" <<-\EOF &&
347 for i in 1 2 3
349 test_expect_success "passing test #$i" "true"
350 done
351 test_done
353 check_sub_test_lib_test git-skip-tests-basic <<-\EOF
354 > ok 1 - passing test #1
355 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
356 > ok 3 - passing test #3
357 > # passed all 3 test(s)
358 > 1..3
363 test_expect_success 'GIT_SKIP_TESTS several tests' '
365 run_sub_test_lib_test git-skip-tests-several \
366 "GIT_SKIP_TESTS several tests" \
367 --skip="git.2 git.5" <<-\EOF &&
368 for i in 1 2 3 4 5 6
370 test_expect_success "passing test #$i" "true"
371 done
372 test_done
374 check_sub_test_lib_test git-skip-tests-several <<-\EOF
375 > ok 1 - passing test #1
376 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
377 > ok 3 - passing test #3
378 > ok 4 - passing test #4
379 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
380 > ok 6 - passing test #6
381 > # passed all 6 test(s)
382 > 1..6
387 test_expect_success 'GIT_SKIP_TESTS sh pattern' '
389 run_sub_test_lib_test git-skip-tests-sh-pattern \
390 "GIT_SKIP_TESTS sh pattern" \
391 --skip="git.[2-5]" <<-\EOF &&
392 for i in 1 2 3 4 5 6
394 test_expect_success "passing test #$i" "true"
395 done
396 test_done
398 check_sub_test_lib_test git-skip-tests-sh-pattern <<-\EOF
399 > ok 1 - passing test #1
400 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS)
401 > ok 3 # skip passing test #3 (GIT_SKIP_TESTS)
402 > ok 4 # skip passing test #4 (GIT_SKIP_TESTS)
403 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS)
404 > ok 6 - passing test #6
405 > # passed all 6 test(s)
406 > 1..6
411 test_expect_success 'GIT_SKIP_TESTS entire suite' '
413 run_sub_test_lib_test git-skip-tests-entire-suite \
414 "GIT_SKIP_TESTS entire suite" \
415 --skip="git" <<-\EOF &&
416 for i in 1 2 3
418 test_expect_success "passing test #$i" "true"
419 done
420 test_done
422 check_sub_test_lib_test git-skip-tests-entire-suite <<-\EOF
423 > 1..0 # SKIP skip all tests in git
428 test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' '
430 run_sub_test_lib_test git-skip-tests-unmatched-suite \
431 "GIT_SKIP_TESTS does not skip unmatched suite" \
432 --skip="notgit" <<-\EOF &&
433 for i in 1 2 3
435 test_expect_success "passing test #$i" "true"
436 done
437 test_done
439 check_sub_test_lib_test git-skip-tests-unmatched-suite <<-\EOF
440 > ok 1 - passing test #1
441 > ok 2 - passing test #2
442 > ok 3 - passing test #3
443 > # passed all 3 test(s)
444 > 1..3
449 test_expect_success '--run basic' '
450 run_sub_test_lib_test run-basic \
451 "--run basic" --run="1,3,5" <<-\EOF &&
452 for i in 1 2 3 4 5 6
454 test_expect_success "passing test #$i" "true"
455 done
456 test_done
458 check_sub_test_lib_test run-basic <<-\EOF
459 > ok 1 - passing test #1
460 > ok 2 # skip passing test #2 (--run)
461 > ok 3 - passing test #3
462 > ok 4 # skip passing test #4 (--run)
463 > ok 5 - passing test #5
464 > ok 6 # skip passing test #6 (--run)
465 > # passed all 6 test(s)
466 > 1..6
470 test_expect_success '--run with a range' '
471 run_sub_test_lib_test run-range \
472 "--run with a range" --run="1-3" <<-\EOF &&
473 for i in 1 2 3 4 5 6
475 test_expect_success "passing test #$i" "true"
476 done
477 test_done
479 check_sub_test_lib_test run-range <<-\EOF
480 > ok 1 - passing test #1
481 > ok 2 - passing test #2
482 > ok 3 - passing test #3
483 > ok 4 # skip passing test #4 (--run)
484 > ok 5 # skip passing test #5 (--run)
485 > ok 6 # skip passing test #6 (--run)
486 > # passed all 6 test(s)
487 > 1..6
491 test_expect_success '--run with two ranges' '
492 run_sub_test_lib_test run-two-ranges \
493 "--run with two ranges" --run="1-2,5-6" <<-\EOF &&
494 for i in 1 2 3 4 5 6
496 test_expect_success "passing test #$i" "true"
497 done
498 test_done
500 check_sub_test_lib_test run-two-ranges <<-\EOF
501 > ok 1 - passing test #1
502 > ok 2 - passing test #2
503 > ok 3 # skip passing test #3 (--run)
504 > ok 4 # skip passing test #4 (--run)
505 > ok 5 - passing test #5
506 > ok 6 - passing test #6
507 > # passed all 6 test(s)
508 > 1..6
512 test_expect_success '--run with a left open range' '
513 run_sub_test_lib_test run-left-open-range \
514 "--run with a left open range" --run="-3" <<-\EOF &&
515 for i in 1 2 3 4 5 6
517 test_expect_success "passing test #$i" "true"
518 done
519 test_done
521 check_sub_test_lib_test run-left-open-range <<-\EOF
522 > ok 1 - passing test #1
523 > ok 2 - passing test #2
524 > ok 3 - passing test #3
525 > ok 4 # skip passing test #4 (--run)
526 > ok 5 # skip passing test #5 (--run)
527 > ok 6 # skip passing test #6 (--run)
528 > # passed all 6 test(s)
529 > 1..6
533 test_expect_success '--run with a right open range' '
534 run_sub_test_lib_test run-right-open-range \
535 "--run with a right open range" --run="4-" <<-\EOF &&
536 for i in 1 2 3 4 5 6
538 test_expect_success "passing test #$i" "true"
539 done
540 test_done
542 check_sub_test_lib_test run-right-open-range <<-\EOF
543 > ok 1 # skip passing test #1 (--run)
544 > ok 2 # skip passing test #2 (--run)
545 > ok 3 # skip passing test #3 (--run)
546 > ok 4 - passing test #4
547 > ok 5 - passing test #5
548 > ok 6 - passing test #6
549 > # passed all 6 test(s)
550 > 1..6
554 test_expect_success '--run with basic negation' '
555 run_sub_test_lib_test run-basic-neg \
556 "--run with basic negation" --run="!3" <<-\EOF &&
557 for i in 1 2 3 4 5 6
559 test_expect_success "passing test #$i" "true"
560 done
561 test_done
563 check_sub_test_lib_test run-basic-neg <<-\EOF
564 > ok 1 - passing test #1
565 > ok 2 - passing test #2
566 > ok 3 # skip passing test #3 (--run)
567 > ok 4 - passing test #4
568 > ok 5 - passing test #5
569 > ok 6 - passing test #6
570 > # passed all 6 test(s)
571 > 1..6
575 test_expect_success '--run with two negations' '
576 run_sub_test_lib_test run-two-neg \
577 "--run with two negations" --run="!3,!6" <<-\EOF &&
578 for i in 1 2 3 4 5 6
580 test_expect_success "passing test #$i" "true"
581 done
582 test_done
584 check_sub_test_lib_test run-two-neg <<-\EOF
585 > ok 1 - passing test #1
586 > ok 2 - passing test #2
587 > ok 3 # skip passing test #3 (--run)
588 > ok 4 - passing test #4
589 > ok 5 - passing test #5
590 > ok 6 # skip passing test #6 (--run)
591 > # passed all 6 test(s)
592 > 1..6
596 test_expect_success '--run a range and negation' '
597 run_sub_test_lib_test run-range-and-neg \
598 "--run a range and negation" --run="-4,!2" <<-\EOF &&
599 for i in 1 2 3 4 5 6
601 test_expect_success "passing test #$i" "true"
602 done
603 test_done
605 check_sub_test_lib_test run-range-and-neg <<-\EOF
606 > ok 1 - passing test #1
607 > ok 2 # skip passing test #2 (--run)
608 > ok 3 - passing test #3
609 > ok 4 - passing test #4
610 > ok 5 # skip passing test #5 (--run)
611 > ok 6 # skip passing test #6 (--run)
612 > # passed all 6 test(s)
613 > 1..6
617 test_expect_success '--run range negation' '
618 run_sub_test_lib_test run-range-neg \
619 "--run range negation" --run="!1-3" <<-\EOF &&
620 for i in 1 2 3 4 5 6
622 test_expect_success "passing test #$i" "true"
623 done
624 test_done
626 check_sub_test_lib_test run-range-neg <<-\EOF
627 > ok 1 # skip passing test #1 (--run)
628 > ok 2 # skip passing test #2 (--run)
629 > ok 3 # skip passing test #3 (--run)
630 > ok 4 - passing test #4
631 > ok 5 - passing test #5
632 > ok 6 - passing test #6
633 > # passed all 6 test(s)
634 > 1..6
638 test_expect_success '--run include, exclude and include' '
639 run_sub_test_lib_test run-inc-neg-inc \
640 "--run include, exclude and include" \
641 --run="1-5,!1-3,2" <<-\EOF &&
642 for i in 1 2 3 4 5 6
644 test_expect_success "passing test #$i" "true"
645 done
646 test_done
648 check_sub_test_lib_test run-inc-neg-inc <<-\EOF
649 > ok 1 # skip passing test #1 (--run)
650 > ok 2 - passing test #2
651 > ok 3 # skip passing test #3 (--run)
652 > ok 4 - passing test #4
653 > ok 5 - passing test #5
654 > ok 6 # skip passing test #6 (--run)
655 > # passed all 6 test(s)
656 > 1..6
660 test_expect_success '--run include, exclude and include, comma separated' '
661 run_sub_test_lib_test run-inc-neg-inc-comma \
662 "--run include, exclude and include, comma separated" \
663 --run=1-5,!1-3,2 <<-\EOF &&
664 for i in 1 2 3 4 5 6
666 test_expect_success "passing test #$i" "true"
667 done
668 test_done
670 check_sub_test_lib_test run-inc-neg-inc-comma <<-\EOF
671 > ok 1 # skip passing test #1 (--run)
672 > ok 2 - passing test #2
673 > ok 3 # skip passing test #3 (--run)
674 > ok 4 - passing test #4
675 > ok 5 - passing test #5
676 > ok 6 # skip passing test #6 (--run)
677 > # passed all 6 test(s)
678 > 1..6
682 test_expect_success '--run exclude and include' '
683 run_sub_test_lib_test run-neg-inc \
684 "--run exclude and include" \
685 --run="!3-,5" <<-\EOF &&
686 for i in 1 2 3 4 5 6
688 test_expect_success "passing test #$i" "true"
689 done
690 test_done
692 check_sub_test_lib_test run-neg-inc <<-\EOF
693 > ok 1 - passing test #1
694 > ok 2 - passing test #2
695 > ok 3 # skip passing test #3 (--run)
696 > ok 4 # skip passing test #4 (--run)
697 > ok 5 - passing test #5
698 > ok 6 # skip passing test #6 (--run)
699 > # passed all 6 test(s)
700 > 1..6
704 test_expect_success '--run empty selectors' '
705 run_sub_test_lib_test run-empty-sel \
706 "--run empty selectors" \
707 --run="1,,3,,,5" <<-\EOF &&
708 for i in 1 2 3 4 5 6
710 test_expect_success "passing test #$i" "true"
711 done
712 test_done
714 check_sub_test_lib_test run-empty-sel <<-\EOF
715 > ok 1 - passing test #1
716 > ok 2 # skip passing test #2 (--run)
717 > ok 3 - passing test #3
718 > ok 4 # skip passing test #4 (--run)
719 > ok 5 - passing test #5
720 > ok 6 # skip passing test #6 (--run)
721 > # passed all 6 test(s)
722 > 1..6
726 test_expect_success '--run substring selector' '
727 run_sub_test_lib_test run-substring-selector \
728 "--run empty selectors" \
729 --run="relevant" <<-\EOF &&
730 test_expect_success "relevant test" "true"
731 for i in 1 2 3 4 5 6
733 test_expect_success "other test #$i" "true"
734 done
735 test_done
737 check_sub_test_lib_test run-substring-selector <<-\EOF
738 > ok 1 - relevant test
739 > ok 2 # skip other test #1 (--run)
740 > ok 3 # skip other test #2 (--run)
741 > ok 4 # skip other test #3 (--run)
742 > ok 5 # skip other test #4 (--run)
743 > ok 6 # skip other test #5 (--run)
744 > ok 7 # skip other test #6 (--run)
745 > # passed all 7 test(s)
746 > 1..7
750 test_expect_success '--run keyword selection' '
751 run_sub_test_lib_test_err run-inv-range-start \
752 "--run invalid range start" \
753 --run="a-5" <<-\EOF &&
754 test_expect_success "passing test #1" "true"
755 test_done
757 check_sub_test_lib_test_err run-inv-range-start \
758 <<-\EOF_OUT 3<<-EOF_ERR
759 > FATAL: Unexpected exit with code 1
760 EOF_OUT
761 > error: --run: invalid non-numeric in range start: ${SQ}a-5${SQ}
762 EOF_ERR
765 test_expect_success '--run invalid range end' '
766 run_sub_test_lib_test_err run-inv-range-end \
767 "--run invalid range end" \
768 --run="1-z" <<-\EOF &&
769 test_expect_success "passing test #1" "true"
770 test_done
772 check_sub_test_lib_test_err run-inv-range-end \
773 <<-\EOF_OUT 3<<-EOF_ERR
774 > FATAL: Unexpected exit with code 1
775 EOF_OUT
776 > error: --run: invalid non-numeric in range end: ${SQ}1-z${SQ}
777 EOF_ERR
780 test_expect_success 'tests respect prerequisites' '
781 run_sub_test_lib_test prereqs "tests respect prereqs" <<-\EOF &&
783 test_set_prereq HAVEIT
784 test_expect_success HAVEIT "prereq is satisfied" "true"
785 test_expect_success "have_prereq works" "
786 test_have_prereq HAVEIT
788 test_expect_success DONTHAVEIT "prereq not satisfied" "false"
790 test_set_prereq HAVETHIS
791 test_expect_success HAVETHIS,HAVEIT "multiple prereqs" "true"
792 test_expect_success HAVEIT,DONTHAVEIT "mixed prereqs (yes,no)" "false"
793 test_expect_success DONTHAVEIT,HAVEIT "mixed prereqs (no,yes)" "false"
795 test_done
798 check_sub_test_lib_test prereqs <<-\EOF
799 ok 1 - prereq is satisfied
800 ok 2 - have_prereq works
801 ok 3 # skip prereq not satisfied (missing DONTHAVEIT)
802 ok 4 - multiple prereqs
803 ok 5 # skip mixed prereqs (yes,no) (missing DONTHAVEIT of HAVEIT,DONTHAVEIT)
804 ok 6 # skip mixed prereqs (no,yes) (missing DONTHAVEIT of DONTHAVEIT,HAVEIT)
805 # passed all 6 test(s)
806 1..6
810 test_expect_success 'tests respect lazy prerequisites' '
811 run_sub_test_lib_test lazy-prereqs "respect lazy prereqs" <<-\EOF &&
813 test_lazy_prereq LAZY_TRUE true
814 test_expect_success LAZY_TRUE "lazy prereq is satisifed" "true"
815 test_expect_success !LAZY_TRUE "negative lazy prereq" "false"
817 test_lazy_prereq LAZY_FALSE false
818 test_expect_success LAZY_FALSE "lazy prereq not satisfied" "false"
819 test_expect_success !LAZY_FALSE "negative false prereq" "true"
821 test_done
824 check_sub_test_lib_test lazy-prereqs <<-\EOF
825 ok 1 - lazy prereq is satisifed
826 ok 2 # skip negative lazy prereq (missing !LAZY_TRUE)
827 ok 3 # skip lazy prereq not satisfied (missing LAZY_FALSE)
828 ok 4 - negative false prereq
829 # passed all 4 test(s)
830 1..4
834 test_expect_success 'nested lazy prerequisites' '
835 run_sub_test_lib_test nested-lazy "nested lazy prereqs" <<-\EOF &&
837 test_lazy_prereq NESTED_INNER "
838 >inner &&
839 rm -f outer
841 test_lazy_prereq NESTED_PREREQ "
842 >outer &&
843 test_have_prereq NESTED_INNER &&
844 echo can create new file in cwd >file &&
845 test_path_is_file outer &&
846 test_path_is_missing inner
848 test_expect_success NESTED_PREREQ "evaluate nested prereq" "true"
850 test_done
853 check_sub_test_lib_test nested-lazy <<-\EOF
854 ok 1 - evaluate nested prereq
855 # passed all 1 test(s)
856 1..1
860 test_expect_success 'lazy prereqs do not turn off tracing' '
861 run_sub_test_lib_test lazy-prereq-and-tracing \
862 "lazy prereqs and -x" -v -x <<-\EOF &&
863 test_lazy_prereq LAZY true
865 test_expect_success lazy "test_have_prereq LAZY && echo trace"
867 test_done
870 grep "echo trace" lazy-prereq-and-tracing/err
873 test_expect_success 'tests clean up after themselves' '
874 run_sub_test_lib_test cleanup "test with cleanup" <<-\EOF &&
875 clean=no
876 test_expect_success "do cleanup" "
877 test_when_finished clean=yes
879 test_expect_success "cleanup happened" "
880 test $clean = yes
882 test_done
885 check_sub_test_lib_test cleanup <<-\EOF
886 ok 1 - do cleanup
887 ok 2 - cleanup happened
888 # passed all 2 test(s)
889 1..2
893 test_expect_success 'tests clean up even on failures' '
894 run_sub_test_lib_test_err \
895 failing-cleanup "Failing tests with cleanup commands" <<-\EOF &&
896 test_expect_success "tests clean up even after a failure" "
897 touch clean-after-failure &&
898 test_when_finished rm clean-after-failure &&
899 (exit 1)
901 test_expect_success "failure to clean up causes the test to fail" "
902 test_when_finished \"(exit 2)\"
904 test_done
906 check_sub_test_lib_test failing-cleanup <<-\EOF
907 > not ok 1 - tests clean up even after a failure
908 > # Z
909 > # touch clean-after-failure &&
910 > # test_when_finished rm clean-after-failure &&
911 > # (exit 1)
912 > # Z
913 > not ok 2 - failure to clean up causes the test to fail
914 > # Z
915 > # test_when_finished "(exit 2)"
916 > # Z
917 > # failed 2 among 2 test(s)
918 > 1..2
922 test_expect_success 'test_atexit is run' '
923 run_sub_test_lib_test_err \
924 atexit-cleanup "Run atexit commands" -i <<-\EOF &&
925 test_expect_success "tests clean up even after a failure" "
926 > ../../clean-atexit &&
927 test_atexit rm ../../clean-atexit &&
928 > ../../also-clean-atexit &&
929 test_atexit rm ../../also-clean-atexit &&
930 > ../../dont-clean-atexit &&
931 (exit 1)
933 test_done
935 test_path_is_file dont-clean-atexit &&
936 test_path_is_missing clean-atexit &&
937 test_path_is_missing also-clean-atexit
940 test_expect_success 'test_oid provides sane info by default' '
941 test_oid zero >actual &&
942 grep "^00*\$" actual &&
943 rawsz="$(test_oid rawsz)" &&
944 hexsz="$(test_oid hexsz)" &&
945 test "$hexsz" -eq $(wc -c <actual) &&
946 test $(( $rawsz * 2)) -eq "$hexsz"
949 test_expect_success 'test_oid can look up data for SHA-1' '
950 test_when_finished "test_detect_hash" &&
951 test_set_hash sha1 &&
952 test_oid zero >actual &&
953 grep "^00*\$" actual &&
954 rawsz="$(test_oid rawsz)" &&
955 hexsz="$(test_oid hexsz)" &&
956 test $(wc -c <actual) -eq 40 &&
957 test "$rawsz" -eq 20 &&
958 test "$hexsz" -eq 40
961 test_expect_success 'test_oid can look up data for SHA-256' '
962 test_when_finished "test_detect_hash" &&
963 test_set_hash sha256 &&
964 test_oid zero >actual &&
965 grep "^00*\$" actual &&
966 rawsz="$(test_oid rawsz)" &&
967 hexsz="$(test_oid hexsz)" &&
968 test $(wc -c <actual) -eq 64 &&
969 test "$rawsz" -eq 32 &&
970 test "$hexsz" -eq 64
973 test_expect_success 'test_oid can look up data for a specified algorithm' '
974 rawsz="$(test_oid --hash=sha1 rawsz)" &&
975 hexsz="$(test_oid --hash=sha1 hexsz)" &&
976 test "$rawsz" -eq 20 &&
977 test "$hexsz" -eq 40 &&
978 rawsz="$(test_oid --hash=sha256 rawsz)" &&
979 hexsz="$(test_oid --hash=sha256 hexsz)" &&
980 test "$rawsz" -eq 32 &&
981 test "$hexsz" -eq 64
984 test_expect_success 'test_bool_env' '
986 sane_unset envvar &&
988 test_bool_env envvar true &&
989 ! test_bool_env envvar false &&
991 envvar= &&
992 export envvar &&
993 ! test_bool_env envvar true &&
994 ! test_bool_env envvar false &&
996 envvar=true &&
997 test_bool_env envvar true &&
998 test_bool_env envvar false &&
1000 envvar=false &&
1001 ! test_bool_env envvar true &&
1002 ! test_bool_env envvar false &&
1004 envvar=invalid &&
1005 # When encountering an invalid bool value, test_bool_env
1006 # prints its error message to the original stderr of the
1007 # test script, hence the redirection of fd 7, and aborts
1008 # with "exit 1", hence the subshell.
1009 ! ( test_bool_env envvar true ) 7>err &&
1010 grep "error: test_bool_env requires bool values" err &&
1012 envvar=true &&
1013 ! ( test_bool_env envvar invalid ) 7>err &&
1014 grep "error: test_bool_env requires bool values" err
1018 ################################################################
1019 # Basics of the basics
1021 test_oid_cache <<\EOF
1022 path0f sha1:f87290f8eb2cbbea7857214459a0739927eab154
1023 path0f sha256:638106af7c38be056f3212cbd7ac65bc1bac74f420ca5a436ff006a9d025d17d
1025 path0s sha1:15a98433ae33114b085f3eb3bb03b832b3180a01
1026 path0s sha256:3a24cc53cf68edddac490bbf94a418a52932130541361f685df685e41dd6c363
1028 path2f sha1:3feff949ed00a62d9f7af97c15cd8a30595e7ac7
1029 path2f sha256:2a7f36571c6fdbaf0e3f62751a0b25a3f4c54d2d1137b3f4af9cb794bb498e5f
1031 path2s sha1:d8ce161addc5173867a3c3c730924388daedbc38
1032 path2s sha256:18fd611b787c2e938ddcc248fabe4d66a150f9364763e9ec133dd01d5bb7c65a
1034 path2d sha1:58a09c23e2ca152193f2786e06986b7b6712bdbe
1035 path2d sha256:00e4b32b96e7e3d65d79112dcbea53238a22715f896933a62b811377e2650c17
1037 path3f sha1:0aa34cae68d0878578ad119c86ca2b5ed5b28376
1038 path3f sha256:09f58616b951bd571b8cb9dc76d372fbb09ab99db2393f5ab3189d26c45099ad
1040 path3s sha1:8599103969b43aff7e430efea79ca4636466794f
1041 path3s sha256:fce1aed087c053306f3f74c32c1a838c662bbc4551a7ac2420f5d6eb061374d0
1043 path3d sha1:21ae8269cacbe57ae09138dcc3a2887f904d02b3
1044 path3d sha256:9b60497be959cb830bf3f0dc82bcc9ad9e925a24e480837ade46b2295e47efe1
1046 subp3f sha1:00fb5908cb97c2564a9783c0c64087333b3b464f
1047 subp3f sha256:a1a9e16998c988453f18313d10375ee1d0ddefe757e710dcae0d66aa1e0c58b3
1049 subp3s sha1:6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
1050 subp3s sha256:81759d9f5e93c6546ecfcadb560c1ff057314b09f93fe8ec06e2d8610d34ef10
1052 subp3d sha1:3c5e5399f3a333eddecce7a9b9465b63f65f51e2
1053 subp3d sha256:76b4ef482d4fa1c754390344cf3851c7f883b27cf9bc999c6547928c46aeafb7
1055 root sha1:087704a96baf1c2d1c869a8b084481e121c88b5b
1056 root sha256:9481b52abab1b2ffeedbf9de63ce422b929f179c1b98ff7bee5f8f1bc0710751
1058 simpletree sha1:7bb943559a305bdd6bdee2cef6e5df2413c3d30a
1059 simpletree sha256:1710c07a6c86f9a3c7376364df04c47ee39e5a5e221fcdd84b743bc9bb7e2bc5
1062 # updating a new file without --add should fail.
1063 test_expect_success 'git update-index without --add should fail adding' '
1064 test_must_fail git update-index should-be-empty
1067 # and with --add it should succeed, even if it is empty (it used to fail).
1068 test_expect_success 'git update-index with --add should succeed' '
1069 git update-index --add should-be-empty
1072 test_expect_success 'writing tree out with git write-tree' '
1073 tree=$(git write-tree)
1076 # we know the shape and contents of the tree and know the object ID for it.
1077 test_expect_success 'validate object ID of a known tree' '
1078 test "$tree" = "$(test_oid simpletree)"
1081 # Removing paths.
1082 test_expect_success 'git update-index without --remove should fail removing' '
1083 rm -f should-be-empty full-of-directories &&
1084 test_must_fail git update-index should-be-empty
1087 test_expect_success 'git update-index with --remove should be able to remove' '
1088 git update-index --remove should-be-empty
1091 # Empty tree can be written with recent write-tree.
1092 test_expect_success 'git write-tree should be able to write an empty tree' '
1093 tree=$(git write-tree)
1096 test_expect_success 'validate object ID of a known tree' '
1097 test "$tree" = $EMPTY_TREE
1100 # Various types of objects
1102 test_expect_success 'adding various types of objects with git update-index --add' '
1103 mkdir path2 path3 path3/subp3 &&
1104 paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
1106 for p in $paths
1108 echo "hello $p" >$p || exit 1
1109 test_ln_s_add "hello $p" ${p}sym || exit 1
1110 done
1111 ) &&
1112 find path* ! -type d -print | xargs git update-index --add
1115 # Show them and see that matches what we expect.
1116 test_expect_success 'showing stage with git ls-files --stage' '
1117 git ls-files --stage >current
1120 test_expect_success 'validate git ls-files output for a known tree' '
1121 cat >expected <<-EOF &&
1122 100644 $(test_oid path0f) 0 path0
1123 120000 $(test_oid path0s) 0 path0sym
1124 100644 $(test_oid path2f) 0 path2/file2
1125 120000 $(test_oid path2s) 0 path2/file2sym
1126 100644 $(test_oid path3f) 0 path3/file3
1127 120000 $(test_oid path3s) 0 path3/file3sym
1128 100644 $(test_oid subp3f) 0 path3/subp3/file3
1129 120000 $(test_oid subp3s) 0 path3/subp3/file3sym
1131 test_cmp expected current
1134 test_expect_success 'writing tree out with git write-tree' '
1135 tree=$(git write-tree)
1138 test_expect_success 'validate object ID for a known tree' '
1139 test "$tree" = "$(test_oid root)"
1142 test_expect_success 'showing tree with git ls-tree' '
1143 git ls-tree $tree >current
1146 test_expect_success 'git ls-tree output for a known tree' '
1147 cat >expected <<-EOF &&
1148 100644 blob $(test_oid path0f) path0
1149 120000 blob $(test_oid path0s) path0sym
1150 040000 tree $(test_oid path2d) path2
1151 040000 tree $(test_oid path3d) path3
1153 test_cmp expected current
1156 # This changed in ls-tree pathspec change -- recursive does
1157 # not show tree nodes anymore.
1158 test_expect_success 'showing tree with git ls-tree -r' '
1159 git ls-tree -r $tree >current
1162 test_expect_success 'git ls-tree -r output for a known tree' '
1163 cat >expected <<-EOF &&
1164 100644 blob $(test_oid path0f) path0
1165 120000 blob $(test_oid path0s) path0sym
1166 100644 blob $(test_oid path2f) path2/file2
1167 120000 blob $(test_oid path2s) path2/file2sym
1168 100644 blob $(test_oid path3f) path3/file3
1169 120000 blob $(test_oid path3s) path3/file3sym
1170 100644 blob $(test_oid subp3f) path3/subp3/file3
1171 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1173 test_cmp expected current
1176 # But with -r -t we can have both.
1177 test_expect_success 'showing tree with git ls-tree -r -t' '
1178 git ls-tree -r -t $tree >current
1181 test_expect_success 'git ls-tree -r output for a known tree' '
1182 cat >expected <<-EOF &&
1183 100644 blob $(test_oid path0f) path0
1184 120000 blob $(test_oid path0s) path0sym
1185 040000 tree $(test_oid path2d) path2
1186 100644 blob $(test_oid path2f) path2/file2
1187 120000 blob $(test_oid path2s) path2/file2sym
1188 040000 tree $(test_oid path3d) path3
1189 100644 blob $(test_oid path3f) path3/file3
1190 120000 blob $(test_oid path3s) path3/file3sym
1191 040000 tree $(test_oid subp3d) path3/subp3
1192 100644 blob $(test_oid subp3f) path3/subp3/file3
1193 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1195 test_cmp expected current
1198 test_expect_success 'writing partial tree out with git write-tree --prefix' '
1199 ptree=$(git write-tree --prefix=path3)
1202 test_expect_success 'validate object ID for a known tree' '
1203 test "$ptree" = $(test_oid path3d)
1206 test_expect_success 'writing partial tree out with git write-tree --prefix' '
1207 ptree=$(git write-tree --prefix=path3/subp3)
1210 test_expect_success 'validate object ID for a known tree' '
1211 test "$ptree" = $(test_oid subp3d)
1214 test_expect_success 'put invalid objects into the index' '
1215 rm -f .git/index &&
1216 suffix=$(echo $ZERO_OID | sed -e "s/^.//") &&
1217 cat >badobjects <<-EOF &&
1218 100644 blob $(test_oid 001) dir/file1
1219 100644 blob $(test_oid 002) dir/file2
1220 100644 blob $(test_oid 003) dir/file3
1221 100644 blob $(test_oid 004) dir/file4
1222 100644 blob $(test_oid 005) dir/file5
1224 git update-index --index-info <badobjects
1227 test_expect_success 'writing this tree without --missing-ok' '
1228 test_must_fail git write-tree
1231 test_expect_success 'writing this tree with --missing-ok' '
1232 git write-tree --missing-ok
1236 ################################################################
1237 test_expect_success 'git read-tree followed by write-tree should be idempotent' '
1238 rm -f .git/index &&
1239 git read-tree $tree &&
1240 test_path_is_file .git/index &&
1241 newtree=$(git write-tree) &&
1242 test "$newtree" = "$tree"
1245 test_expect_success 'validate git diff-files output for a know cache/work tree state' '
1246 cat >expected <<EOF &&
1247 :100644 100644 $(test_oid path0f) $ZERO_OID M path0
1248 :120000 120000 $(test_oid path0s) $ZERO_OID M path0sym
1249 :100644 100644 $(test_oid path2f) $ZERO_OID M path2/file2
1250 :120000 120000 $(test_oid path2s) $ZERO_OID M path2/file2sym
1251 :100644 100644 $(test_oid path3f) $ZERO_OID M path3/file3
1252 :120000 120000 $(test_oid path3s) $ZERO_OID M path3/file3sym
1253 :100644 100644 $(test_oid subp3f) $ZERO_OID M path3/subp3/file3
1254 :120000 120000 $(test_oid subp3s) $ZERO_OID M path3/subp3/file3sym
1256 git diff-files >current &&
1257 test_cmp expected current
1260 test_expect_success 'git update-index --refresh should succeed' '
1261 git update-index --refresh
1264 test_expect_success 'no diff after checkout and git update-index --refresh' '
1265 git diff-files >current &&
1266 cmp -s current /dev/null
1269 ################################################################
1270 P=$(test_oid root)
1272 test_expect_success 'git commit-tree records the correct tree in a commit' '
1273 commit0=$(echo NO | git commit-tree $P) &&
1274 git show --pretty=raw $commit0 >out &&
1275 tree=$(sed -n -e "s/^tree //p" -e "/^author /q" out) &&
1276 test "z$tree" = "z$P"
1279 test_expect_success 'git commit-tree records the correct parent in a commit' '
1280 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
1281 git show --pretty=raw $commit1 >out &&
1282 parent=$(sed -n -e "s/^parent //p" -e "/^author /q" out) &&
1283 test "z$commit0" = "z$parent"
1286 test_expect_success 'git commit-tree omits duplicated parent in a commit' '
1287 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
1288 git show --pretty=raw $commit2 >out &&
1289 cat >match.sed <<-\EOF &&
1290 s/^parent //p
1291 /^author /q
1293 parent=$(sed -n -f match.sed out | sort -u) &&
1294 test "z$commit0" = "z$parent" &&
1295 git show --pretty=raw $commit2 >out &&
1296 test_stdout_line_count = 1 sed -n -f match.sed out
1299 test_expect_success 'update-index D/F conflict' '
1300 mv path0 tmp &&
1301 mv path2 path0 &&
1302 mv tmp path2 &&
1303 git update-index --add --replace path2 path0/file2 &&
1304 numpath0=$(git ls-files path0 | wc -l) &&
1305 test $numpath0 = 1
1308 test_expect_success 'very long name in the index handled sanely' '
1310 a=a && # 1
1311 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
1312 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
1313 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
1314 a=${a}q &&
1316 >path4 &&
1317 git update-index --add path4 &&
1319 git ls-files -s path4 |
1320 sed -e "s/ .*/ /" |
1321 tr -d "\012" &&
1322 echo "$a"
1323 ) | git update-index --index-info &&
1324 len=$(git ls-files "a*" | wc -c) &&
1325 test $len = 4098
1328 test_expect_success 'test_must_fail on a failing git command' '
1329 test_must_fail git notacommand
1332 test_expect_success 'test_must_fail on a failing git command with env' '
1333 test_must_fail env var1=a var2=b git notacommand
1336 test_expect_success 'test_must_fail rejects a non-git command' '
1337 ! test_must_fail grep ^$ notafile 2>err &&
1338 grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
1341 test_expect_success 'test_must_fail rejects a non-git command with env' '
1342 ! test_must_fail env var1=a var2=b grep ^$ notafile 2>err &&
1343 grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
1346 test_done