|
268 | 268 | git push gh &&
|
269 | 269 | test ...
|
270 | 270 |
|
| 271 | + - Check the test coverage for your tests. See the "Test coverage" |
| 272 | + below. |
| 273 | + |
| 274 | + Don't blindly follow test coverage metrics, they're a good way to |
| 275 | + spot if you've missed something. If a new function you added |
| 276 | + doesn't have any coverage you're probably doing something wrong, |
| 277 | + but having 100% coverage doesn't necessarily mean that you tested |
| 278 | + everything. |
| 279 | + |
| 280 | + Tests that are likely to smoke out future regressions are better |
| 281 | + than tests that just inflate the coverage metrics. |
| 282 | + |
271 | 283 | Don't:
|
272 | 284 |
|
273 | 285 | - exit() within a <script> part.
|
@@ -307,16 +319,31 @@ Keep in mind:
|
307 | 319 | Skipping tests
|
308 | 320 | --------------
|
309 | 321 |
|
310 |
| -If you need to skip all the remaining tests you should set skip_all |
311 |
| -and immediately call test_done. The string you give to skip_all will |
312 |
| -be used as an explanation for why the test was skipped. for instance: |
| 322 | +If you need to skip tests you should do so be using the three-arg form |
| 323 | +of the test_* functions (see the "Test harness library" section |
| 324 | +below), e.g.: |
| 325 | + |
| 326 | + test_expect_success PERL 'I need Perl' " |
| 327 | + '$PERL_PATH' -e 'hlagh() if unf_unf()' |
| 328 | + " |
| 329 | + |
| 330 | +The advantage of skipping tests like this is that platforms that don't |
| 331 | +have the PERL and other optional dependencies get an indication of how |
| 332 | +many tests they're missing. |
| 333 | + |
| 334 | +If the test code is too hairy for that (i.e. does a lot of setup work |
| 335 | +outside test assertions) you can also skip all remaining tests by |
| 336 | +setting skip_all and immediately call test_done: |
313 | 337 |
|
314 | 338 | if ! test_have_prereq PERL
|
315 | 339 | then
|
316 | 340 | skip_all='skipping perl interface tests, perl not available'
|
317 | 341 | test_done
|
318 | 342 | fi
|
319 | 343 |
|
| 344 | +The string you give to skip_all will be used as an explanation for why |
| 345 | +the test was skipped. |
| 346 | + |
320 | 347 | End with test_done
|
321 | 348 | ------------------
|
322 | 349 |
|
@@ -350,6 +377,12 @@ library for your script to use.
|
350 | 377 | test_expect_success TTY 'git --paginate rev-list uses a pager' \
|
351 | 378 | ' ... '
|
352 | 379 |
|
| 380 | + You can also supply a comma-separated list of prerequisites, in the |
| 381 | + rare case where your test depends on more than one: |
| 382 | + |
| 383 | + test_expect_success PERL,PYTHON 'yo dawg' \ |
| 384 | + ' test $(perl -E 'print eval "1 +" . qx[python -c "print 2"]') == "4" ' |
| 385 | + |
353 | 386 | - test_expect_failure [<prereq>] <message> <script>
|
354 | 387 |
|
355 | 388 | This is NOT the opposite of test_expect_success, but is used
|
@@ -404,11 +437,12 @@ library for your script to use.
|
404 | 437 | - test_set_prereq SOME_PREREQ
|
405 | 438 |
|
406 | 439 | Set a test prerequisite to be used later with test_have_prereq. The
|
407 |
| - test-lib will set some prerequisites for you, e.g. PERL and PYTHON |
408 |
| - which are derived from ./GIT-BUILD-OPTIONS (grep test_set_prereq |
409 |
| - test-lib.sh for more). Others you can set yourself and use later |
410 |
| - with either test_have_prereq directly, or the three argument |
411 |
| - invocation of test_expect_success and test_expect_failure. |
| 440 | + test-lib will set some prerequisites for you, see the |
| 441 | + "Prerequisites" section below for a full list of these. |
| 442 | + |
| 443 | + Others you can set yourself and use later with either |
| 444 | + test_have_prereq directly, or the three argument invocation of |
| 445 | + test_expect_success and test_expect_failure. |
412 | 446 |
|
413 | 447 | - test_have_prereq SOME PREREQ
|
414 | 448 |
|
@@ -488,6 +522,45 @@ library for your script to use.
|
488 | 522 | ...
|
489 | 523 | '
|
490 | 524 |
|
| 525 | +Prerequisites |
| 526 | +------------- |
| 527 | + |
| 528 | +These are the prerequisites that the test library predefines with |
| 529 | +test_have_prereq. |
| 530 | + |
| 531 | +See the prereq argument to the test_* functions in the "Test harness |
| 532 | +library" section above and the "test_have_prereq" function for how to |
| 533 | +use these, and "test_set_prereq" for how to define your own. |
| 534 | + |
| 535 | + - PERL & PYTHON |
| 536 | + |
| 537 | + Git wasn't compiled with NO_PERL=YesPlease or |
| 538 | + NO_PYTHON=YesPlease. Wrap any tests that need Perl or Python in |
| 539 | + these. |
| 540 | + |
| 541 | + - POSIXPERM |
| 542 | + |
| 543 | + The filesystem supports POSIX style permission bits. |
| 544 | + |
| 545 | + - BSLASHPSPEC |
| 546 | + |
| 547 | + Backslashes in pathspec are not directory separators. This is not |
| 548 | + set on Windows. See 6fd1106a for details. |
| 549 | + |
| 550 | + - EXECKEEPSPID |
| 551 | + |
| 552 | + The process retains the same pid across exec(2). See fb9a2bea for |
| 553 | + details. |
| 554 | + |
| 555 | + - SYMLINKS |
| 556 | + |
| 557 | + The filesystem we're on supports symbolic links. E.g. a FAT |
| 558 | + filesystem doesn't support these. See 704a3143 for details. |
| 559 | + |
| 560 | + - SANITY |
| 561 | + |
| 562 | + Test is not run by root user, and an attempt to write to an |
| 563 | + unwritable file is expected to fail correctly. |
491 | 564 |
|
492 | 565 | Tips for Writing Tests
|
493 | 566 | ----------------------
|
@@ -515,3 +588,115 @@ the purpose of t0000-basic.sh, which is to isolate that level of
|
515 | 588 | validation in one place. Your test also ends up needing
|
516 | 589 | updating when such a change to the internal happens, so do _not_
|
517 | 590 | do it and leave the low level of validation to t0000-basic.sh.
|
| 591 | + |
| 592 | +Test coverage |
| 593 | +------------- |
| 594 | + |
| 595 | +You can use the coverage tests to find code paths that are not being |
| 596 | +used or properly exercised yet. |
| 597 | + |
| 598 | +To do that, run the coverage target at the top-level (not in the t/ |
| 599 | +directory): |
| 600 | + |
| 601 | + make coverage |
| 602 | + |
| 603 | +That'll compile Git with GCC's coverage arguments, and generate a test |
| 604 | +report with gcov after the tests finish. Running the coverage tests |
| 605 | +can take a while, since running the tests in parallel is incompatible |
| 606 | +with GCC's coverage mode. |
| 607 | + |
| 608 | +After the tests have run you can generate a list of untested |
| 609 | +functions: |
| 610 | + |
| 611 | + make coverage-untested-functions |
| 612 | + |
| 613 | +You can also generate a detailed per-file HTML report using the |
| 614 | +Devel::Cover module. To install it do: |
| 615 | + |
| 616 | + # On Debian or Ubuntu: |
| 617 | + sudo aptitude install libdevel-cover-perl |
| 618 | + |
| 619 | + # From the CPAN with cpanminus |
| 620 | + curl -L http://cpanmin.us | perl - --sudo --self-upgrade |
| 621 | + cpanm --sudo Devel::Cover |
| 622 | + |
| 623 | +Then, at the top-level: |
| 624 | + |
| 625 | + make cover_db_html |
| 626 | + |
| 627 | +That'll generate a detailed cover report in the "cover_db_html" |
| 628 | +directory, which you can then copy to a webserver, or inspect locally |
| 629 | +in a browser. |
| 630 | + |
| 631 | +Smoke testing |
| 632 | +------------- |
| 633 | + |
| 634 | +The Git test suite has support for smoke testing. Smoke testing is |
| 635 | +when you submit the results of a test run to a central server for |
| 636 | +analysis and aggregation. |
| 637 | + |
| 638 | +Running a smoke tester is an easy and valuable way of contributing to |
| 639 | +Git development, particularly if you have access to an uncommon OS on |
| 640 | +obscure hardware. |
| 641 | + |
| 642 | +After building Git you can generate a smoke report like this in the |
| 643 | +"t" directory: |
| 644 | + |
| 645 | + make clean smoke |
| 646 | + |
| 647 | +You can also pass arguments via the environment. This should make it |
| 648 | +faster: |
| 649 | + |
| 650 | + GIT_TEST_OPTS='--root=/dev/shm' TEST_JOBS=10 make clean smoke |
| 651 | + |
| 652 | +The "smoke" target will run the Git test suite with Perl's |
| 653 | +"TAP::Harness" module, and package up the results in a .tar.gz archive |
| 654 | +with "TAP::Harness::Archive". The former is included with Perl v5.10.1 |
| 655 | +or later, but you'll need to install the latter from the CPAN. See the |
| 656 | +"Test coverage" section above for how you might do that. |
| 657 | + |
| 658 | +Once the "smoke" target finishes you'll see a message like this: |
| 659 | + |
| 660 | + TAP Archive created at <path to git>/t/test-results/git-smoke.tar.gz |
| 661 | + |
| 662 | +To upload the smoke report you need to have curl(1) installed, then |
| 663 | +do: |
| 664 | + |
| 665 | + make smoke_report |
| 666 | + |
| 667 | +To upload the report anonymously. Hopefully that'll return something |
| 668 | +like "Reported #7 added.". |
| 669 | + |
| 670 | +If you're going to be uploading reports frequently please request a |
| 671 | +user account by E-Mailing [email protected]. Once you have a username |
| 672 | +and password you'll be able to do: |
| 673 | + |
| 674 | + SMOKE_USERNAME=<username> SMOKE_PASSWORD=<password> make smoke_report |
| 675 | + |
| 676 | +You can also add an additional comment to attach to the report, and/or |
| 677 | +a comma separated list of tags: |
| 678 | + |
| 679 | + SMOKE_USERNAME=<username> SMOKE_PASSWORD=<password> \ |
| 680 | + SMOKE_COMMENT=<comment> SMOKE_TAGS=<tags> \ |
| 681 | + make smoke_report |
| 682 | + |
| 683 | +Once the report is uploaded it'll be made available at |
| 684 | +http://smoke.git.nix.is, here's an overview of Recent Smoke Reports |
| 685 | +for Git: |
| 686 | + |
| 687 | + http://smoke.git.nix.is/app/projects/smoke_reports/1 |
| 688 | + |
| 689 | +The reports will also be mirrored to GitHub every few hours: |
| 690 | + |
| 691 | + http://github.com/gitsmoke/smoke-reports |
| 692 | + |
| 693 | +The Smolder SQLite database is also mirrored and made available for |
| 694 | +download: |
| 695 | + |
| 696 | + http://github.com/gitsmoke/smoke-database |
| 697 | + |
| 698 | +Note that the database includes hashed (with crypt()) user passwords |
| 699 | +and E-Mail addresses. Don't use a valuable password for the smoke |
| 700 | +service if you have an account, or an E-Mail address you don't want to |
| 701 | +be publicly known. The user accounts are just meant to be convenient |
| 702 | +labels, they're not meant to be secure. |
0 commit comments