1# Test framework for git. See t/README for usage. 2# 3# Copyright (c) 2005 Junio C Hamano 4# 5# This program is free software: you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation, either version 2 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see http://www.gnu.org/licenses/ . 17 18# Test the binaries we have just built. The tests are kept in 19# t/ subdirectory and are run in 'trash directory' subdirectory. 20iftest -z"$TEST_DIRECTORY" 21then 22# We allow tests to override this, in case they want to run tests 23# outside of t/, e.g. for running tests on the test library 24# itself. 25 TEST_DIRECTORY=$(pwd) 26else 27# ensure that TEST_DIRECTORY is an absolute path so that it 28# is valid even if the current working directory is changed 29 TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd)||exit1 30fi 31iftest -z"$TEST_OUTPUT_DIRECTORY" 32then 33# Similarly, override this to store the test-results subdir 34# elsewhere 35 TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY 36fi 37GIT_BUILD_DIR="$TEST_DIRECTORY"/.. 38 39################################################################ 40# It appears that people try to run tests without building... 41"$GIT_BUILD_DIR/git">/dev/null 42iftest $? !=1 43then 44echo>&2'error: you do not seem to have built git yet.' 45exit1 46fi 47 48. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS 49export PERL_PATH SHELL_PATH 50 51# if --tee was passed, write the output not only to the terminal, but 52# additionally to the file test-results/$BASENAME.out, too. 53case"$GIT_TEST_TEE_STARTED, $* "in 54done,*) 55# do not redirect again 56;; 57*' --tee '*|*' --va'*) 58mkdir-p"$TEST_OUTPUT_DIRECTORY/test-results" 59 BASE="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)" 60(GIT_TEST_TEE_STARTED=done${SHELL_PATH}"$0""$@"2>&1; 61echo $? >$BASE.exit) |tee$BASE.out 62test"$(cat $BASE.exit)"=0 63exit 64;; 65esac 66 67# For repeatability, reset the environment to known value. 68# TERM is sanitized below, after saving color control sequences. 69LANG=C 70LC_ALL=C 71PAGER=cat 72TZ=UTC 73export LANG LC_ALL PAGER TZ 74EDITOR=: 75# A call to "unset" with no arguments causes at least Solaris 10 76# /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets 77# deriving from the command substitution clustered with the other 78# ones. 79unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH"-e' 80 my @env = keys %ENV; 81 my$ok= join("|", qw( 82 TRACE 83 DEBUG 84 USE_LOOKUP 85 TEST 86 .*_TEST 87 PROVE 88 VALGRIND 89 UNZIP 90 PERF_ 91 CURL_VERBOSE 92 TRACE_CURL 93 )); 94 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env); 95 print join("\n", @vars); 96') 97unset XDG_CONFIG_HOME 98unset GITPERLLIB 99GIT_AUTHOR_EMAIL=author@example.com 100GIT_AUTHOR_NAME='A U Thor' 101GIT_COMMITTER_EMAIL=committer@example.com 102GIT_COMMITTER_NAME='C O Mitter' 103GIT_MERGE_VERBOSITY=5 104GIT_MERGE_AUTOEDIT=no 105export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT 106export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME 107export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME 108export EDITOR 109 110# Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output 111GIT_TRACE_BARE=1 112export GIT_TRACE_BARE 113 114iftest -n"${TEST_GIT_INDEX_VERSION:+isset}" 115then 116 GIT_INDEX_VERSION="$TEST_GIT_INDEX_VERSION" 117export GIT_INDEX_VERSION 118fi 119 120# Add libc MALLOC and MALLOC_PERTURB test 121# only if we are not executing the test with valgrind 122ifexpr"$GIT_TEST_OPTS":".* --valgrind ">/dev/null || 123test -n"$TEST_NO_MALLOC_CHECK" 124then 125 setup_malloc_check () { 126: nothing 127} 128 teardown_malloc_check () { 129: nothing 130} 131else 132 setup_malloc_check () { 133 MALLOC_CHECK_=3 MALLOC_PERTURB_=165 134export MALLOC_CHECK_ MALLOC_PERTURB_ 135} 136 teardown_malloc_check () { 137unset MALLOC_CHECK_ MALLOC_PERTURB_ 138} 139fi 140 141:${ASAN_OPTIONS=detect_leaks=0} 142export ASAN_OPTIONS 143 144# Protect ourselves from common misconfiguration to export 145# CDPATH into the environment 146unset CDPATH 147 148unset GREP_OPTIONS 149unset UNZIP 150 151case$(echo $GIT_TRACE |tr "[A-Z]" "[a-z]")in 1521|2|true) 153 GIT_TRACE=4 154;; 155esac 156 157# Convenience 158# 159# A regexp to match 5 and 40 hexdigits 160_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' 161_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05" 162 163# Zero SHA-1 164_z40=0000000000000000000000000000000000000000 165 166EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904 167EMPTY_BLOB=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 168 169# Line feed 170LF=' 171' 172 173# UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores 174# when case-folding filenames 175u200c=$(printf '\342\200\214') 176 177export _x05 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB 178 179# Each test should start with something like this, after copyright notices: 180# 181# test_description='Description of this test... 182# This test checks if command xyzzy does the right thing... 183# ' 184# . ./test-lib.sh 185test"x$TERM"!="xdumb"&& ( 186test -t1&& 187tput bold >/dev/null 2>&1&& 188tput setaf 1>/dev/null 2>&1&& 189tput sgr0 >/dev/null 2>&1 190) && 191 color=t 192 193whiletest"$#"-ne0 194do 195case"$1"in 196-d|--d|--de|--deb|--debu|--debug) 197 debug=t;shift;; 198-i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) 199 immediate=t;shift;; 200-l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) 201 GIT_TEST_LONG=t;export GIT_TEST_LONG;shift;; 202-r) 203shift;test"$#"-ne0|| { 204echo'error: -r requires an argument'>&2; 205exit1; 206} 207 run_list=$1;shift;; 208--run=*) 209 run_list=${1#--*=};shift;; 210-h|--h|--he|--hel|--help) 211help=t;shift;; 212-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) 213 verbose=t;shift;; 214--verbose-only=*) 215 verbose_only=${1#--*=} 216shift;; 217-q|--q|--qu|--qui|--quie|--quiet) 218# Ignore --quiet under a TAP::Harness. Saying how many tests 219# passed without the ok/not ok details is always an error. 220test -z"$HARNESS_ACTIVE"&& quiet=t;shift;; 221--with-dashes) 222 with_dashes=t;shift;; 223--no-color) 224 color=;shift;; 225--va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind) 226 valgrind=memcheck 227shift;; 228--valgrind=*) 229 valgrind=${1#--*=} 230shift;; 231--valgrind-only=*) 232 valgrind_only=${1#--*=} 233shift;; 234--tee) 235shift;;# was handled already 236--root=*) 237 root=${1#--*=} 238shift;; 239--chain-lint) 240 GIT_TEST_CHAIN_LINT=1 241shift;; 242--no-chain-lint) 243 GIT_TEST_CHAIN_LINT=0 244shift;; 245-x) 246 trace=t 247 verbose=t 248shift;; 249*) 250echo"error: unknown test option '$1'">&2;exit1;; 251esac 252done 253 254iftest -n"$valgrind_only" 255then 256test -z"$valgrind"&& valgrind=memcheck 257test -z"$verbose"&& verbose_only="$valgrind_only" 258eliftest -n"$valgrind" 259then 260 verbose=t 261fi 262 263iftest -n"$color" 264then 265# Save the color control sequences now rather than run tput 266# each time say_color() is called. This is done for two 267# reasons: 268# * TERM will be changed to dumb 269# * HOME will be changed to a temporary directory and tput 270# might need to read ~/.terminfo from the original HOME 271# directory to get the control sequences 272# Note: This approach assumes the control sequences don't end 273# in a newline for any terminal of interest (command 274# substitutions strip trailing newlines). Given that most 275# (all?) terminals in common use are related to ECMA-48, this 276# shouldn't be a problem. 277 say_color_error=$(tput bold; tput setaf 1)# bold red 278 say_color_skip=$(tput setaf 4)# blue 279 say_color_warn=$(tput setaf 3)# brown/yellow 280 say_color_pass=$(tput setaf 2)# green 281 say_color_info=$(tput setaf 6)# cyan 282 say_color_reset=$(tput sgr0) 283 say_color_=""# no formatting for normal text 284 say_color () { 285test -z"$1"&&test -n"$quiet"&&return 286eval"say_color_color=\$say_color_$1" 287shift 288printf"%s\\n""$say_color_color$*$say_color_reset" 289} 290else 291 say_color() { 292test -z"$1"&&test -n"$quiet"&&return 293shift 294printf"%s\n""$*" 295} 296fi 297 298TERM=dumb 299export TERM 300 301error () { 302 say_color error "error: $*" 303 GIT_EXIT_OK=t 304exit1 305} 306 307say () { 308 say_color info "$*" 309} 310 311test"${test_description}"!=""|| 312error "Test script did not set test_description." 313 314iftest"$help"="t" 315then 316printf'%s\n'"$test_description" 317exit0 318fi 319 320exec5>&1 321exec6<&0 322iftest"$verbose"="t" 323then 324exec4>&2 3>&1 325else 326exec4>/dev/null 3>/dev/null 327fi 328 329# Send any "-x" output directly to stderr to avoid polluting tests 330# which capture stderr. We can do this unconditionally since it 331# has no effect if tracing isn't turned on. 332# 333# Note that this sets up the trace fd as soon as we assign the variable, so it 334# must come after the creation of descriptor 4 above. Likewise, we must never 335# unset this, as it has the side effect of closing descriptor 4, which we 336# use to show verbose tests to the user. 337# 338# Note also that we don't need or want to export it. The tracing is local to 339# this shell, and we would not want to influence any shells we exec. 340BASH_XTRACEFD=4 341 342test_failure=0 343test_count=0 344test_fixed=0 345test_broken=0 346test_success=0 347 348test_external_has_tap=0 349 350die () { 351 code=$? 352iftest -n"$GIT_EXIT_OK" 353then 354exit$code 355else 356echo>&5"FATAL: Unexpected exit with code$code" 357exit1 358fi 359} 360 361GIT_EXIT_OK= 362trap'die' EXIT 363trap'exit $?' INT 364 365# The user-facing functions are loaded from a separate file so that 366# test_perf subshells can have them too 367. "$TEST_DIRECTORY/test-lib-functions.sh" 368 369# You are not expected to call test_ok_ and test_failure_ directly, use 370# the test_expect_* functions instead. 371 372test_ok_ () { 373 test_success=$(($test_success + 1)) 374 say_color """ok$test_count- $@" 375} 376 377test_failure_ () { 378 test_failure=$(($test_failure + 1)) 379 say_color error "not ok$test_count-$1" 380shift 381printf'%s\n'"$*"|sed-e's/^/# /' 382test"$immediate"=""|| { GIT_EXIT_OK=t;exit1; } 383} 384 385test_known_broken_ok_ () { 386 test_fixed=$(($test_fixed+1)) 387 say_color error "ok$test_count- $@ # TODO known breakage vanished" 388} 389 390test_known_broken_failure_ () { 391 test_broken=$(($test_broken+1)) 392 say_color warn "not ok$test_count- $@ # TODO known breakage" 393} 394 395test_debug () { 396test"$debug"=""||eval"$1" 397} 398 399match_pattern_list () { 400 arg="$1" 401shift 402test -z"$*"&&return1 403for pattern_ 404do 405case"$arg"in 406$pattern_) 407return0 408esac 409done 410return1 411} 412 413match_test_selector_list () { 414 title="$1" 415shift 416 arg="$1" 417shift 418test -z"$1"&&return0 419 420# Both commas and whitespace are accepted as separators. 421 OLDIFS=$IFS 422 IFS=' ,' 423set --$1 424 IFS=$OLDIFS 425 426# If the first selector is negative we include by default. 427 include= 428case"$1"in 429!*) include=t ;; 430esac 431 432for selector 433do 434 orig_selector=$selector 435 436 positive=t 437case"$selector"in 438!*) 439 positive= 440 selector=${selector##?} 441;; 442esac 443 444test -z"$selector"&&continue 445 446case"$selector"in 447*-*) 448ifexpr"z${selector%%-*}":"z[0-9]*[^0-9]">/dev/null 449then 450echo"error:$title: invalid non-numeric in range" \ 451"start: '$orig_selector'">&2 452exit1 453fi 454ifexpr"z${selector#*-}":"z[0-9]*[^0-9]">/dev/null 455then 456echo"error:$title: invalid non-numeric in range" \ 457"end: '$orig_selector'">&2 458exit1 459fi 460;; 461*) 462ifexpr"z$selector":"z[0-9]*[^0-9]">/dev/null 463then 464echo"error:$title: invalid non-numeric in test" \ 465"selector: '$orig_selector'">&2 466exit1 467fi 468esac 469 470# Short cut for "obvious" cases 471test -z"$include"&&test -z"$positive"&&continue 472test -n"$include"&&test -n"$positive"&&continue 473 474case"$selector"in 475-*) 476iftest$arg-le${selector#-} 477then 478 include=$positive 479fi 480;; 481*-) 482iftest$arg-ge${selector%-} 483then 484 include=$positive 485fi 486;; 487*-*) 488iftest${selector%%-*}-le$arg \ 489&&test$arg-le${selector#*-} 490then 491 include=$positive 492fi 493;; 494*) 495iftest$arg-eq$selector 496then 497 include=$positive 498fi 499;; 500esac 501done 502 503test -n"$include" 504} 505 506maybe_teardown_verbose () { 507test -z"$verbose_only"&&return 508exec4>/dev/null 3>/dev/null 509 verbose= 510} 511 512last_verbose=t 513maybe_setup_verbose () { 514test -z"$verbose_only"&&return 515if match_pattern_list $test_count $verbose_only 516then 517exec4>&2 3>&1 518# Emit a delimiting blank line when going from 519# non-verbose to verbose. Within verbose mode the 520# delimiter is printed by test_expect_*. The choice 521# of the initial $last_verbose is such that before 522# test 1, we do not print it. 523test -z"$last_verbose"&&echo>&3"" 524 verbose=t 525else 526exec4>/dev/null 3>/dev/null 527 verbose= 528fi 529 last_verbose=$verbose 530} 531 532maybe_teardown_valgrind () { 533test -z"$GIT_VALGRIND"&&return 534 GIT_VALGRIND_ENABLED= 535} 536 537maybe_setup_valgrind () { 538test -z"$GIT_VALGRIND"&&return 539iftest -z"$valgrind_only" 540then 541 GIT_VALGRIND_ENABLED=t 542return 543fi 544 GIT_VALGRIND_ENABLED= 545if match_pattern_list $test_count $valgrind_only 546then 547 GIT_VALGRIND_ENABLED=t 548fi 549} 550 551want_trace () { 552test"$trace"= t &&test"$verbose"= t 553} 554 555# This is a separate function because some tests use 556# "return" to end a test_expect_success block early 557# (and we want to make sure we run any cleanup like 558# "set +x"). 559test_eval_inner_ () { 560# Do not add anything extra (including LF) after '$*' 561eval" 562 want_trace && set -x 563 $*" 564} 565 566test_eval_ () { 567# We run this block with stderr redirected to avoid extra cruft 568# during a "-x" trace. Once in "set -x" mode, we cannot prevent 569# the shell from printing the "set +x" to turn it off (nor the saving 570# of $? before that). But we can make sure that the output goes to 571# /dev/null. 572# 573# The test itself is run with stderr put back to &4 (so either to 574# /dev/null, or to the original stderr if --verbose was used). 575{ 576 test_eval_inner_ "$@"</dev/null >&3 2>&4 577 test_eval_ret_=$? 578if want_trace 579then 580set+x 581iftest"$test_eval_ret_"!=0 582then 583 say_color error >&4"error: last command exited with \$?=$test_eval_ret_" 584fi 585fi 586}2>/dev/null 587return$test_eval_ret_ 588} 589 590test_run_ () { 591 test_cleanup=: 592 expecting_failure=$2 593 594iftest"${GIT_TEST_CHAIN_LINT:-1}"!=0;then 595# turn off tracing for this test-eval, as it simply creates 596# confusing noise in the "-x" output 597 trace_tmp=$trace 598 trace= 599# 117 is magic because it is unlikely to match the exit 600# code of other programs 601 test_eval_ "(exit 117) &&$1" 602iftest"$?"!=117;then 603 error "bug in the test script: broken &&-chain:$1" 604fi 605 trace=$trace_tmp 606fi 607 608 setup_malloc_check 609 test_eval_ "$1" 610 eval_ret=$? 611 teardown_malloc_check 612 613iftest -z"$immediate"||test$eval_ret=0|| 614test -n"$expecting_failure"&&test"$test_cleanup"!=":" 615then 616 setup_malloc_check 617 test_eval_ "$test_cleanup" 618 teardown_malloc_check 619fi 620iftest"$verbose"="t"&&test -n"$HARNESS_ACTIVE" 621then 622echo"" 623fi 624return"$eval_ret" 625} 626 627test_start_ () { 628 test_count=$(($test_count+1)) 629 maybe_setup_verbose 630 maybe_setup_valgrind 631} 632 633test_finish_ () { 634echo>&3"" 635 maybe_teardown_valgrind 636 maybe_teardown_verbose 637} 638 639test_skip () { 640 to_skip= 641 skipped_reason= 642if match_pattern_list $this_test.$test_count $GIT_SKIP_TESTS 643then 644 to_skip=t 645 skipped_reason="GIT_SKIP_TESTS" 646fi 647iftest -z"$to_skip"&&test -n"$test_prereq"&& 648! test_have_prereq "$test_prereq" 649then 650 to_skip=t 651 652 of_prereq= 653iftest"$missing_prereq"!="$test_prereq" 654then 655 of_prereq=" of$test_prereq" 656fi 657 skipped_reason="missing$missing_prereq${of_prereq}" 658fi 659iftest -z"$to_skip"&&test -n"$run_list"&& 660! match_test_selector_list '--run'$test_count"$run_list" 661then 662 to_skip=t 663 skipped_reason="--run" 664fi 665 666case"$to_skip"in 667 t) 668 say_color skip >&3"skipping test: $@" 669 say_color skip "ok$test_count# skip$1($skipped_reason)" 670: true 671;; 672*) 673 false 674;; 675esac 676} 677 678# stub; perf-lib overrides it 679test_at_end_hook_ () { 680: 681} 682 683test_done () { 684 GIT_EXIT_OK=t 685 686iftest -z"$HARNESS_ACTIVE" 687then 688 test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results" 689mkdir-p"$test_results_dir" 690 base=${0##*/} 691 test_results_path="$test_results_dir/${base%.sh}.counts" 692 693cat>"$test_results_path"<<-EOF 694 total$test_count 695 success$test_success 696 fixed$test_fixed 697 broken$test_broken 698 failed$test_failure 699 700 EOF 701fi 702 703iftest"$test_fixed"!=0 704then 705 say_color error "#$test_fixedknown breakage(s) vanished; please update test(s)" 706fi 707iftest"$test_broken"!=0 708then 709 say_color warn "# still have$test_brokenknown breakage(s)" 710fi 711iftest"$test_broken"!=0||test"$test_fixed"!=0 712then 713 test_remaining=$(( $test_count - $test_broken - $test_fixed )) 714 msg="remaining$test_remainingtest(s)" 715else 716 test_remaining=$test_count 717 msg="$test_counttest(s)" 718fi 719case"$test_failure"in 7200) 721# Maybe print SKIP message 722iftest -n"$skip_all"&&test$test_count-gt0 723then 724 error "Can't use skip_all after running some tests" 725fi 726test -z"$skip_all"|| skip_all=" # SKIP$skip_all" 727 728iftest$test_external_has_tap-eq0 729then 730iftest$test_remaining-gt0 731then 732 say_color pass "# passed all$msg" 733fi 734 say "1..$test_count$skip_all" 735fi 736 737test -d"$remove_trash"&& 738cd"$(dirname "$remove_trash")"&& 739rm-rf"$(basename "$remove_trash")" 740 741 test_at_end_hook_ 742 743exit0;; 744 745*) 746iftest$test_external_has_tap-eq0 747then 748 say_color error "# failed$test_failureamong$msg" 749 say "1..$test_count" 750fi 751 752exit1;; 753 754esac 755} 756 757iftest -n"$valgrind" 758then 759 make_symlink () { 760test -h"$2"&& 761test"$1"="$(readlink "$2")"|| { 762# be super paranoid 763ifmkdir"$2".lock 764then 765rm-f"$2"&& 766ln-s"$1""$2"&& 767rm-r"$2".lock 768else 769whiletest -d"$2".lock 770do 771 say "Waiting for lock on$2." 772sleep1 773done 774fi 775} 776} 777 778 make_valgrind_symlink () { 779# handle only executables, unless they are shell libraries that 780# need to be in the exec-path. 781test -x"$1"|| 782test"# "="$(head -c 2 <"$1")"|| 783return; 784 785 base=$(basename "$1") 786 symlink_target=$GIT_BUILD_DIR/$base 787# do not override scripts 788iftest -x"$symlink_target"&& 789test!-d"$symlink_target"&& 790test"#!"!="$(head -c 2 < "$symlink_target")" 791then 792 symlink_target=../valgrind.sh 793fi 794case"$base"in 795*.sh|*.perl) 796 symlink_target=../unprocessed-script 797esac 798# create the link, or replace it if it is out of date 799 make_symlink "$symlink_target""$GIT_VALGRIND/bin/$base"||exit 800} 801 802# override all git executables in TEST_DIRECTORY/.. 803 GIT_VALGRIND=$TEST_DIRECTORY/valgrind 804mkdir-p"$GIT_VALGRIND"/bin 805forfilein$GIT_BUILD_DIR/git*$GIT_BUILD_DIR/t/helper/test-* 806do 807 make_valgrind_symlink $file 808done 809# special-case the mergetools loadables 810 make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools" 811 OLDIFS=$IFS 812 IFS=: 813for path in$PATH 814do 815ls"$path"/git-*2> /dev/null | 816whilereadfile 817do 818 make_valgrind_symlink "$file" 819done 820done 821 IFS=$OLDIFS 822 PATH=$GIT_VALGRIND/bin:$PATH 823 GIT_EXEC_PATH=$GIT_VALGRIND/bin 824export GIT_VALGRIND 825 GIT_VALGRIND_MODE="$valgrind" 826export GIT_VALGRIND_MODE 827 GIT_VALGRIND_ENABLED=t 828test -n"$valgrind_only"&& GIT_VALGRIND_ENABLED= 829export GIT_VALGRIND_ENABLED 830eliftest -n"$GIT_TEST_INSTALLED" 831then 832 GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path)|| 833 error "Cannot run git from$GIT_TEST_INSTALLED." 834 PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR:$PATH 835 GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH} 836else# normal case, use ../bin-wrappers only unless $with_dashes: 837 git_bin_dir="$GIT_BUILD_DIR/bin-wrappers" 838if!test -x"$git_bin_dir/git" 839then 840iftest -z"$with_dashes" 841then 842 say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH" 843fi 844 with_dashes=t 845fi 846 PATH="$git_bin_dir:$PATH" 847 GIT_EXEC_PATH=$GIT_BUILD_DIR 848iftest -n"$with_dashes" 849then 850 PATH="$GIT_BUILD_DIR:$PATH" 851fi 852fi 853GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt 854GIT_CONFIG_NOSYSTEM=1 855GIT_ATTR_NOSYSTEM=1 856export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM 857 858iftest -z"$GIT_TEST_CMP" 859then 860iftest -n"$GIT_TEST_CMP_USE_COPIED_CONTEXT" 861then 862 GIT_TEST_CMP="$DIFF-c" 863else 864 GIT_TEST_CMP="$DIFF-u" 865fi 866fi 867 868GITPERLLIB="$GIT_BUILD_DIR"/perl/blib/lib:"$GIT_BUILD_DIR"/perl/blib/arch/auto/Git 869export GITPERLLIB 870test -d"$GIT_BUILD_DIR"/templates/blt || { 871 error "You haven't built things yet, have you?" 872} 873 874if!test -x"$GIT_BUILD_DIR"/t/helper/test-chmtime 875then 876echo>&2'You need to build test-chmtime:' 877echo>&2'Run "make t/helper/test-chmtime" in the source (toplevel) directory' 878exit1 879fi 880 881# Test repository 882TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)" 883test -n"$root"&& TRASH_DIRECTORY="$root/$TRASH_DIRECTORY" 884case"$TRASH_DIRECTORY"in 885/*) ;;# absolute path is good 886*) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY";; 887esac 888test!-z"$debug"|| remove_trash=$TRASH_DIRECTORY 889rm-fr"$TRASH_DIRECTORY"|| { 890 GIT_EXIT_OK=t 891echo>&5"FATAL: Cannot prepare test area" 892exit1 893} 894 895HOME="$TRASH_DIRECTORY" 896GNUPGHOME="$HOME/gnupg-home-not-used" 897export HOME GNUPGHOME 898 899iftest -z"$TEST_NO_CREATE_REPO" 900then 901 test_create_repo "$TRASH_DIRECTORY" 902else 903mkdir-p"$TRASH_DIRECTORY" 904fi 905# Use -P to resolve symlinks in our working directory so that the cwd 906# in subprocesses like git equals our $PWD (for pathname comparisons). 907cd -P"$TRASH_DIRECTORY"||exit1 908 909this_test=${0##*/} 910this_test=${this_test%%-*} 911if match_pattern_list "$this_test"$GIT_SKIP_TESTS 912then 913 say_color info >&3"skipping test$this_testaltogether" 914 skip_all="skip all tests in$this_test" 915 test_done 916fi 917 918# Provide an implementation of the 'yes' utility 919yes() { 920iftest$#=0 921then 922 y=y 923else 924 y="$*" 925fi 926 927 i=0 928whiletest$i-lt99 929do 930echo"$y" 931 i=$(($i+1)) 932done 933} 934 935# Fix some commands on Windows 936case$(uname -s)in 937*MINGW*) 938# Windows has its own (incompatible) sort and find 939sort() { 940/usr/bin/sort"$@" 941} 942find() { 943/usr/bin/find"$@" 944} 945sum() { 946md5sum"$@" 947} 948# git sees Windows-style pwd 949pwd() { 950builtin pwd -W 951} 952# no POSIX permissions 953# backslashes in pathspec are converted to '/' 954# exec does not inherit the PID 955 test_set_prereq MINGW 956 test_set_prereq NATIVE_CRLF 957 test_set_prereq SED_STRIPS_CR 958 test_set_prereq GREP_STRIPS_CR 959 GIT_TEST_CMP=mingw_test_cmp 960;; 961*CYGWIN*) 962 test_set_prereq POSIXPERM 963 test_set_prereq EXECKEEPSPID 964 test_set_prereq CYGWIN 965 test_set_prereq SED_STRIPS_CR 966 test_set_prereq GREP_STRIPS_CR 967;; 968*) 969 test_set_prereq POSIXPERM 970 test_set_prereq BSLASHPSPEC 971 test_set_prereq EXECKEEPSPID 972;; 973esac 974 975( COLUMNS=1&&test$COLUMNS=1) && test_set_prereq COLUMNS_CAN_BE_1 976test -z"$NO_PERL"&& test_set_prereq PERL 977test -z"$NO_PYTHON"&& test_set_prereq PYTHON 978test -n"$USE_LIBPCRE"&& test_set_prereq LIBPCRE 979test -z"$NO_GETTEXT"&& test_set_prereq GETTEXT 980 981# Can we rely on git's output in the C locale? 982iftest -n"$GETTEXT_POISON" 983then 984 GIT_GETTEXT_POISON=YesPlease 985export GIT_GETTEXT_POISON 986 test_set_prereq GETTEXT_POISON 987else 988 test_set_prereq C_LOCALE_OUTPUT 989fi 990 991# Use this instead of test_cmp to compare files that contain expected and 992# actual output from git commands that can be translated. When running 993# under GETTEXT_POISON this pretends that the command produced expected 994# results. 995test_i18ncmp () { 996test -n"$GETTEXT_POISON"|| test_cmp "$@" 997} 998 999# Use this instead of "grep expected-string actual" to see if the1000# output from a git command that can be translated either contains an1001# expected string, or does not contain an unwanted one. When running1002# under GETTEXT_POISON this pretends that the command produced expected1003# results.1004test_i18ngrep () {1005iftest -n"$GETTEXT_POISON"1006then1007:# pretend success1008eliftest"x!"="x$1"1009then1010shift1011!grep"$@"1012else1013grep"$@"1014fi1015}10161017test_lazy_prereq PIPE '1018 # test whether the filesystem supports FIFOs1019 case$(uname -s)in1020 CYGWIN*|MINGW*)1021 false1022 ;;1023 *)1024 rm -f testfifo && mkfifo testfifo1025 ;;1026 esac1027'10281029test_lazy_prereq SYMLINKS '1030 # test whether the filesystem supports symbolic links1031 ln -s x y && test -h y1032'10331034test_lazy_prereq FILEMODE '1035 test "$(git config --bool core.filemode)" = true1036'10371038test_lazy_prereq CASE_INSENSITIVE_FS '1039 echo good >CamelCase &&1040 echo bad >camelcase &&1041 test "$(cat CamelCase)" != good1042'10431044test_lazy_prereq UTF8_NFD_TO_NFC '1045 # check whether FS converts nfd unicode to nfc1046 auml=$(printf "\303\244")1047 aumlcdiar=$(printf "\141\314\210")1048 >"$auml" &&1049 case "$(echo *)" in1050 "$aumlcdiar")1051 true ;;1052 *)1053 false ;;1054 esac1055'10561057test_lazy_prereq AUTOIDENT '1058 sane_unset GIT_AUTHOR_NAME &&1059 sane_unset GIT_AUTHOR_EMAIL &&1060 git var GIT_AUTHOR_IDENT1061'10621063test_lazy_prereq EXPENSIVE '1064 test -n "$GIT_TEST_LONG"1065'10661067test_lazy_prereq USR_BIN_TIME '1068 test -x /usr/bin/time1069'10701071test_lazy_prereq NOT_ROOT '1072 uid=$(id -u)&&1073 test "$uid" != 01074'10751076# SANITY is about "can you correctly predict what the filesystem would1077# do by only looking at the permission bits of the files and1078# directories?" A typical example of !SANITY is running the test1079# suite as root, where a test may expect "chmod -r file && cat file"1080# to fail because file is supposed to be unreadable after a successful1081# chmod. In an environment (i.e. combination of what filesystem is1082# being used and who is running the tests) that lacks SANITY, you may1083# be able to delete or create a file when the containing directory1084# doesn't have write permissions, or access a file even if the1085# containing directory doesn't have read or execute permissions.10861087test_lazy_prereq SANITY '1088 mkdir SANETESTD.1 SANETESTD.2 &&10891090 chmod +w SANETESTD.1 SANETESTD.2 &&1091 >SANETESTD.1/x 2>SANETESTD.2/x &&1092 chmod -w SANETESTD.1 &&1093 chmod -r SANETESTD.1/x &&1094 chmod -rx SANETESTD.2 ||1095 error "bug in test sript: cannot prepare SANETESTD"10961097 ! test -r SANETESTD.1/x &&1098 ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x1099 status=$?11001101 chmod +rwx SANETESTD.1 SANETESTD.2 &&1102 rm -rf SANETESTD.1 SANETESTD.2 ||1103 error "bug in test sript: cannot clean SANETESTD"1104 return$status1105'11061107GIT_UNZIP=${GIT_UNZIP:-unzip}1108test_lazy_prereq UNZIP '1109 "$GIT_UNZIP" -v1110 test $? -ne 1271111'11121113run_with_limited_cmdline () {1114(ulimit -s128&&"$@")1115}11161117test_lazy_prereq CMDLINE_LIMIT 'run_with_limited_cmdline true'11181119build_option () {1120 git version --build-options|1121sed-ne"s/^$1: //p"1122}11231124test_lazy_prereq LONG_IS_64BIT '1125 test 8 -le "$(build_option sizeof-long)"1126'