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/README # 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 / README` 1356 lines ยท 47339 bytes Raw Blame History 1 Core Git Tests 2 ============== 3 4 This directory holds many test scripts for core Git tools. The 5 first part of this short document describes how to run the tests 6 and read their output. 7 8 When fixing the tools or adding enhancements, you are strongly 9 encouraged to add tests in this directory to cover what you are 10 trying to fix or enhance. The later part of this short document 11 describes how your test scripts should be organized. 12 13 14 Running Tests 15 ------------- 16 17 The easiest way to run tests is to say "make". This runs all 18 the tests. 19 20 *** t0000-basic.sh *** 21 ok 1 - .git/objects should be empty after git init in an empty repo. 22 ok 2 - .git/objects should have 3 subdirectories. 23 ok 3 - success is reported like this 24 ... 25 ok 43 - very long name in the index handled sanely 26 # fixed 1 known breakage(s) 27 # still have 1 known breakage(s) 28 # passed all remaining 42 test(s) 29 1..43 30 *** t0001-init.sh *** 31 ok 1 - plain 32 ok 2 - plain with GIT_WORK_TREE 33 ok 3 - plain bare 34 35 t/Makefile defines a target for each test file, such that you can also use 36 shell pattern matching to run a subset of the tests: 37 38 make *checkout* 39 40 will run all tests with 'checkout' in their filename. 41 42 Since the tests all output TAP (see https://testanything.org) they can 43 be run with any TAP harness. Here's an example of parallel testing 44 powered by a recent version of prove(1): 45 46 $ prove --timer --jobs 15 ./t[0-9]*.sh 47 [19:17:33] ./t0005-signals.sh ................................... ok 36 ms 48 [19:17:33] ./t0022-crlf-rename.sh ............................... ok 69 ms 49 [19:17:33] ./t0024-crlf-archive.sh .............................. ok 154 ms 50 [19:17:33] ./t0004-unwritable.sh ................................ ok 289 ms 51 [19:17:33] ./t0002-gitfile.sh ................................... ok 480 ms 52 ===( 102;0 25/? 6/? 5/? 16/? 1/? 4/? 2/? 1/? 3/? 1... )=== 53 54 prove and other harnesses come with a lot of useful options. The 55 --state option in particular is very useful: 56 57 # Repeat until no more failures 58 $ prove -j 15 --state=failed,save ./t[0-9]*.sh 59 60 You can give DEFAULT_TEST_TARGET=prove on the make command (or define it 61 in config.mak) to cause "make test" to run tests under prove. 62 GIT_PROVE_OPTS can be used to pass additional options, e.g. 63 64 $ make DEFAULT_TEST_TARGET=prove GIT_PROVE_OPTS='--timer --jobs 16' test 65 66 You can also run each test individually from command line, like this: 67 68 $ sh ./t3010-ls-files-killed-modified.sh 69 ok 1 - git update-index --add to add various paths. 70 ok 2 - git ls-files -k to show killed files. 71 ok 3 - validate git ls-files -k output. 72 ok 4 - git ls-files -m to show modified files. 73 ok 5 - validate git ls-files -m output. 74 # passed all 5 test(s) 75 1..5 76 77 You can pass --verbose (or -v), --debug (or -d), and --immediate 78 (or -i) command line argument to the test, or by setting GIT_TEST_OPTS 79 appropriately before running "make". Short options can be bundled, i.e. 80 '-d -v' is the same as '-dv'. 81 82 -v:: 83 --verbose:: 84 This makes the test more verbose. Specifically, the 85 command being run and their output if any are also 86 output. 87 88 --verbose-only=:: 89 Like --verbose, but the effect is limited to tests with 90 numbers matching . The number matched against is 91 simply the running count of the test within the file. 92 93 -x:: 94 Turn on shell tracing (i.e., `set -x`) during the tests 95 themselves. Implies `--verbose`. 96 Ignored in test scripts that set the variable 'test_untraceable' 97 to a non-empty value, unless it's run with a Bash version 98 supporting BASH_XTRACEFD, i.e. v4.1 or later. 99 100 -d:: 101 --debug:: 102 This may help the person who is developing a new test. 103 It causes the command defined with test_debug to run. 104 The "trash" directory (used to store all temporary data 105 during testing) is not deleted even if there are no 106 failed tests so that you can inspect its contents after 107 the test finished. 108 109 -i:: 110 --immediate:: 111 This causes the test to immediately exit upon the first 112 failed test. Cleanup commands requested with 113 test_when_finished are not executed if the test failed, 114 in order to keep the state for inspection by the tester 115 to diagnose the bug. 116 117 -l:: 118 --long-tests:: 119 This causes additional long-running tests to be run (where 120 available), for more exhaustive testing. 121 122 -r:: 123 --run=:: 124 Run only the subset of tests indicated by 125 . See section "Skipping Tests" below for 126 syntax. 127 128 --valgrind=:: 129 Execute all Git binaries under valgrind tool and exit 130 with status 126 on errors (just like regular tests, this will 131 only stop the test script when running under -i). 132 133 Since it makes no sense to run the tests with --valgrind and 134 not see any output, this option implies --verbose. For 135 convenience, it also implies --tee. 136 137 defaults to 'memcheck', just like valgrind itself. 138 Other particularly useful choices include 'helgrind' and 139 'drd', but you may use any tool recognized by your valgrind 140 installation. 141 142 As a special case, can be 'memcheck-fast', which uses 143 memcheck but disables --track-origins. Use this if you are 144 running tests in bulk, to see if there are _any_ memory 145 issues. 146 147 Note that memcheck is run with the option --leak-check=no, 148 as the git process is short-lived and some errors are not 149 interesting. In order to run a single command under the same 150 conditions manually, you should set GIT_VALGRIND to point to 151 the 't/valgrind/' directory and use the commands under 152 't/valgrind/bin/'. 153 154 --valgrind-only=:: 155 Like --valgrind, but the effect is limited to tests with 156 numbers matching . The number matched against is 157 simply the running count of the test within the file. 158 159 --tee:: 160 In addition to printing the test output to the terminal, 161 write it to files named 't/test-results/$TEST_NAME.out'. 162 As the names depend on the tests' file names, it is safe to 163 run the tests with this option in parallel. 164 165 -V:: 166 --verbose-log:: 167 Write verbose output to the same logfile as `--tee`, but do 168 _not_ write it to stdout. Unlike `--tee --verbose`, this option 169 is safe to use when stdout is being consumed by a TAP parser 170 like `prove`. Implies `--tee` and `--verbose`. 171 172 --with-dashes:: 173 By default tests are run without dashed forms of 174 commands (like git-commit) in the PATH (it only uses 175 wrappers from ../bin-wrappers). Use this option to include 176 the build directory (..) in the PATH, which contains all 177 the dashed forms of commands. This option is currently 178 implied by other options like --valgrind and 179 GIT_TEST_INSTALLED. 180 181 --no-bin-wrappers:: 182 By default, the test suite uses the wrappers in 183 `../bin-wrappers/` to execute `git` and friends. With this option, 184 `../git` and friends are run directly. This is not recommended 185 in general, as the wrappers contain safeguards to ensure that no 186 files from an installed Git are used, but can speed up test runs 187 especially on platforms where running shell scripts is expensive 188 (most notably, Windows). 189 190 --root=:: 191 Create "trash" directories used to store all temporary data during 192 testing under , instead of the t/ directory. 193 Using this option with a RAM-based filesystem (such as tmpfs) 194 can massively speed up the test suite. 195 196 --chain-lint:: 197 --no-chain-lint:: 198 If --chain-lint is enabled, the test harness will check each 199 test to make sure that it properly "&&-chains" all commands (so 200 that a failure in the middle does not go unnoticed by the final 201 exit code of the test). This check is performed in addition to 202 running the tests themselves. You may also enable or disable 203 this feature by setting the GIT_TEST_CHAIN_LINT environment 204 variable to "1" or "0", respectively. 205 206 --stress:: 207 Run the test script repeatedly in multiple parallel jobs until 208 one of them fails. Useful for reproducing rare failures in 209 flaky tests. The number of parallel jobs is, in order of 210 precedence: the value of the GIT_TEST_STRESS_LOAD 211 environment variable, or twice the number of available 212 processors (as shown by the 'getconf' utility), or 8. 213 Implies `--verbose -x --immediate` to get the most information 214 about the failure. Note that the verbose output of each test 215 job is saved to 't/test-results/$TEST_NAME.stress-.out', 216 and only the output of the failed test job is shown on the 217 terminal. The names of the trash directories get a 218 '.stress-' suffix, and the trash directory of the failed 219 test job is renamed to end with a '.stress-failed' suffix. 220 221 --stress-jobs=:: 222 Override the number of parallel jobs. Implies `--stress`. 223 224 --stress-limit=:: 225 When combined with --stress run the test script repeatedly 226 this many times in each of the parallel jobs or until one of 227 them fails, whichever comes first. Implies `--stress`. 228 229 You can also set the GIT_TEST_INSTALLED environment variable to 230 the bindir of an existing git installation to test that installation. 231 You still need to have built this git sandbox, from which various 232 test-* support programs, templates, and perl libraries are used. 233 If your installed git is incomplete, it will silently test parts of 234 your built version instead. 235 236 When using GIT_TEST_INSTALLED, you can also set GIT_TEST_EXEC_PATH to 237 override the location of the dashed-form subcommands (what 238 GIT_EXEC_PATH would be used for during normal operation). 239 GIT_TEST_EXEC_PATH defaults to `$GIT_TEST_INSTALLED/git --exec-path`. 240 241 242 Skipping Tests 243 -------------- 244 245 In some environments, certain tests have no way of succeeding 246 due to platform limitation, such as lack of 'unzip' program, or 247 filesystem that do not allow arbitrary sequence of non-NUL bytes 248 as pathnames. 249 250 You should be able to say something like 251 252 $ GIT_SKIP_TESTS=t9200.8 sh ./t9200-git-cvsexport-commit.sh 253 254 and even: 255 256 $ GIT_SKIP_TESTS='t[0-4]??? t91?? t9200.8' make 257 258 to omit such tests. The value of the environment variable is a 259 SP separated list of patterns that tells which tests to skip, 260 and either can match the "t[0-9]{4}" part to skip the whole 261 test, or t[0-9]{4} followed by ".$number" to say which 262 particular test to skip. 263 264 For an individual test suite --run could be used to specify that 265 only some tests should be run or that some tests should be 266 excluded from a run. 267 268 The argument for --run, , is a list of description 269 substrings or globs or individual test numbers or ranges with an 270 optional negation prefix (of '!') that define what tests in a test 271 suite to include (or exclude, if negated) in the run. A range is two 272 numbers separated with a dash and specifies an inclusive range of tests 273 to run. You may omit the first or the second number to 274 mean "from the first test" or "up to the very last test" respectively. 275 276 The argument to --run is split on commas into separate strings, 277 numbers, and ranges, and picks all tests that match any of the 278 individual selection criteria. If the substring of the description 279 text that you want to match includes a comma, use the glob character 280 '?' instead. For example --run='rebase,merge?cherry-pick' would match 281 on all tests that match either the glob *rebase* or the glob 282 *merge?cherry-pick*. 283 284 If --run starts with an unprefixed number or range, the initial 285 set of tests to run is empty. If the first item starts with '!', 286 all the tests are added to the initial set. After initial set is 287 determined, every test number or range is added or excluded from 288 the set one by one, from left to right. 289 290 For example, to run only tests up to a specific test (21), one 291 could do this: 292 293 $ sh ./t9200-git-cvsexport-commit.sh --run='1-21' 294 295 or this: 296 297 $ sh ./t9200-git-cvsexport-commit.sh --run='-21' 298 299 Common case is to run several setup tests (1, 2, 3) and then a 300 specific test (21) that relies on that setup: 301 302 $ sh ./t9200-git-cvsexport-commit.sh --run='1,2,3,21' 303 304 or: 305 306 $ sh ./t9200-git-cvsexport-commit.sh --run=1,2,3,21 307 308 or: 309 310 $ sh ./t9200-git-cvsexport-commit.sh --run='-3,21' 311 312 As noted above, the test set is built by going through the items 313 from left to right, so this: 314 315 $ sh ./t9200-git-cvsexport-commit.sh --run='1-4,!3' 316 317 will run tests 1, 2, and 4. Items that come later have higher 318 precedence. It means that this: 319 320 $ sh ./t9200-git-cvsexport-commit.sh --run='!3,1-4' 321 322 would just run tests from 1 to 4, including 3. 323 324 You may use negation with ranges. The following will run all 325 test in the test suite except from 7 up to 11: 326 327 $ sh ./t9200-git-cvsexport-commit.sh --run='!7-11' 328 329 Sometimes there may be multiple tests with e.g. "setup" in their name 330 that are needed and rather than figuring out the number for all of them 331 we can just use "setup" as a substring/glob to match against the test 332 description: 333 334 $ sh ./t0050-filesystem.sh --run=setup,9-11 335 336 or one could select both the setup tests and the rename ones (assuming all 337 relevant tests had those words in their descriptions): 338 339 $ sh ./t0050-filesystem.sh --run=setup,rename 340 341 Some tests in a test suite rely on the previous tests performing 342 certain actions, specifically some tests are designated as 343 "setup" test, so you cannot _arbitrarily_ disable one test and 344 expect the rest to function correctly. 345 346 --run is mostly useful when you want to focus on a specific test 347 and know what setup is needed for it. Or when you want to run 348 everything up to a certain test. 349 350 351 Running tests with special setups 352 --------------------------------- 353 354 The whole test suite could be run to test some special features 355 that cannot be easily covered by a few specific test cases. These 356 could be enabled by running the test suite with correct GIT_TEST_ 357 environment set. 358 359 GIT_TEST_FAIL_PREREQS= fails all prerequisites. This is 360 useful for discovering issues with the tests where say a later test 361 implicitly depends on an optional earlier test. 362 363 There's a "FAIL_PREREQS" prerequisite that can be used to test for 364 whether this mode is active, and e.g. skip some tests that are hard to 365 refactor to deal with it. The "SYMLINKS" prerequisite is currently 366 excluded as so much relies on it, but this might change in the future. 367 368 GIT_TEST_SPLIT_INDEX= forces split-index mode on the whole 369 test suite. Accept any boolean values that are accepted by git-config. 370 371 GIT_TEST_PROTOCOL_VERSION=, when set, makes 'protocol.version' 372 default to n. 373 374 GIT_TEST_FULL_IN_PACK_ARRAY= exercises the uncommon 375 pack-objects code path where there are more than 1024 packs even if 376 the actual number of packs in repository is below this limit. Accept 377 any boolean values that are accepted by git-config. 378 379 GIT_TEST_OE_SIZE= exercises the uncommon pack-objects code path 380 where we do not cache object size in memory and read it from existing 381 packs on demand. This normally only happens when the object size is 382 over 2GB. This variable forces the code path on any object larger than 383 bytes. 384 385 GIT_TEST_OE_DELTA_SIZE= exercises the uncommon pack-objects code 386 path where deltas larger than this limit require extra memory 387 allocation for bookkeeping. 388 389 GIT_TEST_VALIDATE_INDEX_CACHE_ENTRIES= checks that cache-tree 390 records are valid when the index is written out or after a merge. This 391 is mostly to catch missing invalidation. Default is true. 392 393 GIT_TEST_COMMIT_GRAPH=, when true, forces the commit-graph to 394 be written after every 'git commit' command, and overrides the 395 'core.commitGraph' setting to true. 396 397 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=, when true, forces 398 commit-graph write to compute and write changed path Bloom filters for 399 every 'git commit-graph write', as if the `--changed-paths` option was 400 passed in. 401 402 GIT_TEST_FSMONITOR=$PWD/t7519/fsmonitor-all exercises the fsmonitor 403 code paths for utilizing a (hook based) file system monitor to speed up 404 detecting new or changed files. 405 406 GIT_TEST_INDEX_VERSION= exercises the index read/write code path 407 for the index version specified. Can be set to any valid version 408 (currently 2, 3, or 4). 409 410 GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL= if enabled will 411 use the boundary-based bitmap traversal algorithm. See the documentation 412 of `pack.useBitmapBoundaryTraversal` for more details. 413 414 GIT_TEST_PACK_SPARSE= if disabled will default the pack-objects 415 builtin to use the non-sparse object walk. This can still be overridden by 416 the --sparse command-line argument. 417 418 GIT_TEST_PACK_PATH_WALK= if enabled will default the pack-objects 419 builtin to use the path-walk API for the object walk. This can still be 420 overridden by the --no-path-walk command-line argument. 421 422 GIT_TEST_PRELOAD_INDEX= exercises the preload-index code path 423 by overriding the minimum number of cache entries required per thread. 424 425 GIT_TEST_INDEX_THREADS= enables exercising the multi-threaded loading 426 of the index for the whole test suite by bypassing the default number of 427 cache entries and thread minimums. Setting this to 1 will make the 428 index loading single threaded. 429 430 GIT_TEST_MULTI_PACK_INDEX=, when true, forces the multi-pack- 431 index to be written after every 'git repack' command, and overrides the 432 'core.multiPackIndex' setting to true. 433 434 GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL=, when true, sets 435 the '--incremental' option on all invocations of 'git multi-pack-index 436 write'. 437 438 GIT_TEST_SIDEBAND_ALL=, when true, overrides the 439 'uploadpack.allowSidebandAll' setting to true, and when false, forces 440 fetch-pack to not request sideband-all (even if the server advertises 441 sideband-all). 442 443 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=, when true (which is 444 the default when running tests), errors out when an abbreviated option 445 is used. 446 447 GIT_TEST_DEFAULT_HASH= specifies which hash algorithm to 448 use in the test scripts. Recognized values for are "sha1" 449 and "sha256". 450 451 GIT_TEST_DEFAULT_REF_STORAGE_FORMAT= specifies which ref storage format 452 to use in the test scripts. Recognized values for are "files" and 453 "reftable". 454 455 GIT_TEST_NO_WRITE_REV_INDEX=, when true disables the 456 'pack.writeReverseIndex' setting. 457 458 GIT_TEST_SPARSE_INDEX=, when true enables index writes to use the 459 sparse-index format by default. 460 461 GIT_TEST_CHECKOUT_WORKERS= overrides the 'checkout.workers' setting 462 to and 'checkout.thresholdForParallelism' to 0, forcing the 463 execution of the parallel-checkout code. 464 465 GIT_TEST_REQUIRE_PREREQ= allows specifying a space separated list of 466 prereqs that are required to succeed. If a prereq in this list is triggered by 467 a test and then fails then the whole test run will abort. This can help to make 468 sure the expected tests are executed and not silently skipped when their 469 dependency breaks or is simply not present in a new environment. 470 471 GIT_TEST_NAME_HASH_VERSION=, when set, causes 'git pack-objects' to 472 assume '--name-hash-version='. 473 474 475 Naming Tests 476 ------------ 477 478 The test files are named as: 479 480 tNNNN-commandname-details.sh 481 482 where N is a decimal digit. 483 484 First digit tells the family: 485 486 0 - the absolute basics and global stuff 487 1 - the basic commands concerning database 488 2 - the basic commands concerning the working tree 489 3 - the other basic commands (e.g. ls-files) 490 4 - the diff commands 491 5 - the pull and exporting commands 492 6 - the revision tree commands (even e.g. merge-base) 493 7 - the porcelainish commands concerning the working tree 494 8 - the porcelainish commands concerning forensics 495 9 - the git tools 496 497 Second digit tells the particular command we are testing. 498 499 Third digit (optionally) tells the particular switch or group of switches 500 we are testing. 501 502 If you create files under t/ directory (i.e. here) that is not 503 the top-level test script, never name the file to match the above 504 pattern. The Makefile here considers all such files as the 505 top-level test script and tries to run all of them. Care is 506 especially needed if you are creating a common test library 507 file, similar to test-lib.sh, because such a library file may 508 not be suitable for standalone execution. 509 510 511 Writing Tests 512 ------------- 513 514 The test script is written as a shell script. It should start 515 with the standard "#!/bin/sh", and an 516 assignment to variable 'test_description', like this: 517 518 #!/bin/sh 519 520 test_description='xxx test (option --frotz) 521 522 This test registers the following structure in the cache 523 and tries to run git-ls-files with option --frotz.' 524 525 526 Source 'test-lib.sh' 527 -------------------- 528 529 After assigning test_description, the test script should source 530 test-lib.sh like this: 531 532 . ./test-lib.sh 533 534 This test harness library does the following things: 535 536 - If the script is invoked with command line argument --help 537 (or -h), it shows the test_description and exits. 538 539 - Creates an empty test directory with an empty .git/objects database 540 and chdir(2) into it. This directory is 't/trash 541 directory.$test_name_without_dotsh', with t/ subject to change by 542 the --root option documented above, and a '.stress-' suffix 543 appended by the --stress option. 544 545 - Defines standard test helper functions for your scripts to 546 use. These functions are designed to make all scripts behave 547 consistently when command line arguments --verbose (or -v), 548 --debug (or -d), and --immediate (or -i) is given. 549 550 Recommended style 551 ----------------- 552 553 - Keep the test_expect_* function call and test title on 554 the same line. 555 556 For example, with test_expect_success, write it like: 557 558 test_expect_success 'test title' ' 559 ... test body ... 560 ' 561 562 Instead of: 563 564 test_expect_success \ 565 'test title' \ 566 '... test body ...' 567 568 - End the line with an opening single quote. 569 570 - Indent here-document bodies, and use "<<-" instead of "<<" 571 to strip leading TABs used for indentation: 572 573 test_expect_success 'test something' ' 574 cat >expect <<-\EOF && 575 one 576 two 577 three 578 EOF 579 test_something > actual && 580 test_cmp expect actual 581 ' 582 583 Instead of: 584 585 test_expect_success 'test something' ' 586 cat >expect <<\EOF && 587 one 588 two 589 three 590 EOF 591 test_something > actual && 592 test_cmp expect actual 593 ' 594 595 - Quote or escape the EOF delimiter that begins a here-document if 596 there is no parameter or other expansion in it, to signal readers 597 that they can skim it more casually: 598 599 cmd <<-\EOF 600 literal here-document text without any expansion 601 EOF 602 603 604 Do's & don'ts 605 ------------- 606 607 Here are a few examples of things you probably should and shouldn't do 608 when writing tests. 609 610 The "do's:" 611 612 - Put all code inside test_expect_success and other assertions. 613 614 Even code that isn't a test per se, but merely some setup code 615 should be inside a test assertion. 616 617 - Chain your test assertions 618 619 Write test code like this: 620 621 git merge foo && 622 git push bar && 623 test ... 624 625 Instead of: 626 627 git merge hla 628 git push gh 629 test ... 630 631 That way all of the commands in your tests will succeed or fail. If 632 you must ignore the return value of something, consider using a 633 helper function (e.g. use sane_unset instead of unset, in order 634 to avoid unportable return value for unsetting a variable that was 635 already unset), or prepending the command with test_might_fail or 636 test_must_fail. 637 638 - Check the test coverage for your tests. See the "Test coverage" 639 below. 640 641 Don't blindly follow test coverage metrics; if a new function you added 642 doesn't have any coverage, then you're probably doing something wrong, 643 but having 100% coverage doesn't necessarily mean that you tested 644 everything. 645 646 Tests that are likely to smoke out future regressions are better 647 than tests that just inflate the coverage metrics. 648 649 - When a test checks for an absolute path that a git command generated, 650 construct the expected value using $(pwd) rather than $PWD, 651 $TEST_DIRECTORY, or $TRASH_DIRECTORY. It makes a difference on 652 Windows, where the shell (MSYS bash) mangles absolute path names. 653 For details, see the commit message of `4114156ae9`. 654 655 - Remember that inside the