Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t0000-basic.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t0000-basic.sh` 1253 lines ยท 36975 bytes Raw Blame History 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 . "$TEST_DIRECTORY"/lib-subtest.sh 23 24 try_local_xy () { 25 local x="local" y="alsolocal" && 26 echo "$x $y" 27 } 28 29 # Check whether the shell supports the "local" keyword. "local" is not 30 # POSIX-standard, but it is very widely supported by POSIX-compliant 31 # shells, and we rely on it within Git's test framework. 32 # 33 # If your shell fails this test, the results of other tests may be 34 # unreliable. You may wish to report the problem to the Git mailing 35 # list , as it could cause us to reconsider 36 # relying on "local". 37 test_expect_success 'verify that the running shell supports "local"' ' 38 x="notlocal" && 39 y="alsonotlocal" && 40 echo "local alsolocal" >expected1 && 41 try_local_xy >actual1 && 42 test_cmp expected1 actual1 && 43 echo "notlocal alsonotlocal" >expected2 && 44 echo "$x $y" >actual2 && 45 test_cmp expected2 actual2 46 ' 47 48 ################################################################ 49 # git init has been done in an empty repository. 50 # make sure it is empty. 51 52 test_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 ' 56 57 # also it should have 2 subdirectories; no fan-out anymore, pack, and info. 58 # 3 is counting "objects" itself 59 test_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 ' 63 64 ################################################################ 65 # Test harness 66 test_expect_success 'success is reported like this' ' 67 : 68 ' 69 70 test_expect_success 'subtest: 3 passing tests' ' 71 write_and_run_sub_test_lib_test full-pass <<-\EOF && 72 for i in 1 2 3 73 do 74 test_expect_success "passing test #$i" "true" 75 done 76 test_done 77 EOF 78 check_sub_test_lib_test full-pass <<-\EOF 79 > ok 1 - passing test #1 80 > ok 2 - passing test #2 81 > ok 3 - passing test #3 82 > # passed all 3 test(s) 83 > 1..3 84 EOF 85 ' 86 87 test_expect_success 'subtest: 2/3 tests passing' ' 88 write_and_run_sub_test_lib_test_err partial-pass <<-\EOF && 89 test_expect_success "passing test #1" "true" 90 test_expect_success "failing test #2" "false" 91 test_expect_success "passing test #3" "true" 92 test_done 93 EOF 94 check_sub_test_lib_test partial-pass <<-\EOF 95 > ok 1 - passing test #1 96 > not ok 2 - failing test #2 97 # false 98 > ok 3 - passing test #3 99 > # failed 1 among 3 test(s) 100 > 1..3 101 EOF 102 ' 103 104 test_expect_success 'subtest: --immediate' ' 105 run_sub_test_lib_test_err partial-pass \ 106 --immediate && 107 check_sub_test_lib_test_err partial-pass \ 108 <<-\EOF_OUT 3<<-EOF_ERR 109 > ok 1 - passing test #1 110 > not ok 2 - failing test #2 111 > # false 112 > 1..2 113 EOF_OUT 114 EOF_ERR 115 ' 116 117 test_expect_success 'subtest: a failing TODO test' ' 118 write_and_run_sub_test_lib_test failing-todo <<-\EOF && 119 test_expect_success "passing test" "true" 120 test_expect_failure "pretend we have a known breakage" "false" 121 test_done 122 EOF 123 check_sub_test_lib_test failing-todo <<-\EOF 124 > ok 1 - passing test 125 > not ok 2 - pretend we have a known breakage # TODO known breakage 126 > # still have 1 known breakage(s) 127 > # passed all remaining 1 test(s) 128 > 1..2 129 EOF 130 ' 131 132 test_expect_success 'subtest: a passing TODO test' ' 133 write_and_run_sub_test_lib_test_err passing-todo <<-\EOF && 134 test_expect_failure "pretend we have fixed a known breakage" "true" 135 test_done 136 EOF 137 check_sub_test_lib_test passing-todo <<-\EOF 138 > ok 1 - pretend we have fixed a known breakage # TODO known breakage vanished 139 > # 1 known breakage(s) vanished; please update test(s) 140 > 1..1 141 EOF 142 ' 143 144 test_expect_success 'subtest: 2 TODO tests, one passin' ' 145 write_and_run_sub_test_lib_test_err partially-passing-todos <<-\EOF && 146 test_expect_failure "pretend we have a known breakage" "false" 147 test_expect_success "pretend we have a passing test" "true" 148 test_expect_failure "pretend we have fixed another known breakage" "true" 149 test_done 150 EOF 151 check_sub_test_lib_test partially-passing-todos <<-\EOF 152 > not ok 1 - pretend we have a known breakage # TODO known breakage 153 > ok 2 - pretend we have a passing test 154 > ok 3 - pretend we have fixed another known breakage # TODO known breakage vanished 155 > # 1 known breakage(s) vanished; please update test(s) 156 > # still have 1 known breakage(s) 157 > # passed all remaining 1 test(s) 158 > 1..3 159 EOF 160 ' 161 162 test_expect_success 'subtest: mixed results: pass, failure and a TODO test' ' 163 write_and_run_sub_test_lib_test_err mixed-results1 <<-\EOF && 164 test_expect_success "passing test" "true" 165 test_expect_success "failing test" "false" 166 test_expect_failure "pretend we have a known breakage" "false" 167 test_done 168 EOF 169 check_sub_test_lib_test mixed-results1 <<-\EOF 170 > ok 1 - passing test 171 > not ok 2 - failing test 172 > # false 173 > not ok 3 - pretend we have a known breakage # TODO known breakage 174 > # still have 1 known breakage(s) 175 > # failed 1 among remaining 2 test(s) 176 > 1..3 177 EOF 178 ' 179 180 test_expect_success 'subtest: mixed results: a mixture of all possible results' ' 181 write_and_run_sub_test_lib_test_err mixed-results2 <<-\EOF && 182 test_expect_success "passing test" "true" 183 test_expect_success "passing test" "true" 184 test_expect_success "passing test" "true" 185 test_expect_success "passing test" "true" 186 test_expect_success "failing test" "false" 187 test_expect_success "failing test" "false" 188 test_expect_success "failing test" "false" 189 test_expect_failure "pretend we have a known breakage" "false" 190 test_expect_failure "pretend we have a known breakage" "false" 191 test_expect_failure "pretend we have fixed a known breakage" "true" 192 test_done 193 EOF 194 check_sub_test_lib_test mixed-results2 <<-\EOF 195 > ok 1 - passing test 196 > ok 2 - passing test 197 > ok 3 - passing test 198 > ok 4 - passing test 199 > not ok 5 - failing test 200 > # false 201 > not ok 6 - failing test 202 > # false 203 > not ok 7 - failing test 204 > # false 205 > not ok 8 - pretend we have a known breakage # TODO known breakage 206 > not ok 9 - pretend we have a known breakage # TODO known breakage 207 > ok 10 - pretend we have fixed a known breakage # TODO known breakage vanished 208 > # 1 known breakage(s) vanished; please update test(s) 209 > # still have 2 known breakage(s) 210 > # failed 3 among remaining 7 test(s) 211 > 1..10 212 EOF 213 ' 214 215 test_expect_success 'subtest: --verbose option' ' 216 write_and_run_sub_test_lib_test_err t1234-verbose --verbose <<-\EOF && 217 test_expect_success "passing test" true 218 test_expect_success "test with output" "echo foo" 219 test_expect_success "failing test" false 220 test_done 221 EOF 222 mv t1234-verbose/err t1234-verbose/err+ && 223 grep -v "^Initialized empty" t1234-verbose/err+ >t1234-verbose/err && 224 check_sub_test_lib_test_err t1234-verbose \ 225 <<-\EOF_OUT 3<<-\EOF_ERR 226 > ok 1 - passing test 227 > ok 2 - test with output 228 > not ok 3 - failing test 229 > # false 230 > # failed 1 among 3 test(s) 231 > 1..3 232 EOF_OUT 233 > expecting success of 1234.1 '\''passing test'\'': true 234 > Z 235 > expecting success of 1234.2 '\''test with output'\'': echo foo 236 > foo 237 > Z 238 > expecting success of 1234.3 '\''failing test'\'': false 239 > Z 240 EOF_ERR 241 ' 242 243 test_expect_success 'subtest: --verbose-only option' ' 244 run_sub_test_lib_test_err \ 245 t1234-verbose \ 246 --verbose-only=2 && 247 check_sub_test_lib_test_err t1234-verbose <<-\EOF_OUT 3<<-\EOF_ERR 248 > ok 1 - passing test 249 > ok 2 - test with output 250 > not ok 3 - failing test 251 > # false 252 > # failed 1 among 3 test(s) 253 > 1..3 254 EOF_OUT 255 > Z 256 > expecting success of 1234.2 '\''test with output'\'': echo foo 257 > foo 258 > Z 259 EOF_ERR 260 ' 261 262 test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' ' 263 ( 264 run_sub_test_lib_test full-pass \ 265 --skip="full.2" && 266 check_sub_test_lib_test full-pass <<-\EOF 267 > ok 1 - passing test #1 268 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) 269 > ok 3 - passing test #3 270 > # passed all 3 test(s) 271 > 1..3 272 EOF 273 ) 274 ' 275 276 test_expect_success 'subtest: skip several with GIT_SKIP_TESTS' ' 277 ( 278 write_and_run_sub_test_lib_test git-skip-tests-several \ 279 --skip="git.2 git.5" <<-\EOF && 280 for i in 1 2 3 4 5 6 281 do 282 test_expect_success "passing test #$i" "true" 283 done 284 test_done 285 EOF 286 check_sub_test_lib_test git-skip-tests-several <<-\EOF 287 > ok 1 - passing test #1 288 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) 289 > ok 3 - passing test #3 290 > ok 4 - passing test #4 291 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS) 292 > ok 6 - passing test #6 293 > # passed all 6 test(s) 294 > 1..6 295 EOF 296 ) 297 ' 298 299 test_expect_success 'subtest: sh pattern skipping with GIT_SKIP_TESTS' ' 300 ( 301 run_sub_test_lib_test git-skip-tests-several \ 302 --skip="git.[2-5]" && 303 check_sub_test_lib_test git-skip-tests-several <<-\EOF 304 > ok 1 - passing test #1 305 > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) 306 > ok 3 # skip passing test #3 (GIT_SKIP_TESTS) 307 > ok 4 # skip passing test #4 (GIT_SKIP_TESTS) 308 > ok 5 # skip passing test #5 (GIT_SKIP_TESTS) 309 > ok 6 - passing test #6 310 > # passed all 6 test(s) 311 > 1..6 312 EOF 313 ) 314 ' 315 316 test_expect_success 'subtest: skip entire test suite with GIT_SKIP_TESTS' ' 317 ( 318 GIT_SKIP_TESTS="git" && export GIT_SKIP_TESTS && 319 run_sub_test_lib_test git-skip-tests-several \ 320 --skip="git" && 321 check_sub_test_lib_test git-skip-tests-several <<-\EOF 322 > 1..0 # SKIP skip all tests in git 323 EOF 324 ) 325 ' 326 327 test_expect_success 'subtest: GIT_SKIP_TESTS does not skip unmatched suite' ' 328 ( 329 GIT_SKIP_TESTS="notgit" && export GIT_SKIP_TESTS && 330 run_sub_test_lib_test full-pass \ 331 --skip="notfull" && 332 check_sub_test_lib_test full-pass <<-\EOF 333 > ok 1 - passing test #1 334 > ok 2 - passing test #2 335 > ok 3 - passing test #3 336 > # passed all 3 test(s) 337 > 1..3 338 EOF 339 ) 340 ' 341 342 test_expect_success 'subtest: --run basic' ' 343 run_sub_test_lib_test git-skip-tests-several --run="1,3,5" && 344 check_sub_test_lib_test git-skip-tests-several <<-\EOF 345 > ok 1 - passing test #1 346 > ok 2 # skip passing test #2 (--run) 347 > ok 3 - passing test #3 348 > ok 4 # skip passing test #4 (--run) 349 > ok 5 - passing test #5 350 > ok 6 # skip passing test #6 (--run) 351 > # passed all 6 test(s) 352 > 1..6 353 EOF 354 ' 355 356 test_expect_success 'subtest: --run with a range' ' 357 run_sub_test_lib_test git-skip-tests-several \ 358 --run="1-3" && 359 check_sub_test_lib_test git-skip-tests-several <<-\EOF 360 > ok 1 - passing test #1 361 > ok 2 - passing test #2 362 > ok 3 - passing test #3 363 > ok 4 # skip passing test #4 (--run) 364 > ok 5 # skip passing test #5 (--run) 365 > ok 6 # skip passing test #6 (--run) 366 > # passed all 6 test(s) 367 > 1..6 368 EOF 369 ' 370 371 test_expect_success 'subtest: --run with two ranges' ' 372 run_sub_test_lib_test git-skip-tests-several \ 373 --run="1-2,5-6" && 374 check_sub_test_lib_test git-skip-tests-several <<-\EOF 375 > ok 1 - passing test #1 376 > ok 2 - passing test #2 377 > ok 3 # skip passing test #3 (--run) 378 > ok 4 # skip passing test #4 (--run) 379 > ok 5 - passing test #5 380 > ok 6 - passing test #6 381 > # passed all 6 test(s) 382 > 1..6 383 EOF 384 ' 385 386 test_expect_success 'subtest: --run with a left open range' ' 387 run_sub_test_lib_test git-skip-tests-several \ 388 --run="-3" && 389 check_sub_test_lib_test git-skip-tests-several <<-\EOF 390 > ok 1 - passing test #1 391 > ok 2 - passing test #2 392 > ok 3 - passing test #3 393 > ok 4 # skip passing test #4 (--run) 394 > ok 5 # skip passing test #5 (--run) 395 > ok 6 # skip passing test #6 (--run) 396 > # passed all 6 test(s) 397 > 1..6 398 EOF 399 ' 400 401 test_expect_success 'subtest: --run with a right open range' ' 402 run_sub_test_lib_test git-skip-tests-several \ 403 --run="4-" && 404 check_sub_test_lib_test git-skip-tests-several <<-\EOF 405 > ok 1 # skip passing test #1 (--run) 406 > ok 2 # skip passing test #2 (--run) 407 > ok 3 # skip passing test #3 (--run) 408 > ok 4 - passing test #4 409 > ok 5 - passing test #5 410 > ok 6 - passing test #6 411 > # passed all 6 test(s) 412 > 1..6 413 EOF 414 ' 415 416 test_expect_success 'subtest: --run with basic negation' ' 417 run_sub_test_lib_test git-skip-tests-several \ 418 --run="!3" && 419 check_sub_test_lib_test git-skip-tests-several <<-\EOF 420 > ok 1 - passing test #1 421 > ok 2 - passing test #2 422 > ok 3 # skip passing test #3 (--run) 423 > ok 4 - passing test #4 424 > ok 5 - passing test #5 425 > ok 6 - passing test #6 426 > # passed all 6 test(s) 427 > 1..6 428 EOF 429 ' 430 431 test_expect_success 'subtest: --run with two negations' ' 432 run_sub_test_lib_test git-skip-tests-several \ 433 --run="!3,!6" && 434 check_sub_test_lib_test git-skip-tests-several <<-\EOF 435 > ok 1 - passing test #1 436 > ok 2 - passing test #2 437 > ok 3 # skip passing test #3 (--run) 438 > ok 4 - passing test #4 439 > ok 5 - passing test #5 440 > ok 6 # skip passing test #6 (--run) 441 > # passed all 6 test(s) 442 > 1..6 443 EOF 444 ' 445 446 test_expect_success 'subtest: --run a range and negation' ' 447 run_sub_test_lib_test git-skip-tests-several \ 448 --run="-4,!2" && 449 check_sub_test_lib_test git-skip-tests-several <<-\EOF 450 > ok 1 - passing test #1 451 > ok 2 # skip passing test #2 (--run) 452 > ok 3 - passing test #3 453 > ok 4 - passing test #4 454 > ok 5 # skip passing test #5 (--run) 455 > ok 6 # skip passing test #6 (--run) 456 > # passed all 6 test(s) 457 > 1..6 458 EOF 459 ' 460 461 test_expect_success 'subtest: --run range negation' ' 462 run_sub_test_lib_test git-skip-tests-several \ 463 --run="!1-3" && 464 check_sub_test_lib_test git-skip-tests-several <<-\EOF 465 > ok 1 # skip passing test #1 (--run) 466 > ok 2 # skip passing test #2 (--run) 467 > ok 3 # skip passing test #3 (--run) 468 > ok 4 - passing test #4 469 > ok 5 - passing test #5 470 > ok 6 - passing test #6 471 > # passed all 6 test(s) 472 > 1..6 473 EOF 474 ' 475 476 test_expect_success 'subtest: --run include, exclude and include' ' 477 run_sub_test_lib_test git-skip-tests-several \ 478 --run="1-5,!1-3,2" && 479 check_sub_test_lib_test git-skip-tests-several <<-\EOF 480 > ok 1 # skip passing test #1 (--run) 481 > ok 2 - passing test #2 482 > ok 3 # skip passing test #3 (--run) 483 > ok 4 - passing test #4 484 > ok 5 - passing test #5 485 > ok 6 # skip passing test #6 (--run) 486 > # passed all 6 test(s) 487 > 1..6 488 EOF 489 ' 490 491 test_expect_success 'subtest: --run include, exclude and include, comma separated' ' 492 run_sub_test_lib_test git-skip-tests-several \ 493 --run=1-5,!1-3,2 && 494 check_sub_test_lib_test git-skip-tests-several <<-\EOF 495 > ok 1 # skip passing test #1 (--run) 496 > ok 2 - passing test #2 497 > ok 3 # skip passing test #3 (--run) 498 > ok 4 - passing test #4 499 > ok 5 - passing test #5 500 > ok 6 # skip passing test #6 (--run) 501 > # passed all 6 test(s) 502 > 1..6 503 EOF 504 ' 505 506 test_expect_success 'subtest: --run exclude and include' ' 507 run_sub_test_lib_test git-skip-tests-several \ 508 --run="!3-,5" && 509 check_sub_test_lib_test git-skip-tests-several <<-\EOF 510 > ok 1 - passing test #1 511 > ok 2 - passing test #2 512 > ok 3 # skip passing test #3 (--run) 513 > ok 4 # skip passing test #4 (--run) 514 > ok 5 - passing test #5 515 > ok 6 # skip passing test #6 (--run) 516 > # passed all 6 test(s) 517 > 1..6 518 EOF 519 ' 520 521 test_expect_success 'subtest: --run empty selectors' ' 522 run_sub_test_lib_test git-skip-tests-several \ 523 --run="1,,3,,,5" && 524 check_sub_test_lib_test git-skip-tests-several <<-\EOF 525 > ok 1 - passing test #1 526 > ok 2 # skip passing test #2 (--run) 527 > ok 3 - passing test #3 528 > ok 4 # skip passing test #4 (--run) 529 > ok 5 - passing test #5 530 > ok 6 # skip passing test #6 (--run) 531 > # passed all 6 test(s) 532 > 1..6 533 EOF 534 ' 535 536 test_expect_success 'subtest: --run substring selector' ' 537 write_and_run_sub_test_lib_test run-substring-selector \ 538 --run="relevant" <<-\EOF && 539 test_expect_success "relevant test" "true" 540 for i in 1 2 3 4 5 6 541 do 542 test_expect_success "other test #$i" "true" 543 done 544 test_done 545 EOF 546 check_sub_test_lib_test run-substring-selector <<-\EOF 547 > ok 1 - relevant test 548 > ok 2 # skip other test #1 (--run) 549 > ok 3 # skip other test #2 (--run) 550 > ok 4 # skip other test #3 (--run) 551 > ok 5 # skip other test #4 (--run) 552 > ok 6 # skip other test #5 (--run) 553 > ok 7 # skip other test #6 (--run) 554 > # passed all 7 test(s) 555 > 1..7 556 EOF 557 ' 558 559 test_expect_success 'subtest: --run keyword selection' ' 560 write_and_run_sub_test_lib_test_err run-inv-range-start \ 561 --run="a-5" <<-\EOF && 562 test_expect_success "passing test #1" "true" 563 test_done 564 EOF 565 check_sub_test_lib_test_err run-inv-range-start \ 566 <<-\EOF_OUT 3<<-EOF_ERR 567 > FATAL: Unexpected exit with code 1 568 EOF_OUT 569 > error: --run: invalid non-numeric in range start: ${SQ}a-5${SQ} 570 EOF_ERR 571 ' 572 573 test_expect_success 'subtest: --run invalid range end' ' 574 run_sub_test_lib_test_err run-inv-range-start \ 575 --run="1-z" && 576 check_sub_test_lib_test_err run-inv-range-start \ 577 <<-\EOF_OUT 3<<-EOF_ERR 578 > FATAL: Unexpected exit with code 1 579 EOF_OUT 580 > error: --run: invalid non-numeric in range end: ${SQ}1-z${SQ} 581 EOF_ERR 582 ' 583 584 test_expect_success 'subtest: --invert-exit-code without --immediate' ' 585 run_sub_test_lib_test_err full-pass \ 586 --invert-exit-code && 587 check_sub_test_lib_test_err full-pass \ 588 <<-\EOF_OUT 3<<-EOF_ERR 589 ok 1 - passing test #1 590 ok 2 - passing test #2 591 ok 3 - passing test #3 592 # passed all 3 test(s) 593 1..3 594 # faking up non-zero exit with --invert-exit-code 595 EOF_OUT 596 EOF_ERR 597 ' 598 599 test_expect_success 'subtest: --invert-exit-code with --immediate: all passed' ' 600 run_sub_test_lib_test_err full-pass \ 601 --invert-exit-code --immediate && 602 check_sub_test_lib_test_err full-pass \ 603 <<-\EOF_OUT 3<<-EOF_ERR 604 ok 1 - passing test #1 605 ok 2 - passing test #2 606 ok 3 - passing test #3 607 # passed all 3 test(s) 608 1..3 609 # faking up non-zero exit with --invert-exit-code 610 EOF_OUT 611 EOF_ERR 612 ' 613 614 test_expect_success 'subtest: --invert-exit-code without --immediate: partial pass' ' 615 run_sub_test_lib_test partial-pass \ 616 --invert-exit-code && 617 check_sub_test_lib_test partial-pass <<-\EOF 618 ok 1 - passing test #1 619 not ok 2 - # TODO induced breakage (--invert-exit-code): failing test #2 620 # false 621 ok 3 - passing test #3 622 # failed 1 among 3 test(s) 623 1..3 624 # faked up failures as TODO & now exiting with 0 due to --invert-exit-code 625 EOF 626 ' 627 628 test_expect_success 'subtest: --invert-exit-code with --immediate: partial pass' ' 629 run_sub_test_lib_test partial-pass \ 630 --invert-exit-code --immediate && 631 check_sub_test_lib_test partial-pass \ 632 <<-\EOF_OUT 3<<-EOF_ERR 633 ok 1 - passing test #1 634 not ok 2 - # TODO induced breakage (--invert-exit-code): failing test #2 635 # false 636 1..2 637 # faked up failures as TODO & now exiting with 0 due to --invert-exit-code 638 EOF_OUT 639 EOF_ERR 640 ' 641 642 test_expect_success 'subtest: --invert-exit-code --immediate: got a failure' ' 643 run_sub_test_lib_test partial-pass \ 644 --invert-exit-code --immediate && 645 check_sub_test_lib_test_err partial-pass \ 646 <<-\EOF_OUT 3<<-EOF_ERR 647 ok 1 - passing test #1 648 not ok 2 - # TODO induced breakage (--invert-exit-code): failing test #2 649 # false 650 1..2 651 # faked up failures as TODO & now exiting with 0 due to --invert-exit-code 652 EOF_OUT 653 EOF_ERR 654 ' 655 656 test_expect_success 'subtest: tests respect prerequisites' ' 657 write_and_run_sub_test_lib_test prereqs <<-\EOF && 658 659 test_set_prereq HAVEIT 660 test_expect_success HAVEIT "prereq is satisfied" "true" 661 test_expect_success "have_prereq works" " 662 test_have_prereq HAVEIT 663 " 664 test_expect_success DONTHAVEIT "prereq not satisfied" "false" 665 666 test_set_prereq HAVETHIS 667 test_expect_success HAVETHIS,HAVEIT "multiple prereqs" "true" 668 test_expect_success HAVEIT,DONTHAVEIT "mixed prereqs (yes,no)" "false" 669 test_expect_success DONTHAVEIT,HAVEIT "mixed prereqs (no,yes)" "false" 670 671 test_done 672 EOF 673 674 check_sub_test_lib_test prereqs <<-\EOF 675 ok 1 - prereq is satisfied 676 ok 2 - have_prereq works 677 ok 3 # skip prereq not satisfied (missing DONTHAVEIT) 678 ok 4 - multiple prereqs 679 ok 5 # skip mixed prereqs (yes,no) (missing DONTHAVEIT of HAVEIT,DONTHAVEIT) 680 ok 6 # skip mixed prereqs (no,yes) (missing DONTHAVEIT of DONTHAVEIT,HAVEIT) 681 # passed all 6 test(s) 682 1..6 683 EOF 684 ' 685 686 test_expect_success 'subtest: tests respect lazy prerequisites' ' 687 write_and_run_sub_test_lib_test lazy-prereqs <<-\EOF && 688 689 test_lazy_prereq LAZY_TRUE true 690 test_expect_success LAZY_TRUE "lazy prereq is satisfied" "true" 691 test_expect_success !LAZY_TRUE "negative lazy prereq" "false" 692 693 test_lazy_prereq LAZY_FALSE false 694 test_expect_success LAZY_FALSE "lazy prereq not satisfied" "false" 695 test_expect_success !LAZY_FALSE "negative false prereq" "true" 696 697 test_done 698 EOF 699 700 check_sub_test_lib_test lazy-prereqs <<-\EOF 701 ok 1 - lazy prereq is satisfied 702 ok 2 # skip negative lazy prereq (missing !LAZY_TRUE) 703 ok 3 # skip lazy prereq not satisfied (missing LAZY_FALSE) 704 ok 4 - negative false prereq 705 # passed all 4 test(s) 706 1..4 707 EOF 708 ' 709 710 test_expect_success 'subtest: nested lazy prerequisites' ' 711 write_and_run_sub_test_lib_test nested-lazy <<-\EOF && 712 713 test_lazy_prereq NESTED_INNER " 714 >inner && 715 rm -f outer 716 " 717 test_lazy_prereq NESTED_PREREQ " 718 >outer && 719 test_have_prereq NESTED_INNER && 720 echo can create new file in cwd >file && 721 test_path_is_file outer && 722 test_path_is_missing inner 723 " 724 test_expect_success NESTED_PREREQ "evaluate nested prereq" "true" 725 726 test_done 727 EOF 728 729 check_sub_test_lib_test nested-lazy <<-\EOF 730 ok 1 - evaluate nested prereq 731 # passed all 1 test(s) 732 1..1 733 EOF 734 ' 735 736 test_expect_success 'subtest: lazy prereqs do not turn off tracing' ' 737 write_and_run_sub_test_lib_test lazy-prereq-and-tracing \ 738 -v -x <<-\EOF && 739 test_lazy_prereq LAZY true 740 741 test_expect_success lazy "test_have_prereq LAZY && echo trace" 742 743 test_done 744 EOF 745 746 test_grep "echo trace" lazy-prereq-and-tracing/err 747 ' 748 749 test_expect_success 'subtest: tests clean up after themselves' ' 750 write_and_run_sub_test_lib_test cleanup <<-\EOF && 751 clean=no 752 test_expect_success "do cleanup" " 753 test_when_finished clean=yes 754 " 755 test_expect_success "cleanup happened" " 756 test $clean = yes 757 " 758 test_done 759 EOF 760 761 check_sub_test_lib_test cleanup <<-\EOF 762 ok 1 - do cleanup 763 ok 2 - cleanup happened 764 # passed all 2 test(s) 765 1..2 766 EOF 767 ' 768 769 test_expect_success 'subtest: tests clean up even on failures' ' 770 write_and_run_sub_test_lib_test_err \ 771 failing-cleanup <<-\EOF && 772 test_expect_success "tests clean up even after a failure" " 773 touch clean-after-failure && 774 test_when_finished rm clean-after-failure && 775 (exit 1) 776 " 777 test_expect_success "failure to clean up causes the test to fail" " 778 test_when_finished \"(exit 2)\" 779 " 780 test_done 781 EOF 782 check_sub_test_lib_test failing-cleanup <<-\EOF 783 > not ok 1 - tests clean up even after a failure 784 > # Z 785 > # touch clean-after-failure && 786 > # test_when_finished rm clean-after-failure && 787 > # (exit 1) 788 > # Z 789 > not ok 2 - failure to clean up causes the test to fail 790 > # Z 791 > # test_when_finished "(exit 2)" 792 > # Z 793 > # failed 2 among 2 test(s) 794 > 1..2 795 EOF 796 ' 797 798 test_expect_success 'subtest: test_atexit is run' ' 799 write_and_run_sub_test_lib_test_err \ 800 atexit-cleanup -i <<-\EOF && 801 test_expect_success "tests clean up even after a failure" " 802 > ../../clean-atexit && 803 test_atexit rm ../../clean-atexit && 804 > ../../also-clean-atexit && 805 test_atexit rm ../../also-clean-atexit && 806 > ../../dont-clean-atexit && 807 (exit 1) 808 " 809 test_done 810 EOF 811 test_path_is_file dont-clean-atexit && 812 test_path_is_missing clean-atexit && 813 test_path_is_missing also-clean-atexit 814 ' 815 816 test_expect_success 'test_oid provides sane info by default' ' 817 test_oid zero >actual && 818 test_grep "^00*\$" actual && 819 rawsz="$(test_oid rawsz)" && 820 hexsz="$(test_oid hexsz)" && 821 # +1 accounts for the trailing newline 822 test $(( $hexsz + 1)) -eq $(wc -c actual && 830 test_grep "^00*\$" actual && 831 rawsz="$(test_oid rawsz)" && 832 hexsz="$(test_oid hexsz)" && 833 test $(wc -c actual && 842 test_grep "^00*\$" actual && 843 rawsz="$(test_oid rawsz)" && 844 hexsz="$(test_oid hexsz)" && 845 test $(wc -c err && 887 test_grep "error: test_bool_env requires bool values" err && 888 889 envvar=true && 890 ! ( test_bool_env envvar invalid ) 7>err && 891 test_grep "error: test_bool_env requires bool values" err 892 ) 893 ' 894 895 ################################################################ 896 # Basics of the basics 897 898 test_oid_cache <<\EOF 899 path0f sha1:`f87290f8eb2cbbea7857214459a0739927eab154` 900 path0f sha256:`638106af7c38be056f3212cbd7ac65bc1bac74f420ca5a436ff006a9d025d17d` 901 902 path0s sha1:`15a98433ae33114b085f3eb3bb03b832b3180a01` 903 path0s sha256:`3a24cc53cf68edddac490bbf94a418a52932130541361f685df685e41dd6c363` 904 905 path2f sha1:`3feff949ed00a62d9f7af97c15cd8a30595e7ac7` 906 path2f sha256:`2a7f36571c6fdbaf0e3f62751a0b25a3f4c54d2d1137b3f4af9cb794bb498e5f` 907 908 path2s sha1:`d8ce161addc5173867a3c3c730924388daedbc38` 909 path2s sha256:`18fd611b787c2e938ddcc248fabe4d66a150f9364763e9ec133dd01d5bb7c65a` 910 911 path2d sha1:`58a09c23e2ca152193f2786e06986b7b6712bdbe` 912 path2d sha256:`00e4b32b96e7e3d65d79112dcbea53238a22715f896933a62b811377e2650c17` 913 914 path3f sha1:`0aa34cae68d0878578ad119c86ca2b5ed5b28376` 915 path3f sha256:`09f58616b951bd571b8cb9dc76d372fbb09ab99db2393f5ab3189d26c45099ad` 916 917 path3s sha1:`8599103969b43aff7e430efea79ca4636466794f` 918 path3s sha256:`fce1aed087c053306f3f74c32c1a838c662bbc4551a7ac2420f5d6eb061374d0` 919 920 path3d sha1:`21ae8269cacbe57ae09138dcc3a2887f904d02b3` 921 path3d sha256:`9b60497be959cb830bf3f0dc82bcc9ad9e925a24e480837ade46b2295e47efe1` 922 923 subp3f sha1:`00fb5908cb97c2564a9783c0c64087333b3b464f` 924 subp3f sha256:`a1a9e16998c988453f18313d10375ee1d0ddefe757e710dcae0d66aa1e0c58b3` 925 926 subp3s sha1:`6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c` 927 subp3s sha256:`81759d9f5e93c6546ecfcadb560c1ff057314b09f93fe8ec06e2d8610d34ef10` 928 929 subp3d sha1:`3c5e5399f3a333eddecce7a9b9465b63f65f51e2` 930 subp3d sha256:`76b4ef482d4fa1c754390344cf3851c7f883b27cf9bc999c6547928c46aeafb7` 931 932 root sha1:`087704a96baf1c2d1c869a8b084481e121c88b5b` 933 root sha256:`9481b52abab1b2ffeedbf9de63ce422b929f179c1b98ff7bee5f8f1bc0710751` 934 935 simpletree sha1:`7bb943559a305bdd6bdee2cef6e5df2413c3d30a` 936 simpletree sha256:`1710c07a6c86f9a3c7376364df04c47ee39e5a5e221fcdd84b743bc9bb7e2bc5` 937 EOF 938 939 # updating a new file without --add should fail. 940 test_expect_success 'git update-index without --add should fail adding' ' 941 test_must_fail git update-index should-be-empty 942 ' 943 944 # and with --add it should succeed, even if it is empty (it used to fail). 945 test_expect_success 'git update-index with --add should succeed' ' 946 git update-index --add should-be-empty 947 ' 948 949 test_expect_success 'writing tree out with git write-tree' ' 950 tree=$(git write-tree) 951 ' 952 953 # we know the shape and contents of the tree and know the object ID for it. 954 test_expect_success 'validate object ID of a known tree' ' 955 test "$tree" = "$(test_oid simpletree)" 956 ' 957 958 # Removing paths. 959 test_expect_success 'git update-index without --remove should fail removing' ' 960 rm -f should-be-empty full-of-directories && 961 test_must_fail git update-index should-be-empty 962 ' 963 964 test_expect_success 'git update-index with --remove should be able to remove' ' 965 git update-index --remove should-be-empty 966 ' 967 968 # Empty tree can be written with recent write-tree. 969 test_expect_success 'git write-tree should be able to write an empty tree' ' 970 tree=$(git write-tree) 971 ' 972 973 test_expect_success 'validate object ID of a known tree' ' 974 test "$tree" = $EMPTY_TREE 975 ' 976 977 # Various types of objects 978 979 test_expect_success 'adding various types of objects with git update-index --add' ' 980 mkdir path2 path3 path3/subp3 && 981 paths="path0 path2/file2 path3/file3 path3/subp3/file3" && 982 ( 983 for p in $paths 984 do 985 echo "hello $p" >$p || exit 1 986 test_ln_s_add "hello $p" ${p}sym || exit 1 987 done 988 ) && 989 find path* ! -type d -print | xargs git update-index --add 990 ' 991 992 # Show them and see that matches what we expect. 993 test_expect_success 'showing stage with git ls-files --stage' ' 994 git ls-files --stage >current 995 ' 996 997 test_expect_success 'validate git ls-files output for a known tree' ' 998 cat >expected <<-EOF && 999 100644 $(test_oid path0f) 0 path0 1000 120000 $(test_oid path0s) 0 path0sym 1001 100644 $(test_oid path2f) 0 path2/file2 1002 120000 $(test_oid path2s) 0 path2/file2sym 1003 100644 $(test_oid path3f) 0 path3/file3 1004 120000 $(test_oid path3s) 0 path3/file3sym 1005 100644 $(test_oid subp3f) 0 path3/subp3/file3 1006 120000 $(test_oid subp3s) 0 path3/subp3/file3sym 1007 EOF 1008 test_cmp expected current 1009 ' 1010 1011 test_expect_success 'writing tree out with git write-tree' ' 1012 tree=$(git write-tree) 1013 ' 1014 1015 test_expect_success 'validate object ID for a known tree' ' 1016 test "$tree" = "$(test_oid root)" 1017 ' 1018 1019 test_expect_success 'showing tree with git ls-tree' ' 1020 git ls-tree $tree >current 1021 ' 1022 1023 test_expect_success 'git ls-tree output for a known tree' ' 1024 cat >expected <<-EOF && 1025 100644 blob $(test_oid path0f) path0 1026 120000 blob $(test_oid path0s) path0sym 1027 040000 tree $(test_oid path2d) path2 1028 040000 tree $(test_oid path3d) path3 1029 EOF 1030 test_cmp expected current 1031 ' 1032 1033 # This changed in ls-tree pathspec change -- recursive does 1034 # not show tree nodes anymore. 1035 test_expect_success 'showing tree with git ls-tree -r' ' 1036 git ls-tree -r $tree >current 1037 ' 1038 1039 test_expect_success 'git ls-tree -r output for a known tree' ' 1040 cat >expected <<-EOF && 1041 100644 blob $(test_oid path0f) path0 1042 120000 blob $(test_oid path0s) path0sym 1043 100644 blob $(test_oid path2f) path2/file2 1044 120000 blob $(test_oid path2s) path2/file2sym 1045 100644 blob $(test_oid path3f) path3/file3 1046 120000 blob $(test_oid path3s) path3/file3sym 1047 100644 blob $(test_oid subp3f) path3/subp3/file3 1048 120000 blob $(test_oid subp3s) path3/subp3/file3sym 1049 EOF 1050 test_cmp expected current 1051 ' 1052 1053 # But with -r -t we can have both. 1054 test_expect_success 'showing tree with git ls-tree -r -t' ' 1055 git ls-tree -r -t $tree >current 1056 ' 1057 1058 test_expect_success 'git ls-tree -r output for a known tree' ' 1059 cat >expected <<-EOF && 1060 100644 blob $(test_oid path0f) path0 1061 120000 blob $(test_oid path0s) path0sym 1062 040000 tree $(test_oid path2d) path2 1063 100644 blob $(test_oid path2f) path2/file2 1064 120000 blob $(test_oid path2s) path2/file2sym 1065 040000 tree $(test_oid path3d) path3 1066 100644 blob $(test_oid path3f) path3/file3 1067 120000 blob $(test_oid path3s) path3/file3sym 1068 040000 tree $(test_oid subp3d) path3/subp3 1069 100644 blob $(test_oid subp3f) path3/subp3/file3 1070 120000 blob $(test_oid subp3s) path3/subp3/file3sym 1071 EOF 1072 test_cmp expected current 1073 ' 1074 1075 test_expect_success 'writing partial tree out with git write-tree --prefix' ' 1076 ptree=$(git write-tree --prefix=path3) 1077 ' 1078 1079 test_expect_success 'validate object ID for a known tree' ' 1080 test "$ptree" = $(test_oid path3d) 1081 ' 1082 1083 test_expect_success 'writing partial tree out with git write-tree --prefix' ' 1084 ptree=$(git write-tree --prefix=path3/subp3) 1085 ' 1086 1087 test_expect_success 'validate object ID for a known tree' ' 1088 test "$ptree" = $(test_oid subp3d) 1089 ' 1090 1091 test_expect_success 'put invalid objects into the index' ' 1092 rm -f .git/index && 1093 suffix=$(echo $ZERO_OID | sed -e "s/^.//") && 1094 cat >badobjects <<-EOF && 1095 100644 blob $(test_oid 001) dir/file1 1096 100644 blob $(test_oid 002) dir/file2 1097 100644 blob $(test_oid 003) dir/file3 1098 100644 blob $(test_oid 004) dir/file4 1099 100644 blob $(test_oid 005) dir/file5 1100 EOF 1101 git update-index --index-info expected <current && 1134 test_cmp expected current 1135 ' 1136 1137 test_expect_success 'git update-index --refresh should succeed' ' 1138 git update-index --refresh 1139 ' 1140 1141 test_expect_success 'no diff after checkout and git update-index --refresh' ' 1142 git diff-files >current && 1143 cmp -s current /dev/null 1144 ' 1145 1146 ################################################################ 1147 P=$(test_oid root) 1148 1149 test_expect_success 'git commit-tree records the correct tree in a commit' ' 1150 commit0=$(echo NO | git commit-tree $P) && 1151 git show --pretty=raw $commit0 >out && 1152 tree=$(sed -n -e "s/^tree //p" -e "/^author /q" out) && 1153 test "z$tree" = "z$P" 1154 ' 1155 1156 test_expect_success 'git commit-tree records the correct parent in a commit' ' 1157 commit1=$(echo NO | git commit-tree $P -p $commit0) && 1158 git show --pretty=raw $commit1 >out && 1159 parent=$(sed -n -e "s/^parent //p" -e "/^author /q" out) && 1160 test "z$commit0" = "z$parent" 1161 ' 1162 1163 test_expect_success 'git commit-tree omits duplicated parent in a commit' ' 1164 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) && 1165 git show --pretty=raw $commit2 >out && 1166 cat >match.sed <<-\EOF && 1167 s/^parent //p 1168 /^author /q 1169 EOF 1170 parent=$(sed -n -f match.sed out | sort -u) && 1171 test "z$commit0" = "z$parent" && 1172 git show --pretty=raw $commit2 >out && 1173 test_stdout_line_count = 1 sed -n -f match.sed out 1174 ' 1175 1176 test_expect_success 'update-index D/F conflict' ' 1177 mv path0 tmp && 1178 mv path2 path0 && 1179 mv tmp path2 && 1180 git update-index --add --replace path2 path0/file2 && 1181 git ls-files path0 >tmp && 1182 numpath0=$(wc -l path4 && 1195 git update-index --add path4 && 1196 git ls-files -s path4 >tmp && 1197 ( 1198 sed -e "s/ .*/ /" tmp | 1199 tr -d "\012" && 1200 echo "$a" 1201 ) | git update-index --index-info && 1202 git ls-files "a*" >tmp && 1203 len=$(wc -c expected <<-\EOF && 1228 path5/a 1229 path5/a- 1230 EOF 1231 git ls-files >actual && 1232 test_cmp expected actual 1233 ' 1234 1235 test_expect_success 'test_must_fail on a failing git command' ' 1236 test_must_fail git notacommand 1237 ' 1238 1239 test_expect_success 'test_must_fail on a failing git command with env' ' 1240 test_must_fail env var1=a var2=b git notacommand 1241 ' 1242 1243 test_expect_success 'test_must_fail rejects a non-git command' ' 1244 ! test_must_fail grep ^$ notafile 2>err && 1245 test_grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err 1246 ' 1247 1248 test_expect_success 'test_must_fail rejects a non-git command with env' ' 1249 ! test_must_fail env var1=a var2=b grep ^$ notafile 2>err && 1250 test_grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err 1251 ' 1252 1253 test_done