tests: paint unexpectedly fixed known breakages in bold red
[git.git] / t / t0000-basic.sh
blob8973d2ccc8406bb55ae771a2a1a2b136f7159891
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Test the very basics part #1.
8 The rest of the test suite does not check the basic operation of git
9 plumbing commands to work very carefully. Their job is to concentrate
10 on tricky features that caused bugs in the past to detect regression.
12 This test runs very basic features, like registering things in cache,
13 writing tree, etc.
15 Note that this test *deliberately* hard-codes many expected object
16 IDs. When object ID computation changes, like in the previous case of
17 swapping compression and hashing order, the person who is making the
18 modification *should* take notice and update the test vectors here.
21 ################################################################
22 # It appears that people try to run tests without building...
24 ../git >/dev/null
25 if test $? != 1
26 then
27 echo >&2 'You do not seem to have built git yet.'
28 exit 1
31 . ./test-lib.sh
33 ################################################################
34 # git init has been done in an empty repository.
35 # make sure it is empty.
37 test_expect_success '.git/objects should be empty after git init in an empty repo' '
38 find .git/objects -type f -print >should-be-empty &&
39 test_line_count = 0 should-be-empty
42 # also it should have 2 subdirectories; no fan-out anymore, pack, and info.
43 # 3 is counting "objects" itself
44 test_expect_success '.git/objects should have 3 subdirectories' '
45 find .git/objects -type d -print >full-of-directories &&
46 test_line_count = 3 full-of-directories
49 ################################################################
50 # Test harness
51 test_expect_success 'success is reported like this' '
54 test_expect_failure 'pretend we have a known breakage' '
55 false
58 run_sub_test_lib_test () {
59 name="$1" descr="$2" # stdin is the body of the test code
60 mkdir "$name" &&
62 cd "$name" &&
63 cat >"$name.sh" <<-EOF &&
64 #!$SHELL_PATH
66 test_description='$descr (run in sub test-lib)
68 This is run in a sub test-lib so that we do not get incorrect
69 passing metrics
72 # Point to the t/test-lib.sh, which isn't in ../ as usual
73 . "\$TEST_DIRECTORY"/test-lib.sh
74 EOF
75 cat >>"$name.sh" &&
76 chmod +x "$name.sh" &&
77 export TEST_DIRECTORY &&
78 ./"$name.sh" >out 2>err
82 check_sub_test_lib_test () {
83 name="$1" # stdin is the expected output from the test
85 cd "$name" &&
86 ! test -s err &&
87 sed -e 's/^> //' -e 's/Z$//' >expect &&
88 test_cmp expect out
92 test_expect_success 'pretend we have a fully passing test suite' "
93 run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF &&
94 for i in 1 2 3
96 test_expect_success \"passing test #\$i\" 'true'
97 done
98 test_done
99 EOF
100 check_sub_test_lib_test full-pass <<-\\EOF
101 > ok 1 - passing test #1
102 > ok 2 - passing test #2
103 > ok 3 - passing test #3
104 > # passed all 3 test(s)
105 > 1..3
109 test_expect_success 'pretend we have a partially passing test suite' "
110 test_must_fail run_sub_test_lib_test \
111 partial-pass '2/3 tests passing' <<-\\EOF &&
112 test_expect_success 'passing test #1' 'true'
113 test_expect_success 'failing test #2' 'false'
114 test_expect_success 'passing test #3' 'true'
115 test_done
117 check_sub_test_lib_test partial-pass <<-\\EOF
118 > ok 1 - passing test #1
119 > not ok 2 - failing test #2
120 # false
121 > ok 3 - passing test #3
122 > # failed 1 among 3 test(s)
123 > 1..3
127 test_expect_success 'pretend we have a known breakage' "
128 run_sub_test_lib_test failing-todo 'A failing TODO test' <<-\\EOF &&
129 test_expect_success 'passing test' 'true'
130 test_expect_failure 'pretend we have a known breakage' 'false'
131 test_done
133 check_sub_test_lib_test failing-todo <<-\\EOF
134 > ok 1 - passing test
135 > not ok 2 - pretend we have a known breakage # TODO known breakage
136 > # still have 1 known breakage(s)
137 > # passed all remaining 1 test(s)
138 > 1..2
142 test_expect_success 'pretend we have fixed a known breakage' "
143 run_sub_test_lib_test passing-todo 'A passing TODO test' <<-\\EOF &&
144 test_expect_failure 'pretend we have fixed a known breakage' 'true'
145 test_done
147 check_sub_test_lib_test passing-todo <<-\\EOF
148 > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished
149 > # 1 known breakage(s) vanished; please update test(s)
150 > 1..1
154 test_expect_success 'pretend we have fixed one of two known breakages (run in sub test-lib)' "
155 run_sub_test_lib_test partially-passing-todos \
156 '2 TODO tests, one passing' <<-\\EOF &&
157 test_expect_failure 'pretend we have a known breakage' 'false'
158 test_expect_success 'pretend we have a passing test' 'true'
159 test_expect_failure 'pretend we have fixed another known breakage' 'true'
160 test_done
162 check_sub_test_lib_test partially-passing-todos <<-\\EOF
163 > not ok 1 - pretend we have a known breakage # TODO known breakage
164 > ok 2 - pretend we have a passing test
165 > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished
166 > # 1 known breakage(s) vanished; please update test(s)
167 > # still have 1 known breakage(s)
168 > # passed all remaining 1 test(s)
169 > 1..3
173 test_expect_success 'pretend we have a pass, fail, and known breakage' "
174 test_must_fail run_sub_test_lib_test \
175 mixed-results1 'mixed results #1' <<-\\EOF &&
176 test_expect_success 'passing test' 'true'
177 test_expect_success 'failing test' 'false'
178 test_expect_failure 'pretend we have a known breakage' 'false'
179 test_done
181 check_sub_test_lib_test mixed-results1 <<-\\EOF
182 > ok 1 - passing test
183 > not ok 2 - failing test
184 > # false
185 > not ok 3 - pretend we have a known breakage # TODO known breakage
186 > # still have 1 known breakage(s)
187 > # failed 1 among remaining 2 test(s)
188 > 1..3
192 test_expect_success 'pretend we have a mix of all possible results' "
193 test_must_fail run_sub_test_lib_test \
194 mixed-results2 'mixed results #2' <<-\\EOF &&
195 test_expect_success 'passing test' 'true'
196 test_expect_success 'passing test' 'true'
197 test_expect_success 'passing test' 'true'
198 test_expect_success 'passing test' 'true'
199 test_expect_success 'failing test' 'false'
200 test_expect_success 'failing test' 'false'
201 test_expect_success 'failing test' 'false'
202 test_expect_failure 'pretend we have a known breakage' 'false'
203 test_expect_failure 'pretend we have a known breakage' 'false'
204 test_expect_failure 'pretend we have fixed a known breakage' 'true'
205 test_done
207 check_sub_test_lib_test mixed-results2 <<-\\EOF
208 > ok 1 - passing test
209 > ok 2 - passing test
210 > ok 3 - passing test
211 > ok 4 - passing test
212 > not ok 5 - failing test
213 > # false
214 > not ok 6 - failing test
215 > # false
216 > not ok 7 - failing test
217 > # false
218 > not ok 8 - pretend we have a known breakage # TODO known breakage
219 > not ok 9 - pretend we have a known breakage # TODO known breakage
220 > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished
221 > # 1 known breakage(s) vanished; please update test(s)
222 > # still have 2 known breakage(s)
223 > # failed 3 among remaining 7 test(s)
224 > 1..10
228 test_set_prereq HAVEIT
229 haveit=no
230 test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
231 test_have_prereq HAVEIT &&
232 haveit=yes
234 donthaveit=yes
235 test_expect_success DONTHAVEIT 'unmet prerequisite causes test to be skipped' '
236 donthaveit=no
238 if test $haveit$donthaveit != yesyes
239 then
240 say "bug in test framework: prerequisite tags do not work reliably"
241 exit 1
244 test_set_prereq HAVETHIS
245 haveit=no
246 test_expect_success HAVETHIS,HAVEIT 'test runs if prerequisites are satisfied' '
247 test_have_prereq HAVEIT &&
248 test_have_prereq HAVETHIS &&
249 haveit=yes
251 donthaveit=yes
252 test_expect_success HAVEIT,DONTHAVEIT 'unmet prerequisites causes test to be skipped' '
253 donthaveit=no
255 donthaveiteither=yes
256 test_expect_success DONTHAVEIT,HAVEIT 'unmet prerequisites causes test to be skipped' '
257 donthaveiteither=no
259 if test $haveit$donthaveit$donthaveiteither != yesyesyes
260 then
261 say "bug in test framework: multiple prerequisite tags do not work reliably"
262 exit 1
265 clean=no
266 test_expect_success 'tests clean up after themselves' '
267 test_when_finished clean=yes
270 if test $clean != yes
271 then
272 say "bug in test framework: basic cleanup command does not work reliably"
273 exit 1
276 test_expect_success 'tests clean up even on failures' "
277 test_must_fail run_sub_test_lib_test \
278 failing-cleanup 'Failing tests with cleanup commands' <<-\\EOF &&
279 test_expect_success 'tests clean up even after a failure' '
280 touch clean-after-failure &&
281 test_when_finished rm clean-after-failure &&
282 (exit 1)
284 test_expect_success 'failure to clean up causes the test to fail' '
285 test_when_finished \"(exit 2)\"
287 test_done
289 check_sub_test_lib_test failing-cleanup <<-\\EOF
290 > not ok 1 - tests clean up even after a failure
291 > # Z
292 > # touch clean-after-failure &&
293 > # test_when_finished rm clean-after-failure &&
294 > # (exit 1)
295 > # Z
296 > not ok 2 - failure to clean up causes the test to fail
297 > # Z
298 > # test_when_finished \"(exit 2)\"
299 > # Z
300 > # failed 2 among 2 test(s)
301 > 1..2
305 ################################################################
306 # Basics of the basics
308 # updating a new file without --add should fail.
309 test_expect_success 'git update-index without --add should fail adding' '
310 test_must_fail git update-index should-be-empty
313 # and with --add it should succeed, even if it is empty (it used to fail).
314 test_expect_success 'git update-index with --add should succeed' '
315 git update-index --add should-be-empty
318 test_expect_success 'writing tree out with git write-tree' '
319 tree=$(git write-tree)
322 # we know the shape and contents of the tree and know the object ID for it.
323 test_expect_success 'validate object ID of a known tree' '
324 test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a
327 # Removing paths.
328 test_expect_success 'git update-index without --remove should fail removing' '
329 rm -f should-be-empty full-of-directories &&
330 test_must_fail git update-index should-be-empty
333 test_expect_success 'git update-index with --remove should be able to remove' '
334 git update-index --remove should-be-empty
337 # Empty tree can be written with recent write-tree.
338 test_expect_success 'git write-tree should be able to write an empty tree' '
339 tree=$(git write-tree)
342 test_expect_success 'validate object ID of a known tree' '
343 test "$tree" = 4b825dc642cb6eb9a060e54bf8d69288fbee4904
346 # Various types of objects
348 # Some filesystems do not support symblic links; on such systems
349 # some expected values are different
350 if test_have_prereq SYMLINKS
351 then
352 expectfilter=cat
353 expectedtree=087704a96baf1c2d1c869a8b084481e121c88b5b
354 expectedptree1=21ae8269cacbe57ae09138dcc3a2887f904d02b3
355 expectedptree2=3c5e5399f3a333eddecce7a9b9465b63f65f51e2
356 else
357 expectfilter='grep -v sym'
358 expectedtree=8e18edf7d7edcf4371a3ac6ae5f07c2641db7c46
359 expectedptree1=cfb8591b2f65de8b8cc1020cd7d9e67e7793b325
360 expectedptree2=ce580448f0148b985a513b693fdf7d802cacb44f
364 test_expect_success 'adding various types of objects with git update-index --add' '
365 mkdir path2 path3 path3/subp3 &&
366 paths="path0 path2/file2 path3/file3 path3/subp3/file3" &&
368 for p in $paths
370 echo "hello $p" >$p || exit 1
371 if test_have_prereq SYMLINKS
372 then
373 ln -s "hello $p" ${p}sym || exit 1
375 done
376 ) &&
377 find path* ! -type d -print | xargs git update-index --add
380 # Show them and see that matches what we expect.
381 test_expect_success 'showing stage with git ls-files --stage' '
382 git ls-files --stage >current
385 test_expect_success 'validate git ls-files output for a known tree' '
386 $expectfilter >expected <<-\EOF &&
387 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
388 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
389 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
390 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
391 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
392 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
393 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
394 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
396 test_cmp expected current
399 test_expect_success 'writing tree out with git write-tree' '
400 tree=$(git write-tree)
403 test_expect_success 'validate object ID for a known tree' '
404 test "$tree" = "$expectedtree"
407 test_expect_success 'showing tree with git ls-tree' '
408 git ls-tree $tree >current
411 test_expect_success SYMLINKS 'git ls-tree output for a known tree' '
412 cat >expected <<-\EOF &&
413 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
414 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
415 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
416 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
418 test_cmp expected current
421 # This changed in ls-tree pathspec change -- recursive does
422 # not show tree nodes anymore.
423 test_expect_success 'showing tree with git ls-tree -r' '
424 git ls-tree -r $tree >current
427 test_expect_success 'git ls-tree -r output for a known tree' '
428 $expectfilter >expected <<-\EOF &&
429 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
430 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
431 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
432 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
433 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
434 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
435 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
436 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
438 test_cmp expected current
441 # But with -r -t we can have both.
442 test_expect_success 'showing tree with git ls-tree -r -t' '
443 git ls-tree -r -t $tree >current
446 test_expect_success SYMLINKS 'git ls-tree -r output for a known tree' '
447 cat >expected <<-\EOF &&
448 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
449 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
450 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
451 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
452 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
453 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
454 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
455 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
456 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
457 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
458 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
460 test_cmp expected current
463 test_expect_success 'writing partial tree out with git write-tree --prefix' '
464 ptree=$(git write-tree --prefix=path3)
467 test_expect_success 'validate object ID for a known tree' '
468 test "$ptree" = "$expectedptree1"
471 test_expect_success 'writing partial tree out with git write-tree --prefix' '
472 ptree=$(git write-tree --prefix=path3/subp3)
475 test_expect_success 'validate object ID for a known tree' '
476 test "$ptree" = "$expectedptree2"
479 test_expect_success 'put invalid objects into the index' '
480 rm -f .git/index &&
481 cat >badobjects <<-\EOF &&
482 100644 blob 1000000000000000000000000000000000000000 dir/file1
483 100644 blob 2000000000000000000000000000000000000000 dir/file2
484 100644 blob 3000000000000000000000000000000000000000 dir/file3
485 100644 blob 4000000000000000000000000000000000000000 dir/file4
486 100644 blob 5000000000000000000000000000000000000000 dir/file5
488 git update-index --index-info <badobjects
491 test_expect_success 'writing this tree without --missing-ok' '
492 test_must_fail git write-tree
495 test_expect_success 'writing this tree with --missing-ok' '
496 git write-tree --missing-ok
500 ################################################################
501 test_expect_success 'git read-tree followed by write-tree should be idempotent' '
502 rm -f .git/index
503 git read-tree $tree &&
504 test -f .git/index &&
505 newtree=$(git write-tree) &&
506 test "$newtree" = "$tree"
509 test_expect_success 'validate git diff-files output for a know cache/work tree state' '
510 $expectfilter >expected <<\EOF &&
511 :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
512 :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
513 :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
514 :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym
515 :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3
516 :120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym
517 :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
518 :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
520 git diff-files >current &&
521 test_cmp current expected
524 test_expect_success 'git update-index --refresh should succeed' '
525 git update-index --refresh
528 test_expect_success 'no diff after checkout and git update-index --refresh' '
529 git diff-files >current &&
530 cmp -s current /dev/null
533 ################################################################
534 P=$expectedtree
536 test_expect_success 'git commit-tree records the correct tree in a commit' '
537 commit0=$(echo NO | git commit-tree $P) &&
538 tree=$(git show --pretty=raw $commit0 |
539 sed -n -e "s/^tree //p" -e "/^author /q") &&
540 test "z$tree" = "z$P"
543 test_expect_success 'git commit-tree records the correct parent in a commit' '
544 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
545 parent=$(git show --pretty=raw $commit1 |
546 sed -n -e "s/^parent //p" -e "/^author /q") &&
547 test "z$commit0" = "z$parent"
550 test_expect_success 'git commit-tree omits duplicated parent in a commit' '
551 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
552 parent=$(git show --pretty=raw $commit2 |
553 sed -n -e "s/^parent //p" -e "/^author /q" |
554 sort -u) &&
555 test "z$commit0" = "z$parent" &&
556 numparent=$(git show --pretty=raw $commit2 |
557 sed -n -e "s/^parent //p" -e "/^author /q" |
558 wc -l) &&
559 test $numparent = 1
562 test_expect_success 'update-index D/F conflict' '
563 mv path0 tmp &&
564 mv path2 path0 &&
565 mv tmp path2 &&
566 git update-index --add --replace path2 path0/file2 &&
567 numpath0=$(git ls-files path0 | wc -l) &&
568 test $numpath0 = 1
571 test_expect_success 'very long name in the index handled sanely' '
573 a=a && # 1
574 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16
575 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256
576 a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096
577 a=${a}q &&
579 >path4 &&
580 git update-index --add path4 &&
582 git ls-files -s path4 |
583 sed -e "s/ .*/ /" |
584 tr -d "\012"
585 echo "$a"
586 ) | git update-index --index-info &&
587 len=$(git ls-files "a*" | wc -c) &&
588 test $len = 4098
591 test_done