]> git.ipfire.org Git - thirdparty/git.git/blame - t/t0000-basic.sh
i18n: make GETTEXT_POISON a runtime option
[thirdparty/git.git] / t / t0000-basic.sh
CommitLineData
e1970ce4
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Test the very basics part #1.
7
8The rest of the test suite does not check the basic operation of git
9plumbing commands to work very carefully. Their job is to concentrate
10on tricky features that caused bugs in the past to detect regression.
11
12This test runs very basic features, like registering things in cache,
13writing tree, etc.
14
15Note that this test *deliberately* hard-codes many expected object
16IDs. When object ID computation changes, like in the previous case of
17swapping compression and hashing order, the person who is making the
18modification *should* take notice and update the test vectors here.
19'
eea42069 20
e1970ce4
JH
21. ./test-lib.sh
22
01d3a526
MH
23try_local_x () {
24 local x="local" &&
25 echo "$x"
26}
27
28# This test is an experiment to check whether any Git users are using
29# Shells that don't support the "local" keyword. "local" is not
30# POSIX-standard, but it is very widely supported by POSIX-compliant
31# shells, and if it doesn't cause problems for people, we would like
32# to be able to use it in Git code.
33#
34# For now, this is the only test that requires "local". If your shell
35# fails this test, you can ignore the failure, but please report the
36# problem to the Git mailing list <git@vger.kernel.org>, as it might
37# convince us to continue avoiding the use of "local".
38test_expect_success 'verify that the running shell supports "local"' '
39 x="notlocal" &&
40 echo "local" >expected1 &&
41 try_local_x >actual1 &&
42 test_cmp expected1 actual1 &&
43 echo "notlocal" >expected2 &&
44 echo "$x" >actual2 &&
45 test_cmp expected2 actual2
46'
47
e1970ce4 48################################################################
5be60078 49# git init has been done in an empty repository.
e1970ce4
JH
50# make sure it is empty.
51
1b5b2b64
SL
52test_expect_success '.git/objects should be empty after git init in an empty repo' '
53 find .git/objects -type f -print >should-be-empty &&
54 test_line_count = 0 should-be-empty
55'
e1970ce4 56
9106c097
LT
57# also it should have 2 subdirectories; no fan-out anymore, pack, and info.
58# 3 is counting "objects" itself
1b5b2b64
SL
59test_expect_success '.git/objects should have 3 subdirectories' '
60 find .git/objects -type d -print >full-of-directories &&
61 test_line_count = 3 full-of-directories
62'
e1970ce4 63
41ac414e
JH
64################################################################
65# Test harness
66test_expect_success 'success is reported like this' '
1b5b2b64 67 :
41ac414e 68'
7b905119 69
0445e6f0
IB
70_run_sub_test_lib_test_common () {
71 neg="$1" name="$2" descr="$3" # stdin is the body of the test code
72 shift 3
565b6fa8
AS
73 mkdir "$name" &&
74 (
a63c12c9
JK
75 # Pretend we're not running under a test harness, whether we
76 # are or not. The test-lib output depends on the setting of
77 # this variable, so we need a stable setting under which to run
78 # the sub-test.
79 sane_unset HARNESS_ACTIVE &&
565b6fa8
AS
80 cd "$name" &&
81 cat >"$name.sh" <<-EOF &&
82 #!$SHELL_PATH
83
84 test_description='$descr (run in sub test-lib)
85
86 This is run in a sub test-lib so that we do not get incorrect
87 passing metrics
88 '
89
4231d1ba
JH
90 # Tell the framework that we are self-testing to make sure
91 # it yields a stable result.
92 GIT_TEST_FRAMEWORK_SELFTEST=t &&
93
565b6fa8
AS
94 # Point to the t/test-lib.sh, which isn't in ../ as usual
95 . "\$TEST_DIRECTORY"/test-lib.sh
96 EOF
97 cat >>"$name.sh" &&
98 chmod +x "$name.sh" &&
99 export TEST_DIRECTORY &&
68830470
JK
100 TEST_OUTPUT_DIRECTORY=$(pwd) &&
101 export TEST_OUTPUT_DIRECTORY &&
0445e6f0
IB
102 if test -z "$neg"
103 then
104 ./"$name.sh" "$@" >out 2>err
105 else
106 ! ./"$name.sh" "$@" >out 2>err
107 fi
565b6fa8
AS
108 )
109}
1b5b2b64 110
0445e6f0
IB
111run_sub_test_lib_test () {
112 _run_sub_test_lib_test_common '' "$@"
113}
114
115run_sub_test_lib_test_err () {
116 _run_sub_test_lib_test_common '!' "$@"
117}
118
565b6fa8
AS
119check_sub_test_lib_test () {
120 name="$1" # stdin is the expected output from the test
121 (
122 cd "$name" &&
ec10b018 123 test_must_be_empty err &&
565b6fa8
AS
124 sed -e 's/^> //' -e 's/Z$//' >expect &&
125 test_cmp expect out
126 )
127}
1b5b2b64 128
0445e6f0 129check_sub_test_lib_test_err () {
832c0e5e 130 name="$1" # stdin is the expected output from the test
0445e6f0
IB
131 # expected error output is in descriptior 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
5ebf89e8
AS
141test_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"
1b5b2b64 157
5ebf89e8
AS
158test_expect_success 'pretend we have a partially passing test suite' "
159 test_must_fail run_sub_test_lib_test \
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"
1b5b2b64 175
5ebf89e8
AS
176test_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"
1b5b2b64 190
565b6fa8
AS
191test_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'
1b5b2b64
SL
194 test_done
195 EOF
565b6fa8 196 check_sub_test_lib_test passing-todo <<-\\EOF
b73d9a23
AS
197 > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
198 > # 1 known breakage(s) vanished; please update test(s)
1b5b2b64
SL
199 > 1..1
200 EOF
7b905119 201"
565b6fa8 202
b73d9a23
AS
203test_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
5ebf89e8
AS
222test_expect_success 'pretend we have a pass, fail, and known breakage' "
223 test_must_fail run_sub_test_lib_test \
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
241test_expect_success 'pretend we have a mix of all possible results' "
242 test_must_fail run_sub_test_lib_test \
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
b73d9a23
AS
269 > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
270 > # 1 known breakage(s) vanished; please update test(s)
5ebf89e8 271 > # still have 2 known breakage(s)
b73d9a23 272 > # failed 3 among remaining 7 test(s)
5ebf89e8
AS
273 > 1..10
274 EOF
275"
276
6cdccfce 277test_expect_success C_LOCALE_OUTPUT 'test --verbose' '
517cd55f
TR
278 test_must_fail run_sub_test_lib_test \
279 test-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
99094a7a 285 mv test-verbose/out test-verbose/out+ &&
517cd55f
TR
286 grep -v "^Initialized empty" test-verbose/out+ >test-verbose/out &&
287 check_sub_test_lib_test test-verbose <<-\EOF
288 > expecting success: true
517cd55f
TR
289 > ok 1 - passing test
290 > Z
291 > expecting success: echo foo
292 > foo
517cd55f
TR
293 > ok 2 - test with output
294 > Z
295 > expecting success: false
517cd55f
TR
296 > not ok 3 - failing test
297 > # false
298 > Z
299 > # failed 1 among 3 test(s)
300 > 1..3
301 EOF
302'
303
ff09af3f
TR
304test_expect_success 'test --verbose-only' '
305 test_must_fail run_sub_test_lib_test \
306 test-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 test-verbose-only-2 <<-\EOF
314 > ok 1 - passing test
315 > Z
316 > expecting success: echo foo
317 > foo
ff09af3f
TR
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
ef2ac68d 327test_expect_success 'GIT_SKIP_TESTS' "
7e28c16f
RJ
328 (
329 GIT_SKIP_TESTS='git.2' && export GIT_SKIP_TESTS &&
ef2ac68d 330 run_sub_test_lib_test git-skip-tests-basic \
7e28c16f
RJ
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 )
ef2ac68d
IB
346"
347
348test_expect_success 'GIT_SKIP_TESTS several tests' "
7e28c16f
RJ
349 (
350 GIT_SKIP_TESTS='git.2 git.5' && export GIT_SKIP_TESTS &&
ef2ac68d 351 run_sub_test_lib_test git-skip-tests-several \
7e28c16f
RJ
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 )
ef2ac68d
IB
370"
371
372test_expect_success 'GIT_SKIP_TESTS sh pattern' "
7e28c16f
RJ
373 (
374 GIT_SKIP_TESTS='git.[2-5]' && export GIT_SKIP_TESTS &&
ef2ac68d 375 run_sub_test_lib_test git-skip-tests-sh-pattern \
7e28c16f
RJ
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 )
ef2ac68d
IB
394"
395
0445e6f0
IB
396test_expect_success '--run basic' "
397 run_sub_test_lib_test run-basic \
398 '--run basic' --run='1 3 5' <<-\\EOF &&
399 for i in 1 2 3 4 5 6
400 do
401 test_expect_success \"passing test #\$i\" 'true'
402 done
403 test_done
404 EOF
405 check_sub_test_lib_test run-basic <<-\\EOF
406 > ok 1 - passing test #1
407 > ok 2 # skip passing test #2 (--run)
408 > ok 3 - passing test #3
409 > ok 4 # skip passing test #4 (--run)
410 > ok 5 - passing test #5
411 > ok 6 # skip passing test #6 (--run)
412 > # passed all 6 test(s)
413 > 1..6
414 EOF
415"
416
417test_expect_success '--run with a range' "
418 run_sub_test_lib_test run-range \
419 '--run with a range' --run='1-3' <<-\\EOF &&
420 for i in 1 2 3 4 5 6
421 do
422 test_expect_success \"passing test #\$i\" 'true'
423 done
424 test_done
425 EOF
426 check_sub_test_lib_test run-range <<-\\EOF
427 > ok 1 - passing test #1
428 > ok 2 - passing test #2
429 > ok 3 - passing test #3
430 > ok 4 # skip passing test #4 (--run)
431 > ok 5 # skip passing test #5 (--run)
432 > ok 6 # skip passing test #6 (--run)
433 > # passed all 6 test(s)
434 > 1..6
435 EOF
436"
437
438test_expect_success '--run with two ranges' "
439 run_sub_test_lib_test run-two-ranges \
440 '--run with two ranges' --run='1-2 5-6' <<-\\EOF &&
441 for i in 1 2 3 4 5 6
442 do
443 test_expect_success \"passing test #\$i\" 'true'
444 done
445 test_done
446 EOF
447 check_sub_test_lib_test run-two-ranges <<-\\EOF
448 > ok 1 - passing test #1
449 > ok 2 - passing test #2
450 > ok 3 # skip passing test #3 (--run)
451 > ok 4 # skip passing test #4 (--run)
452 > ok 5 - passing test #5
453 > ok 6 - passing test #6
454 > # passed all 6 test(s)
455 > 1..6
456 EOF
457"
458
459test_expect_success '--run with a left open range' "
460 run_sub_test_lib_test run-left-open-range \
461 '--run with a left open range' --run='-3' <<-\\EOF &&
462 for i in 1 2 3 4 5 6
463 do
464 test_expect_success \"passing test #\$i\" 'true'
465 done
466 test_done
467 EOF
468 check_sub_test_lib_test run-left-open-range <<-\\EOF
469 > ok 1 - passing test #1
470 > ok 2 - passing test #2
471 > ok 3 - passing test #3
472 > ok 4 # skip passing test #4 (--run)
473 > ok 5 # skip passing test #5 (--run)
474 > ok 6 # skip passing test #6 (--run)
475 > # passed all 6 test(s)
476 > 1..6
477 EOF
478"
479
480test_expect_success '--run with a right open range' "
481 run_sub_test_lib_test run-right-open-range \
482 '--run with a right open range' --run='4-' <<-\\EOF &&
483 for i in 1 2 3 4 5 6
484 do
485 test_expect_success \"passing test #\$i\" 'true'
486 done
487 test_done
488 EOF
489 check_sub_test_lib_test run-right-open-range <<-\\EOF
490 > ok 1 # skip passing test #1 (--run)
491 > ok 2 # skip passing test #2 (--run)
492 > ok 3 # skip passing test #3 (--run)
493 > ok 4 - passing test #4
494 > ok 5 - passing test #5
495 > ok 6 - passing test #6
496 > # passed all 6 test(s)
497 > 1..6
498 EOF
499"
500
501test_expect_success '--run with basic negation' "
502 run_sub_test_lib_test run-basic-neg \
503 '--run with basic negation' --run='"'!3'"' <<-\\EOF &&
504 for i in 1 2 3 4 5 6
505 do
506 test_expect_success \"passing test #\$i\" 'true'
507 done
508 test_done
509 EOF
510 check_sub_test_lib_test run-basic-neg <<-\\EOF
511 > ok 1 - passing test #1
512 > ok 2 - passing test #2
513 > ok 3 # skip passing test #3 (--run)
514 > ok 4 - passing test #4
515 > ok 5 - passing test #5
516 > ok 6 - passing test #6
517 > # passed all 6 test(s)
518 > 1..6
519 EOF
520"
521
522test_expect_success '--run with two negations' "
523 run_sub_test_lib_test run-two-neg \
524 '--run with two negations' --run='"'!3 !6'"' <<-\\EOF &&
525 for i in 1 2 3 4 5 6
526 do
527 test_expect_success \"passing test #\$i\" 'true'
528 done
529 test_done
530 EOF
531 check_sub_test_lib_test run-two-neg <<-\\EOF
532 > ok 1 - passing test #1
533 > ok 2 - passing test #2
534 > ok 3 # skip passing test #3 (--run)
535 > ok 4 - passing test #4
536 > ok 5 - passing test #5
537 > ok 6 # skip passing test #6 (--run)
538 > # passed all 6 test(s)
539 > 1..6
540 EOF
541"
542
543test_expect_success '--run a range and negation' "
544 run_sub_test_lib_test run-range-and-neg \
545 '--run a range and negation' --run='"'-4 !2'"' <<-\\EOF &&
546 for i in 1 2 3 4 5 6
547 do
548 test_expect_success \"passing test #\$i\" 'true'
549 done
550 test_done
551 EOF
552 check_sub_test_lib_test run-range-and-neg <<-\\EOF
553 > ok 1 - passing test #1
554 > ok 2 # skip passing test #2 (--run)
555 > ok 3 - passing test #3
556 > ok 4 - passing test #4
557 > ok 5 # skip passing test #5 (--run)
558 > ok 6 # skip passing test #6 (--run)
559 > # passed all 6 test(s)
560 > 1..6
561 EOF
562"
563
564test_expect_success '--run range negation' "
565 run_sub_test_lib_test run-range-neg \
566 '--run range negation' --run='"'!1-3'"' <<-\\EOF &&
567 for i in 1 2 3 4 5 6
568 do
569 test_expect_success \"passing test #\$i\" 'true'
570 done
571 test_done
572 EOF
573 check_sub_test_lib_test run-range-neg <<-\\EOF
574 > ok 1 # skip passing test #1 (--run)
575 > ok 2 # skip passing test #2 (--run)
576 > ok 3 # skip passing test #3 (--run)
577 > ok 4 - passing test #4
578 > ok 5 - passing test #5
579 > ok 6 - passing test #6
580 > # passed all 6 test(s)
581 > 1..6
582 EOF
583"
584
585test_expect_success '--run include, exclude and include' "
586 run_sub_test_lib_test run-inc-neg-inc \
587 '--run include, exclude and include' \
588 --run='"'1-5 !1-3 2'"' <<-\\EOF &&
589 for i in 1 2 3 4 5 6
590 do
591 test_expect_success \"passing test #\$i\" 'true'
592 done
593 test_done
594 EOF
595 check_sub_test_lib_test run-inc-neg-inc <<-\\EOF
596 > ok 1 # skip passing test #1 (--run)
597 > ok 2 - passing test #2
598 > ok 3 # skip passing test #3 (--run)
599 > ok 4 - passing test #4
600 > ok 5 - passing test #5
601 > ok 6 # skip passing test #6 (--run)
602 > # passed all 6 test(s)
603 > 1..6
604 EOF
605"
606
607test_expect_success '--run include, exclude and include, comma separated' "
608 run_sub_test_lib_test run-inc-neg-inc-comma \
609 '--run include, exclude and include, comma separated' \
610 --run=1-5,\!1-3,2 <<-\\EOF &&
611 for i in 1 2 3 4 5 6
612 do
613 test_expect_success \"passing test #\$i\" 'true'
614 done
615 test_done
616 EOF
617 check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF
618 > ok 1 # skip passing test #1 (--run)
619 > ok 2 - passing test #2
620 > ok 3 # skip passing test #3 (--run)
621 > ok 4 - passing test #4
622 > ok 5 - passing test #5
623 > ok 6 # skip passing test #6 (--run)
624 > # passed all 6 test(s)
625 > 1..6
626 EOF
627"
628
629test_expect_success '--run exclude and include' "
630 run_sub_test_lib_test run-neg-inc \
631 '--run exclude and include' \
632 --run='"'!3- 5'"' <<-\\EOF &&
633 for i in 1 2 3 4 5 6
634 do
635 test_expect_success \"passing test #\$i\" 'true'
636 done
637 test_done
638 EOF
639 check_sub_test_lib_test run-neg-inc <<-\\EOF
640 > ok 1 - passing test #1
641 > ok 2 - passing test #2
642 > ok 3 # skip passing test #3 (--run)
643 > ok 4 # skip passing test #4 (--run)
644 > ok 5 - passing test #5
645 > ok 6 # skip passing test #6 (--run)
646 > # passed all 6 test(s)
647 > 1..6
648 EOF
649"
650
651test_expect_success '--run empty selectors' "
652 run_sub_test_lib_test run-empty-sel \
653 '--run empty selectors' \
654 --run='1,,3,,,5' <<-\\EOF &&
655 for i in 1 2 3 4 5 6
656 do
657 test_expect_success \"passing test #\$i\" 'true'
658 done
659 test_done
660 EOF
661 check_sub_test_lib_test run-empty-sel <<-\\EOF
662 > ok 1 - passing test #1
663 > ok 2 # skip passing test #2 (--run)
664 > ok 3 - passing test #3
665 > ok 4 # skip passing test #4 (--run)
666 > ok 5 - passing test #5
667 > ok 6 # skip passing test #6 (--run)
668 > # passed all 6 test(s)
669 > 1..6
670 EOF
671"
672
673test_expect_success '--run invalid range start' "
674 run_sub_test_lib_test_err run-inv-range-start \
675 '--run invalid range start' \
676 --run='a-5' <<-\\EOF &&
677 test_expect_success \"passing test #1\" 'true'
678 test_done
679 EOF
680 check_sub_test_lib_test_err run-inv-range-start \
681 <<-\\EOF_OUT 3<<-\\EOF_ERR
682 > FATAL: Unexpected exit with code 1
683 EOF_OUT
684 > error: --run: invalid non-numeric in range start: 'a-5'
685 EOF_ERR
686"
687
688test_expect_success '--run invalid range end' "
689 run_sub_test_lib_test_err run-inv-range-end \
690 '--run invalid range end' \
691 --run='1-z' <<-\\EOF &&
692 test_expect_success \"passing test #1\" 'true'
693 test_done
694 EOF
695 check_sub_test_lib_test_err run-inv-range-end \
696 <<-\\EOF_OUT 3<<-\\EOF_ERR
697 > FATAL: Unexpected exit with code 1
698 EOF_OUT
699 > error: --run: invalid non-numeric in range end: '1-z'
700 EOF_ERR
701"
702
703test_expect_success '--run invalid selector' "
704 run_sub_test_lib_test_err run-inv-selector \
705 '--run invalid selector' \
706 --run='1?' <<-\\EOF &&
707 test_expect_success \"passing test #1\" 'true'
708 test_done
709 EOF
710 check_sub_test_lib_test_err run-inv-selector \
711 <<-\\EOF_OUT 3<<-\\EOF_ERR
712 > FATAL: Unexpected exit with code 1
713 EOF_OUT
714 > error: --run: invalid non-numeric in test selector: '1?'
715 EOF_ERR
716"
717
718
a7bb3940
JS
719test_set_prereq HAVEIT
720haveit=no
721test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
1b5b2b64
SL
722 test_have_prereq HAVEIT &&
723 haveit=yes
a7bb3940
JS
724'
725donthaveit=yes
726test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' '
1b5b2b64 727 donthaveit=no
a7bb3940
JS
728'
729if test $haveit$donthaveit != yesyes
730then
731 say "bug in test framework: prerequisite tags do not work reliably"
93a57246
ÆAB
732 exit 1
733fi
734
735test_set_prereq HAVETHIS
736haveit=no
737test_expect_success HAVETHIS,HAVEIT 'test runs if prerequisites are satisfied' '
1b5b2b64
SL
738 test_have_prereq HAVEIT &&
739 test_have_prereq HAVETHIS &&
740 haveit=yes
93a57246
ÆAB
741'
742donthaveit=yes
743test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' '
1b5b2b64 744 donthaveit=no
93a57246 745'
ce60653e
ÆAB
746donthaveiteither=yes
747test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' '
1b5b2b64 748 donthaveiteither=no
ce60653e
ÆAB
749'
750if test $haveit$donthaveit$donthaveiteither != yesyesyes
93a57246
ÆAB
751then
752 say "bug in test framework: multiple prerequisite tags do not work reliably"
a7bb3940
JS
753 exit 1
754fi
41ac414e 755
bdccd3c1
JK
756test_lazy_prereq LAZY_TRUE true
757havetrue=no
758test_expect_success LAZY_TRUE 'test runs if lazy prereq is satisfied' '
759 havetrue=yes
760'
761donthavetrue=yes
762test_expect_success !LAZY_TRUE 'missing lazy prereqs skip tests' '
763 donthavetrue=no
764'
765
766if test "$havetrue$donthavetrue" != yesyes
767then
768 say 'bug in test framework: lazy prerequisites do not work'
769 exit 1
770fi
771
772test_lazy_prereq LAZY_FALSE false
773nothavefalse=no
774test_expect_success !LAZY_FALSE 'negative lazy prereqs checked' '
775 nothavefalse=yes
776'
777havefalse=yes
778test_expect_success LAZY_FALSE 'missing negative lazy prereqs will skip' '
779 havefalse=no
780'
781
782if test "$nothavefalse$havefalse" != yesyes
783then
784 say 'bug in test framework: negative lazy prerequisites do not work'
785 exit 1
786fi
787
b6b0afdc
JN
788clean=no
789test_expect_success 'tests clean up after themselves' '
1b5b2b64 790 test_when_finished clean=yes
b6b0afdc
JN
791'
792
892e6f7e 793if test $clean != yes
b6b0afdc 794then
892e6f7e 795 say "bug in test framework: basic cleanup command does not work reliably"
b6b0afdc
JN
796 exit 1
797fi
798
892e6f7e 799test_expect_success 'tests clean up even on failures' "
565b6fa8
AS
800 test_must_fail run_sub_test_lib_test \
801 failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
1b5b2b64
SL
802 test_expect_success 'tests clean up even after a failure' '
803 touch clean-after-failure &&
804 test_when_finished rm clean-after-failure &&
805 (exit 1)
806 '
807 test_expect_success 'failure to clean up causes the test to fail' '
808 test_when_finished \"(exit 2)\"
809 '
810 test_done
1b5b2b64 811 EOF
565b6fa8 812 check_sub_test_lib_test failing-cleanup <<-\\EOF
5e5c006e 813 > not ok 1 - tests clean up even after a failure
1b5b2b64
SL
814 > # Z
815 > # touch clean-after-failure &&
816 > # test_when_finished rm clean-after-failure &&
817 > # (exit 1)
818 > # Z
5e5c006e 819 > not ok 2 - failure to clean up causes the test to fail
1b5b2b64
SL
820 > # Z
821 > # test_when_finished \"(exit 2)\"
822 > # Z
823 > # failed 2 among 2 test(s)
824 > 1..2
825 EOF
892e6f7e
ÆAB
826"
827
2c02b110 828test_expect_success 'test_oid setup' '
829 test_oid_init
830'
831
832test_expect_success 'test_oid provides sane info by default' '
833 test_oid zero >actual &&
834 grep "^00*\$" actual &&
835 rawsz="$(test_oid rawsz)" &&
836 hexsz="$(test_oid hexsz)" &&
837 test "$hexsz" -eq $(wc -c <actual) &&
838 test $(( $rawsz * 2)) -eq "$hexsz"
839'
840
841test_expect_success 'test_oid can look up data for SHA-1' '
842 test_when_finished "test_detect_hash" &&
843 test_set_hash sha1 &&
844 test_oid zero >actual &&
845 grep "^00*\$" actual &&
846 rawsz="$(test_oid rawsz)" &&
847 hexsz="$(test_oid hexsz)" &&
848 test $(wc -c <actual) -eq 40 &&
849 test "$rawsz" -eq 20 &&
850 test "$hexsz" -eq 40
851'
852
853test_expect_success 'test_oid can look up data for SHA-256' '
854 test_when_finished "test_detect_hash" &&
855 test_set_hash sha256 &&
856 test_oid zero >actual &&
857 grep "^00*\$" actual &&
858 rawsz="$(test_oid rawsz)" &&
859 hexsz="$(test_oid hexsz)" &&
860 test $(wc -c <actual) -eq 64 &&
861 test "$rawsz" -eq 32 &&
862 test "$hexsz" -eq 64
863'
864
e1970ce4
JH
865################################################################
866# Basics of the basics
867
e483e144 868test_oid_cache <<\EOF
869path0f sha1:f87290f8eb2cbbea7857214459a0739927eab154
870path0f sha256:638106af7c38be056f3212cbd7ac65bc1bac74f420ca5a436ff006a9d025d17d
871
872path0s sha1:15a98433ae33114b085f3eb3bb03b832b3180a01
873path0s sha256:3a24cc53cf68edddac490bbf94a418a52932130541361f685df685e41dd6c363
874
875path2f sha1:3feff949ed00a62d9f7af97c15cd8a30595e7ac7
876path2f sha256:2a7f36571c6fdbaf0e3f62751a0b25a3f4c54d2d1137b3f4af9cb794bb498e5f
877
878path2s sha1:d8ce161addc5173867a3c3c730924388daedbc38
879path2s sha256:18fd611b787c2e938ddcc248fabe4d66a150f9364763e9ec133dd01d5bb7c65a
880
881path2d sha1:58a09c23e2ca152193f2786e06986b7b6712bdbe
882path2d sha256:00e4b32b96e7e3d65d79112dcbea53238a22715f896933a62b811377e2650c17
883
884path3f sha1:0aa34cae68d0878578ad119c86ca2b5ed5b28376
885path3f sha256:09f58616b951bd571b8cb9dc76d372fbb09ab99db2393f5ab3189d26c45099ad
886
887path3s sha1:8599103969b43aff7e430efea79ca4636466794f
888path3s sha256:fce1aed087c053306f3f74c32c1a838c662bbc4551a7ac2420f5d6eb061374d0
889
890path3d sha1:21ae8269cacbe57ae09138dcc3a2887f904d02b3
891path3d sha256:9b60497be959cb830bf3f0dc82bcc9ad9e925a24e480837ade46b2295e47efe1
892
893subp3f sha1:00fb5908cb97c2564a9783c0c64087333b3b464f
894subp3f sha256:a1a9e16998c988453f18313d10375ee1d0ddefe757e710dcae0d66aa1e0c58b3
895
896subp3s sha1:6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
897subp3s sha256:81759d9f5e93c6546ecfcadb560c1ff057314b09f93fe8ec06e2d8610d34ef10
898
899subp3d sha1:3c5e5399f3a333eddecce7a9b9465b63f65f51e2
900subp3d sha256:76b4ef482d4fa1c754390344cf3851c7f883b27cf9bc999c6547928c46aeafb7
901
902root sha1:087704a96baf1c2d1c869a8b084481e121c88b5b
903root sha256:9481b52abab1b2ffeedbf9de63ce422b929f179c1b98ff7bee5f8f1bc0710751
904
905simpletree sha1:7bb943559a305bdd6bdee2cef6e5df2413c3d30a
906simpletree sha256:1710c07a6c86f9a3c7376364df04c47ee39e5a5e221fcdd84b743bc9bb7e2bc5
907EOF
908
e1970ce4 909# updating a new file without --add should fail.
1b5b2b64
SL
910test_expect_success 'git update-index without --add should fail adding' '
911 test_must_fail git update-index should-be-empty
41ac414e 912'
e1970ce4
JH
913
914# and with --add it should succeed, even if it is empty (it used to fail).
1b5b2b64
SL
915test_expect_success 'git update-index with --add should succeed' '
916 git update-index --add should-be-empty
917'
e1970ce4 918
1b5b2b64
SL
919test_expect_success 'writing tree out with git write-tree' '
920 tree=$(git write-tree)
921'
e1970ce4
JH
922
923# we know the shape and contents of the tree and know the object ID for it.
e483e144 924test_expect_success 'validate object ID of a known tree' '
925 test "$tree" = "$(test_oid simpletree)"
1b5b2b64 926 '
e1970ce4
JH
927
928# Removing paths.
1b5b2b64
SL
929test_expect_success 'git update-index without --remove should fail removing' '
930 rm -f should-be-empty full-of-directories &&
931 test_must_fail git update-index should-be-empty
41ac414e 932'
e1970ce4 933
1b5b2b64
SL
934test_expect_success 'git update-index with --remove should be able to remove' '
935 git update-index --remove should-be-empty
936'
e1970ce4
JH
937
938# Empty tree can be written with recent write-tree.
1b5b2b64
SL
939test_expect_success 'git write-tree should be able to write an empty tree' '
940 tree=$(git write-tree)
941'
e1970ce4 942
1b5b2b64 943test_expect_success 'validate object ID of a known tree' '
f9e7d9f8 944 test "$tree" = $EMPTY_TREE
1b5b2b64 945'
e1970ce4
JH
946
947# Various types of objects
1b5b2b64 948
1b5b2b64
SL
949test_expect_success 'adding various types of objects with git update-index --add' '
950 mkdir path2 path3 path3/subp3 &&
951 paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
952 (
953 for p in $paths
954 do
955 echo "hello $p" >$p || exit 1
c723a76d 956 test_ln_s_add "hello $p" ${p}sym || exit 1
1b5b2b64
SL
957 done
958 ) &&
959 find path* ! -type d -print | xargs git update-index --add
960'
e1970ce4
JH
961
962# Show them and see that matches what we expect.
1b5b2b64
SL
963test_expect_success 'showing stage with git ls-files --stage' '
964 git ls-files --stage >current
965'
966
e483e144 967test_expect_success 'validate git ls-files output for a known tree' '
968 cat >expected <<-EOF &&
969 100644 $(test_oid path0f) 0 path0
970 120000 $(test_oid path0s) 0 path0sym
971 100644 $(test_oid path2f) 0 path2/file2
972 120000 $(test_oid path2s) 0 path2/file2sym
973 100644 $(test_oid path3f) 0 path3/file3
974 120000 $(test_oid path3s) 0 path3/file3sym
975 100644 $(test_oid subp3f) 0 path3/subp3/file3
976 120000 $(test_oid subp3s) 0 path3/subp3/file3sym
1b5b2b64
SL
977 EOF
978 test_cmp expected current
979'
980
981test_expect_success 'writing tree out with git write-tree' '
982 tree=$(git write-tree)
983'
984
e483e144 985test_expect_success 'validate object ID for a known tree' '
986 test "$tree" = "$(test_oid root)"
1b5b2b64
SL
987'
988
989test_expect_success 'showing tree with git ls-tree' '
990 git ls-tree $tree >current
991'
992
e483e144 993test_expect_success 'git ls-tree output for a known tree' '
994 cat >expected <<-EOF &&
995 100644 blob $(test_oid path0f) path0
996 120000 blob $(test_oid path0s) path0sym
997 040000 tree $(test_oid path2d) path2
998 040000 tree $(test_oid path3d) path3
1b5b2b64
SL
999 EOF
1000 test_cmp expected current
1001'
e1970ce4 1002
246cc52f
JH
1003# This changed in ls-tree pathspec change -- recursive does
1004# not show tree nodes anymore.
1b5b2b64
SL
1005test_expect_success 'showing tree with git ls-tree -r' '
1006 git ls-tree -r $tree >current
1007'
1008
e483e144 1009test_expect_success 'git ls-tree -r output for a known tree' '
1010 cat >expected <<-EOF &&
1011 100644 blob $(test_oid path0f) path0
1012 120000 blob $(test_oid path0s) path0sym
1013 100644 blob $(test_oid path2f) path2/file2
1014 120000 blob $(test_oid path2s) path2/file2sym
1015 100644 blob $(test_oid path3f) path3/file3
1016 120000 blob $(test_oid path3s) path3/file3sym
1017 100644 blob $(test_oid subp3f) path3/subp3/file3
1018 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1b5b2b64
SL
1019 EOF
1020 test_cmp expected current
1021'
e1970ce4 1022
fdeb6bf5 1023# But with -r -t we can have both.
1b5b2b64
SL
1024test_expect_success 'showing tree with git ls-tree -r -t' '
1025 git ls-tree -r -t $tree >current
1026'
3d12d0cf 1027
e483e144 1028test_expect_success 'git ls-tree -r output for a known tree' '
1029 cat >expected <<-EOF &&
1030 100644 blob $(test_oid path0f) path0
1031 120000 blob $(test_oid path0s) path0sym
1032 040000 tree $(test_oid path2d) path2
1033 100644 blob $(test_oid path2f) path2/file2
1034 120000 blob $(test_oid path2s) path2/file2sym
1035 040000 tree $(test_oid path3d) path3
1036 100644 blob $(test_oid path3f) path3/file3
1037 120000 blob $(test_oid path3s) path3/file3sym
1038 040000 tree $(test_oid subp3d) path3/subp3
1039 100644 blob $(test_oid subp3f) path3/subp3/file3
1040 120000 blob $(test_oid subp3s) path3/subp3/file3sym
1b5b2b64
SL
1041 EOF
1042 test_cmp expected current
1043'
3d12d0cf 1044
1b5b2b64
SL
1045test_expect_success 'writing partial tree out with git write-tree --prefix' '
1046 ptree=$(git write-tree --prefix=path3)
41ac414e 1047'
3d12d0cf 1048
e483e144 1049test_expect_success 'validate object ID for a known tree' '
1050 test "$ptree" = $(test_oid path3d)
1b5b2b64
SL
1051'
1052
1053test_expect_success 'writing partial tree out with git write-tree --prefix' '
1054 ptree=$(git write-tree --prefix=path3/subp3)
1055'
1056
e483e144 1057test_expect_success 'validate object ID for a known tree' '
1058 test "$ptree" = $(test_oid subp3d)
1b5b2b64
SL
1059'
1060
1061test_expect_success 'put invalid objects into the index' '
1062 rm -f .git/index &&
cdd1e17f 1063 suffix=$(echo $ZERO_OID | sed -e "s/^.//") &&
1064 cat >badobjects <<-EOF &&
1065 100644 blob $(test_oid 001) dir/file1
1066 100644 blob $(test_oid 002) dir/file2
1067 100644 blob $(test_oid 003) dir/file3
1068 100644 blob $(test_oid 004) dir/file4
1069 100644 blob $(test_oid 005) dir/file5
1b5b2b64
SL
1070 EOF
1071 git update-index --index-info <badobjects
1072'
1073
1074test_expect_success 'writing this tree without --missing-ok' '
1075 test_must_fail git write-tree
1076'
1077
1078test_expect_success 'writing this tree with --missing-ok' '
1079 git write-tree --missing-ok
1080'
3d12d0cf
JS
1081
1082
e1970ce4 1083################################################################
1b5b2b64 1084test_expect_success 'git read-tree followed by write-tree should be idempotent' '
99094a7a 1085 rm -f .git/index &&
1b5b2b64
SL
1086 git read-tree $tree &&
1087 test -f .git/index &&
1088 newtree=$(git write-tree) &&
1089 test "$newtree" = "$tree"
1090'
1091
e483e144 1092test_expect_success 'validate git diff-files output for a know cache/work tree state' '
1093 cat >expected <<EOF &&
1094:100644 100644 $(test_oid path0f) $ZERO_OID M path0
1095:120000 120000 $(test_oid path0s) $ZERO_OID M path0sym
1096:100644 100644 $(test_oid path2f) $ZERO_OID M path2/file2
1097:120000 120000 $(test_oid path2s) $ZERO_OID M path2/file2sym
1098:100644 100644 $(test_oid path3f) $ZERO_OID M path3/file3
1099:120000 120000 $(test_oid path3s) $ZERO_OID M path3/file3sym
1100:100644 100644 $(test_oid subp3f) $ZERO_OID M path3/subp3/file3
1101:120000 120000 $(test_oid subp3s) $ZERO_OID M path3/subp3/file3sym
e1970ce4 1102EOF
1b5b2b64 1103 git diff-files >current &&
dcbaa0b3 1104 test_cmp expected current
1b5b2b64 1105'
e1970ce4 1106
1b5b2b64
SL
1107test_expect_success 'git update-index --refresh should succeed' '
1108 git update-index --refresh
1109'
e1970ce4 1110
1b5b2b64
SL
1111test_expect_success 'no diff after checkout and git update-index --refresh' '
1112 git diff-files >current &&
1113 cmp -s current /dev/null
1114'
e1970ce4 1115
9af0b8db 1116################################################################
e483e144 1117P=$(test_oid root)
1b5b2b64 1118
e483e144 1119test_expect_success 'git commit-tree records the correct tree in a commit' '
1b5b2b64
SL
1120 commit0=$(echo NO | git commit-tree $P) &&
1121 tree=$(git show --pretty=raw $commit0 |
1122 sed -n -e "s/^tree //p" -e "/^author /q") &&
1123 test "z$tree" = "z$P"
1124'
1125
e483e144 1126test_expect_success 'git commit-tree records the correct parent in a commit' '
1b5b2b64
SL
1127 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
1128 parent=$(git show --pretty=raw $commit1 |
1129 sed -n -e "s/^parent //p" -e "/^author /q") &&
1130 test "z$commit0" = "z$parent"
1131'
1132
e483e144 1133test_expect_success 'git commit-tree omits duplicated parent in a commit' '
1b5b2b64
SL
1134 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
1135 parent=$(git show --pretty=raw $commit2 |
1136 sed -n -e "s/^parent //p" -e "/^author /q" |
1137 sort -u) &&
1138 test "z$commit0" = "z$parent" &&
1139 numparent=$(git show --pretty=raw $commit2 |
1140 sed -n -e "s/^parent //p" -e "/^author /q" |
1141 wc -l) &&
1142 test $numparent = 1
1143'
9af0b8db 1144
81a361be
JH
1145test_expect_success 'update-index D/F conflict' '
1146 mv path0 tmp &&
1147 mv path2 path0 &&
1148 mv tmp path2 &&
1149 git update-index --add --replace path2 path0/file2 &&
1150 numpath0=$(git ls-files path0 | wc -l) &&
1151 test $numpath0 = 1
1152'
1153
7fec10b7
JH
1154test_expect_success 'very long name in the index handled sanely' '
1155
1156 a=a && # 1
1157 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
1158 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
1159 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
1160 a=${a}q &&
1161
1162 >path4 &&
1163 git update-index --add path4 &&
1164 (
1165 git ls-files -s path4 |
1166 sed -e "s/ .*/ /" |
75651fd7 1167 tr -d "\012" &&
7fec10b7
JH
1168 echo "$a"
1169 ) | git update-index --index-info &&
1170 len=$(git ls-files "a*" | wc -c) &&
1171 test $len = 4098
1172'
1173
e1970ce4 1174test_done