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