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