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