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# If we were built with ASAN, it may complain about leaks 40# of program-lifetime variables. Disable it by default to lower 41# the noise level. This needs to happen at the start of the script, 42# before we even do our "did we build git yet" check (since we don't 43# want that one to complain to stderr). 44:${ASAN_OPTIONS=detect_leaks=0:abort_on_error=1} 45export ASAN_OPTIONS 46 47# If LSAN is in effect we _do_ want leak checking, but we still 48# want to abort so that we notice the problems. 49:${LSAN_OPTIONS=abort_on_error=1} 50export LSAN_OPTIONS 51 52################################################################ 53# It appears that people try to run tests without building... 54"$GIT_BUILD_DIR/git">/dev/null 55iftest $? !=1 56then 57echo>&2'error: you do not seem to have built git yet.' 58exit1 59fi 60 61. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS 62export PERL_PATH SHELL_PATH 63 64# if --tee was passed, write the output not only to the terminal, but 65# additionally to the file test-results/$BASENAME.out, too. 66case"$GIT_TEST_TEE_STARTED, $* "in 67done,*) 68# do not redirect again 69;; 70*' --tee '*|*' --va'*|*' --verbose-log '*) 71mkdir-p"$TEST_OUTPUT_DIRECTORY/test-results" 72 BASE="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)" 73 74# Make this filename available to the sub-process in case it is using 75# --verbose-log. 76 GIT_TEST_TEE_OUTPUT_FILE=$BASE.out 77export GIT_TEST_TEE_OUTPUT_FILE 78 79# Truncate before calling "tee -a" to get rid of the results 80# from any previous runs. 81>"$GIT_TEST_TEE_OUTPUT_FILE" 82 83(GIT_TEST_TEE_STARTED=done${TEST_SHELL_PATH}"$0""$@"2>&1; 84echo $? >"$BASE.exit") |tee-a"$GIT_TEST_TEE_OUTPUT_FILE" 85test"$(cat "$BASE.exit")"=0 86exit 87;; 88esac 89 90# For repeatability, reset the environment to known value. 91# TERM is sanitized below, after saving color control sequences. 92LANG=C 93LC_ALL=C 94PAGER=cat 95TZ=UTC 96export LANG LC_ALL PAGER TZ 97EDITOR=: 98 99# GIT_TEST_GETTEXT_POISON should not influence git commands executed 100# during initialization of test-lib and the test repo. Back it up, 101# unset and then restore after initialization is finished. 102iftest -n"$GIT_TEST_GETTEXT_POISON" 103then 104 GIT_TEST_GETTEXT_POISON_ORIG=$GIT_TEST_GETTEXT_POISON 105unset GIT_TEST_GETTEXT_POISON 106fi 107 108# A call to "unset" with no arguments causes at least Solaris 10 109# /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets 110# deriving from the command substitution clustered with the other 111# ones. 112unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH"-e' 113 my @env = keys %ENV; 114 my$ok= join("|", qw( 115 TRACE 116 DEBUG 117 TEST 118 .*_TEST 119 PROVE 120 VALGRIND 121 UNZIP 122 PERF_ 123 CURL_VERBOSE 124 TRACE_CURL 125 )); 126 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env); 127 print join("\n", @vars); 128') 129unset XDG_CACHE_HOME 130unset XDG_CONFIG_HOME 131unset GITPERLLIB 132GIT_AUTHOR_EMAIL=author@example.com 133GIT_AUTHOR_NAME='A U Thor' 134GIT_COMMITTER_EMAIL=committer@example.com 135GIT_COMMITTER_NAME='C O Mitter' 136GIT_MERGE_VERBOSITY=5 137GIT_MERGE_AUTOEDIT=no 138export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT 139export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME 140export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME 141export EDITOR 142 143# Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output 144GIT_TRACE_BARE=1 145export GIT_TRACE_BARE 146 147check_var_migration () { 148# the warnings and hints given from this helper depends 149# on end-user settings, which will disrupt the self-test 150# done on the test framework itself. 151case"$GIT_TEST_FRAMEWORK_SELFTEST"in 152 t)return;; 153esac 154 155 old_name=$1 new_name=$2 156eval"old_isset=\${${old_name}:+isset}" 157eval"new_isset=\${${new_name}:+isset}" 158 159case"$old_isset,$new_isset"in 160 isset,) 161echo>&2"warning:$old_nameis now$new_name" 162echo>&2"hint: set$new_nametoo during the transition period" 163eval"$new_name=\$$old_name" 164;; 165 isset,isset) 166# do this later 167# echo >&2 "warning: $old_name is now $new_name" 168# echo >&2 "hint: remove $old_name" 169;; 170esac 171} 172 173check_var_migration GIT_FSMONITOR_TEST GIT_TEST_FSMONITOR 174check_var_migration TEST_GIT_INDEX_VERSION GIT_TEST_INDEX_VERSION 175check_var_migration GIT_FORCE_PRELOAD_TEST GIT_TEST_PRELOAD_INDEX 176 177# Use specific version of the index file format 178iftest -n"${GIT_TEST_INDEX_VERSION:+isset}" 179then 180 GIT_INDEX_VERSION="$GIT_TEST_INDEX_VERSION" 181export GIT_INDEX_VERSION 182fi 183 184# Add libc MALLOC and MALLOC_PERTURB test 185# only if we are not executing the test with valgrind 186ifexpr"$GIT_TEST_OPTS":".* --valgrind ">/dev/null || 187test -n"$TEST_NO_MALLOC_CHECK" 188then 189 setup_malloc_check () { 190: nothing 191} 192 teardown_malloc_check () { 193: nothing 194} 195else 196 setup_malloc_check () { 197 MALLOC_CHECK_=3 MALLOC_PERTURB_=165 198export MALLOC_CHECK_ MALLOC_PERTURB_ 199} 200 teardown_malloc_check () { 201unset MALLOC_CHECK_ MALLOC_PERTURB_ 202} 203fi 204 205# Protect ourselves from common misconfiguration to export 206# CDPATH into the environment 207unset CDPATH 208 209unset GREP_OPTIONS 210unset UNZIP 211 212case$(echo $GIT_TRACE |tr "[A-Z]" "[a-z]")in 2131|2|true) 214 GIT_TRACE=4 215;; 216esac 217 218# Convenience 219# 220# A regexp to match 5, 35 and 40 hexdigits 221_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' 222_x35="$_x05$_x05$_x05$_x05$_x05$_x05$_x05" 223_x40="$_x35$_x05" 224 225# Zero SHA-1 226_z40=0000000000000000000000000000000000000000 227 228OID_REGEX="$_x40" 229ZERO_OID=$_z40 230EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904 231EMPTY_BLOB=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 232 233# Line feed 234LF=' 235' 236 237# UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores 238# when case-folding filenames 239u200c=$(printf '\342\200\214') 240 241export _x05 _x35 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB ZERO_OID OID_REGEX 242 243# Each test should start with something like this, after copyright notices: 244# 245# test_description='Description of this test... 246# This test checks if command xyzzy does the right thing... 247# ' 248# . ./test-lib.sh 249test"x$TERM"!="xdumb"&& ( 250test -t1&& 251tput bold >/dev/null 2>&1&& 252tput setaf 1>/dev/null 2>&1&& 253tput sgr0 >/dev/null 2>&1 254) && 255 color=t 256 257whiletest"$#"-ne0 258do 259case"$1"in 260-d|--d|--de|--deb|--debu|--debug) 261 debug=t;shift;; 262-i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) 263 immediate=t;shift;; 264-l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) 265 GIT_TEST_LONG=t;export GIT_TEST_LONG;shift;; 266-r) 267shift;test"$#"-ne0|| { 268echo'error: -r requires an argument'>&2; 269exit1; 270} 271 run_list=$1;shift;; 272--run=*) 273 run_list=${1#--*=};shift;; 274-h|--h|--he|--hel|--help) 275help=t;shift;; 276-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) 277 verbose=t;shift;; 278--verbose-only=*) 279 verbose_only=${1#--*=} 280shift;; 281-q|--q|--qu|--qui|--quie|--quiet) 282# Ignore --quiet under a TAP::Harness. Saying how many tests 283# passed without the ok/not ok details is always an error. 284test -z"$HARNESS_ACTIVE"&& quiet=t;shift;; 285--with-dashes) 286 with_dashes=t;shift;; 287--no-color) 288 color=;shift;; 289--va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind) 290 valgrind=memcheck 291shift;; 292--valgrind=*) 293 valgrind=${1#--*=} 294shift;; 295--valgrind-only=*) 296 valgrind_only=${1#--*=} 297shift;; 298--tee) 299shift;;# was handled already 300--root=*) 301 root=${1#--*=} 302shift;; 303--chain-lint) 304 GIT_TEST_CHAIN_LINT=1 305shift;; 306--no-chain-lint) 307 GIT_TEST_CHAIN_LINT=0 308shift;; 309-x) 310# Some test scripts can't be reliably traced with '-x', 311# unless the test is run with a Bash version supporting 312# BASH_XTRACEFD (introduced in Bash v4.1). Check whether 313# this test is marked as such, and ignore '-x' if it 314# isn't executed with a suitable Bash version. 315iftest -z"$test_untraceable"|| { 316test -n"$BASH_VERSION"&& { 317test${BASH_VERSINFO[0]}-gt4|| { 318test${BASH_VERSINFO[0]}-eq4&& 319test${BASH_VERSINFO[1]}-ge1 320} 321} 322} 323then 324 trace=t 325else 326echo>&2"warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD" 327fi 328shift;; 329--verbose-log) 330 verbose_log=t 331shift;; 332*) 333echo"error: unknown test option '$1'">&2;exit1;; 334esac 335done 336 337iftest -n"$valgrind_only" 338then 339test -z"$valgrind"&& valgrind=memcheck 340test -z"$verbose"&& verbose_only="$valgrind_only" 341eliftest -n"$valgrind" 342then 343test -z"$verbose_log"&& verbose=t 344fi 345 346iftest -n"$trace"&&test -z"$verbose_log" 347then 348 verbose=t 349fi 350 351iftest -n"$color" 352then 353# Save the color control sequences now rather than run tput 354# each time say_color() is called. This is done for two 355# reasons: 356# * TERM will be changed to dumb 357# * HOME will be changed to a temporary directory and tput 358# might need to read ~/.terminfo from the original HOME 359# directory to get the control sequences 360# Note: This approach assumes the control sequences don't end 361# in a newline for any terminal of interest (command 362# substitutions strip trailing newlines). Given that most 363# (all?) terminals in common use are related to ECMA-48, this 364# shouldn't be a problem. 365 say_color_error=$(tput bold; tput setaf 1)# bold red 366 say_color_skip=$(tput setaf 4)# blue 367 say_color_warn=$(tput setaf 3)# brown/yellow 368 say_color_pass=$(tput setaf 2)# green 369 say_color_info=$(tput setaf 6)# cyan 370 say_color_reset=$(tput sgr0) 371 say_color_=""# no formatting for normal text 372 say_color () { 373test -z"$1"&&test -n"$quiet"&&return 374eval"say_color_color=\$say_color_$1" 375shift 376printf"%s\\n""$say_color_color$*$say_color_reset" 377} 378else 379 say_color() { 380test -z"$1"&&test -n"$quiet"&&return 381shift 382printf"%s\n""$*" 383} 384fi 385 386TERM=dumb 387export TERM 388 389error () { 390 say_color error "error: $*" 391 GIT_EXIT_OK=t 392exit1 393} 394 395say () { 396 say_color info "$*" 397} 398 399iftest -n"$HARNESS_ACTIVE" 400then 401iftest"$verbose"= t ||test -n"$verbose_only" 402then 403printf'Bail out! %s\n' \ 404'verbose mode forbidden under TAP harness; try --verbose-log' 405exit1 406fi 407fi 408 409test"${test_description}"!=""|| 410error "Test script did not set test_description." 411 412iftest"$help"="t" 413then 414printf'%s\n'"$test_description" 415exit0 416fi 417 418exec5>&1 419exec6<&0 420exec7>&2 421iftest"$verbose_log"="t" 422then 423exec3>>"$GIT_TEST_TEE_OUTPUT_FILE"4>&3 424eliftest"$verbose"="t" 425then 426exec4>&2 3>&1 427else 428exec4>/dev/null 3>/dev/null 429fi 430 431# Send any "-x" output directly to stderr to avoid polluting tests 432# which capture stderr. We can do this unconditionally since it 433# has no effect if tracing isn't turned on. 434# 435# Note that this sets up the trace fd as soon as we assign the variable, so it 436# must come after the creation of descriptor 4 above. Likewise, we must never 437# unset this, as it has the side effect of closing descriptor 4, which we 438# use to show verbose tests to the user. 439# 440# Note also that we don't need or want to export it. The tracing is local to 441# this shell, and we would not want to influence any shells we exec. 442BASH_XTRACEFD=4 443 444test_failure=0 445test_count=0 446test_fixed=0 447test_broken=0 448test_success=0 449 450test_external_has_tap=0 451 452die () { 453 code=$? 454iftest -n"$GIT_EXIT_OK" 455then 456exit$code 457else 458echo>&5"FATAL: Unexpected exit with code$code" 459exit1 460fi 461} 462 463GIT_EXIT_OK= 464trap'die' EXIT 465trap'exit $?' INT 466 467# The user-facing functions are loaded from a separate file so that 468# test_perf subshells can have them too 469. "$TEST_DIRECTORY/test-lib-functions.sh" 470 471# You are not expected to call test_ok_ and test_failure_ directly, use 472# the test_expect_* functions instead. 473 474test_ok_ () { 475 test_success=$(($test_success + 1)) 476 say_color """ok$test_count- $@" 477} 478 479test_failure_ () { 480 test_failure=$(($test_failure + 1)) 481 say_color error "not ok$test_count-$1" 482shift 483printf'%s\n'"$*"|sed-e's/^/# /' 484test"$immediate"=""|| { GIT_EXIT_OK=t;exit1; } 485} 486 487test_known_broken_ok_ () { 488 test_fixed=$(($test_fixed+1)) 489 say_color error "ok$test_count- $@ # TODO known breakage vanished" 490} 491 492test_known_broken_failure_ () { 493 test_broken=$(($test_broken+1)) 494 say_color warn "not ok$test_count- $@ # TODO known breakage" 495} 496 497test_debug () { 498test"$debug"=""||eval"$1" 499} 500 501match_pattern_list () { 502 arg="$1" 503shift 504test -z"$*"&&return1 505for pattern_ 506do 507case"$arg"in 508$pattern_) 509return0 510esac 511done 512return1 513} 514 515match_test_selector_list () { 516 title="$1" 517shift 518 arg="$1" 519shift 520test -z"$1"&&return0 521 522# Both commas and whitespace are accepted as separators. 523 OLDIFS=$IFS 524 IFS=' ,' 525set --$1 526 IFS=$OLDIFS 527 528# If the first selector is negative we include by default. 529 include= 530case"$1"in 531!*) include=t ;; 532esac 533 534for selector 535do 536 orig_selector=$selector 537 538 positive=t 539case"$selector"in 540!*) 541 positive= 542 selector=${selector##?} 543;; 544esac 545 546test -z"$selector"&&continue 547 548case"$selector"in 549*-*) 550ifexpr"z${selector%%-*}":"z[0-9]*[^0-9]">/dev/null 551then 552echo"error:$title: invalid non-numeric in range" \ 553"start: '$orig_selector'">&2 554exit1 555fi 556ifexpr"z${selector#*-}":"z[0-9]*[^0-9]">/dev/null 557then 558echo"error:$title: invalid non-numeric in range" \ 559"end: '$orig_selector'">&2 560exit1 561fi 562;; 563*) 564ifexpr"z$selector":"z[0-9]*[^0-9]">/dev/null 565then 566echo"error:$title: invalid non-numeric in test" \ 567"selector: '$orig_selector'">&2 568exit1 569fi 570esac 571 572# Short cut for "obvious" cases 573test -z"$include"&&test -z"$positive"&&continue 574test -n"$include"&&test -n"$positive"&&continue 575 576case"$selector"in 577-*) 578iftest$arg-le${selector#-} 579then 580 include=$positive 581fi 582;; 583*-) 584iftest$arg-ge${selector%-} 585then 586 include=$positive 587fi 588;; 589*-*) 590iftest${selector%%-*}-le$arg \ 591&&test$arg-le${selector#*-} 592then 593 include=$positive 594fi 595;; 596*) 597iftest$arg-eq$selector 598then 599 include=$positive 600fi 601;; 602esac 603done 604 605test -n"$include" 606} 607 608maybe_teardown_verbose () { 609test -z"$verbose_only"&&return 610exec4>/dev/null 3>/dev/null 611 verbose= 612} 613 614last_verbose=t 615maybe_setup_verbose () { 616test -z"$verbose_only"&&return 617if match_pattern_list $test_count $verbose_only 618then 619exec4>&2 3>&1 620# Emit a delimiting blank line when going from 621# non-verbose to verbose. Within verbose mode the 622# delimiter is printed by test_expect_*. The choice 623# of the initial $last_verbose is such that before 624# test 1, we do not print it. 625test -z"$last_verbose"&&echo>&3"" 626 verbose=t 627else 628exec4>/dev/null 3>/dev/null 629 verbose= 630fi 631 last_verbose=$verbose 632} 633 634maybe_teardown_valgrind () { 635test -z"$GIT_VALGRIND"&&return 636 GIT_VALGRIND_ENABLED= 637} 638 639maybe_setup_valgrind () { 640test -z"$GIT_VALGRIND"&&return 641iftest -z"$valgrind_only" 642then 643 GIT_VALGRIND_ENABLED=t 644return 645fi 646 GIT_VALGRIND_ENABLED= 647if match_pattern_list $test_count $valgrind_only 648then 649 GIT_VALGRIND_ENABLED=t 650fi 651} 652 653want_trace () { 654test"$trace"= t && { 655test"$verbose"= t ||test"$verbose_log"= t 656} 657} 658 659# This is a separate function because some tests use 660# "return" to end a test_expect_success block early 661# (and we want to make sure we run any cleanup like 662# "set +x"). 663test_eval_inner_ () { 664# Do not add anything extra (including LF) after '$*' 665eval" 666 want_trace && set -x 667 $*" 668} 669 670test_eval_ () { 671# If "-x" tracing is in effect, then we want to avoid polluting stderr 672# with non-test commands. But once in "set -x" mode, we cannot prevent 673# the shell from printing the "set +x" to turn it off (nor the saving 674# of $? before that). But we can make sure that the output goes to 675# /dev/null. 676# 677# There are a few subtleties here: 678# 679# - we have to redirect descriptor 4 in addition to 2, to cover 680# BASH_XTRACEFD 681# 682# - the actual eval has to come before the redirection block (since 683# it needs to see descriptor 4 to set up its stderr) 684# 685# - likewise, any error message we print must be outside the block to 686# access descriptor 4 687# 688# - checking $? has to come immediately after the eval, but it must 689# be _inside_ the block to avoid polluting the "set -x" output 690# 691 692 test_eval_inner_ "$@"</dev/null >&3 2>&4 693{ 694 test_eval_ret_=$? 695if want_trace 696then 697set+x 698fi 699}2>/dev/null 4>&2 700 701iftest"$test_eval_ret_"!=0&& want_trace 702then 703 say_color error >&4"error: last command exited with \$?=$test_eval_ret_" 704fi 705return$test_eval_ret_ 706} 707 708test_run_ () { 709 test_cleanup=: 710 expecting_failure=$2 711 712iftest"${GIT_TEST_CHAIN_LINT:-1}"!=0;then 713# turn off tracing for this test-eval, as it simply creates 714# confusing noise in the "-x" output 715 trace_tmp=$trace 716 trace= 717# 117 is magic because it is unlikely to match the exit 718# code of other programs 719if$(printf '%s\n' "$1" | sed -f "$GIT_BUILD_DIR/t/chainlint.sed" | grep -q '?![A-Z][A-Z]*?!')|| 720test"OK-117"!="$(test_eval_ "(exit 117)&&$1${LF}${LF}echo OK-\$?"3>&1)" 721 then 722 error "bug in the testscript: broken &&-chain or run-away HERE-DOC:$1" 723 fi 724 trace=$trace_tmp 725 fi 726 727 setup_malloc_check 728 test_eval_ "$1" 729 eval_ret=$? 730 teardown_malloc_check 731 732 if test -z "$immediate" || test$eval_ret= 0 || 733 test -n "$expecting_failure" && test "$test_cleanup" != ":" 734 then 735 setup_malloc_check 736 test_eval_ "$test_cleanup" 737 teardown_malloc_check 738 fi 739 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE" 740 then 741 echo "" 742 fi 743 return "$eval_ret" 744} 745 746test_start_ () { 747 test_count=$(($test_count+1)) 748 maybe_setup_verbose 749 maybe_setup_valgrind 750} 751 752test_finish_ () { 753 echo >&3 "" 754 maybe_teardown_valgrind 755 maybe_teardown_verbose 756} 757 758test_skip () { 759 to_skip= 760 skipped_reason= 761 if match_pattern_list$this_test.$test_count$GIT_SKIP_TESTS 762 then 763 to_skip=t 764 skipped_reason="GIT_SKIP_TESTS" 765 fi 766 if test -z "$to_skip" && test -n "$test_prereq" && 767 ! test_have_prereq "$test_prereq" 768 then 769 to_skip=t 770 771 of_prereq= 772 if test "$missing_prereq" != "$test_prereq" 773 then 774 of_prereq=" of $test_prereq" 775 fi 776 skipped_reason="missing $missing_prereq${of_prereq}" 777 fi 778 if test -z "$to_skip" && test -n "$run_list" && 779 ! match_test_selector_list '--run'$test_count"$run_list" 780 then 781 to_skip=t 782 skipped_reason="--run" 783 fi 784 785 case "$to_skip" in 786 t) 787 say_color skip >&3 "skipping test: $@" 788 say_color skip "ok $test_count# skip $1 ($skipped_reason)" 789: true 790;; 791*) 792 false 793;; 794esac 795} 796 797# stub; perf-lib overrides it 798test_at_end_hook_ () { 799: 800} 801 802test_done () { 803 GIT_EXIT_OK=t 804 805iftest -z"$HARNESS_ACTIVE" 806then 807 test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results" 808mkdir-p"$test_results_dir" 809 base=${0##*/} 810 test_results_path="$test_results_dir/${base%.sh}.counts" 811 812cat>"$test_results_path"<<-EOF 813 total$test_count 814 success$test_success 815 fixed$test_fixed 816 broken$test_broken 817 failed$test_failure 818 819 EOF 820fi 821 822iftest"$test_fixed"!=0 823then 824 say_color error "#$test_fixedknown breakage(s) vanished; please update test(s)" 825fi 826iftest"$test_broken"!=0 827then 828 say_color warn "# still have$test_brokenknown breakage(s)" 829fi 830iftest"$test_broken"!=0||test"$test_fixed"!=0 831then 832 test_remaining=$(( $test_count - $test_broken - $test_fixed )) 833 msg="remaining$test_remainingtest(s)" 834else 835 test_remaining=$test_count 836 msg="$test_counttest(s)" 837fi 838case"$test_failure"in 8390) 840iftest$test_external_has_tap-eq0 841then 842iftest$test_remaining-gt0 843then 844 say_color pass "# passed all$msg" 845fi 846 847# Maybe print SKIP message 848test -z"$skip_all"|| skip_all="# SKIP$skip_all" 849case"$test_count"in 8500) 851 say "1..$test_count${skip_all:+ $skip_all}" 852;; 853*) 854test -z"$skip_all"|| 855 say_color warn "$skip_all" 856 say "1..$test_count" 857;; 858esac 859fi 860 861iftest -z"$debug" 862then 863test -d"$TRASH_DIRECTORY"|| 864 error "Tests passed but trash directory already removed before test cleanup; aborting" 865 866cd"$TRASH_DIRECTORY/.."&& 867rm-fr"$TRASH_DIRECTORY"|| 868 error "Tests passed but test cleanup failed; aborting" 869fi 870 test_at_end_hook_ 871 872exit0;; 873 874*) 875iftest$test_external_has_tap-eq0 876then 877 say_color error "# failed$test_failureamong$msg" 878 say "1..$test_count" 879fi 880 881exit1;; 882 883esac 884} 885 886iftest -n"$valgrind" 887then 888 make_symlink () { 889test -h"$2"&& 890test"$1"="$(readlink "$2")"|| { 891# be super paranoid 892ifmkdir"$2".lock 893then 894rm-f"$2"&& 895ln-s"$1""$2"&& 896rm-r"$2".lock 897else 898whiletest -d"$2".lock 899do 900 say "Waiting for lock on$2." 901sleep1 902done 903fi 904} 905} 906 907 make_valgrind_symlink () { 908# handle only executables, unless they are shell libraries that 909# need to be in the exec-path. 910test -x"$1"|| 911test"# "="$(test_copy_bytes 2 <"$1")"|| 912return; 913 914 base=$(basename "$1") 915case"$base"in 916test-*) 917 symlink_target="$GIT_BUILD_DIR/t/helper/$base" 918;; 919*) 920 symlink_target="$GIT_BUILD_DIR/$base" 921;; 922esac 923# do not override scripts 924iftest -x"$symlink_target"&& 925test!-d"$symlink_target"&& 926test"#!"!="$(test_copy_bytes 2 <"$symlink_target")" 927then 928 symlink_target=../valgrind.sh 929fi 930case"$base"in 931*.sh|*.perl) 932 symlink_target=../unprocessed-script 933esac 934# create the link, or replace it if it is out of date 935 make_symlink "$symlink_target""$GIT_VALGRIND/bin/$base"||exit 936} 937 938# override all git executables in TEST_DIRECTORY/.. 939 GIT_VALGRIND=$TEST_DIRECTORY/valgrind 940mkdir-p"$GIT_VALGRIND"/bin 941forfilein$GIT_BUILD_DIR/git*$GIT_BUILD_DIR/t/helper/test-* 942do 943 make_valgrind_symlink $file 944done 945# special-case the mergetools loadables 946 make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools" 947 OLDIFS=$IFS 948 IFS=: 949for path in$PATH 950do 951ls"$path"/git-*2> /dev/null | 952whilereadfile 953do 954 make_valgrind_symlink "$file" 955done 956done 957 IFS=$OLDIFS 958 PATH=$GIT_VALGRIND/bin:$PATH 959 GIT_EXEC_PATH=$GIT_VALGRIND/bin 960export GIT_VALGRIND 961 GIT_VALGRIND_MODE="$valgrind" 962export GIT_VALGRIND_MODE 963 GIT_VALGRIND_ENABLED=t 964test -n"$valgrind_only"&& GIT_VALGRIND_ENABLED= 965export GIT_VALGRIND_ENABLED 966eliftest -n"$GIT_TEST_INSTALLED" 967then 968 GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path)|| 969 error "Cannot run git from$GIT_TEST_INSTALLED." 970 PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR:$PATH 971 GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH} 972else# normal case, use ../bin-wrappers only unless $with_dashes: 973 git_bin_dir="$GIT_BUILD_DIR/bin-wrappers" 974if!test -x"$git_bin_dir/git" 975then 976iftest -z"$with_dashes" 977then 978 say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH" 979fi 980 with_dashes=t 981fi 982 PATH="$git_bin_dir:$PATH" 983 GIT_EXEC_PATH=$GIT_BUILD_DIR 984iftest -n"$with_dashes" 985then 986 PATH="$GIT_BUILD_DIR:$PATH" 987fi 988fi 989GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt 990GIT_CONFIG_NOSYSTEM=1 991GIT_ATTR_NOSYSTEM=1 992export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM 993 994iftest -z"$GIT_TEST_CMP" 995then 996iftest -n"$GIT_TEST_CMP_USE_COPIED_CONTEXT" 997then 998 GIT_TEST_CMP="$DIFF-c" 999else1000 GIT_TEST_CMP="$DIFF-u"1001fi1002fi10031004GITPERLLIB="$GIT_BUILD_DIR"/perl/build/lib1005export GITPERLLIB1006test -d"$GIT_BUILD_DIR"/templates/blt || {1007 error "You haven't built things yet, have you?"1008}10091010if!test -x"$GIT_BUILD_DIR"/t/helper/test-tool1011then1012echo>&2'You need to build test-tool:'1013echo>&2'Run "make t/helper/test-tool" in the source (toplevel) directory'1014exit11015fi10161017# Test repository1018TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)"1019test -n"$root"&& TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"1020case"$TRASH_DIRECTORY"in1021/*) ;;# absolute path is good1022*) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY";;1023esac1024rm-fr"$TRASH_DIRECTORY"|| {1025 GIT_EXIT_OK=t1026echo>&5"FATAL: Cannot prepare test area"1027exit11028}10291030HOME="$TRASH_DIRECTORY"1031GNUPGHOME="$HOME/gnupg-home-not-used"1032export HOME GNUPGHOME10331034iftest -z"$TEST_NO_CREATE_REPO"1035then1036 test_create_repo "$TRASH_DIRECTORY"1037else1038mkdir-p"$TRASH_DIRECTORY"1039fi1040# Use -P to resolve symlinks in our working directory so that the cwd1041# in subprocesses like git equals our $PWD (for pathname comparisons).1042cd -P"$TRASH_DIRECTORY"||exit110431044this_test=${0##*/}1045this_test=${this_test%%-*}1046if match_pattern_list "$this_test"$GIT_SKIP_TESTS1047then1048 say_color info >&3"skipping test$this_testaltogether"1049 skip_all="skip all tests in$this_test"1050 test_done1051fi10521053# Provide an implementation of the 'yes' utility1054yes() {1055iftest$#=01056then1057 y=y1058else1059 y="$*"1060fi10611062 i=01063whiletest$i-lt991064do1065echo"$y"1066 i=$(($i+1))1067done1068}10691070# Fix some commands on Windows1071uname_s=$(uname -s)1072case$uname_sin1073*MINGW*)1074# Windows has its own (incompatible) sort and find1075sort() {1076/usr/bin/sort"$@"1077}1078find() {1079/usr/bin/find"$@"1080}1081# git sees Windows-style pwd1082pwd() {1083builtin pwd -W1084}1085# no POSIX permissions1086# backslashes in pathspec are converted to '/'1087# exec does not inherit the PID1088 test_set_prereq MINGW1089 test_set_prereq NATIVE_CRLF1090 test_set_prereq SED_STRIPS_CR1091 test_set_prereq GREP_STRIPS_CR1092 GIT_TEST_CMP=mingw_test_cmp1093;;1094*CYGWIN*)1095 test_set_prereq POSIXPERM1096 test_set_prereq EXECKEEPSPID1097 test_set_prereq CYGWIN1098 test_set_prereq SED_STRIPS_CR1099 test_set_prereq GREP_STRIPS_CR1100;;1101*)1102 test_set_prereq POSIXPERM1103 test_set_prereq BSLASHPSPEC1104 test_set_prereq EXECKEEPSPID1105;;1106esac11071108( COLUMNS=1&&test$COLUMNS=1) && test_set_prereq COLUMNS_CAN_BE_11109test -z"$NO_PERL"&& test_set_prereq PERL1110test -z"$NO_PTHREADS"&& test_set_prereq PTHREADS1111test -z"$NO_PYTHON"&& test_set_prereq PYTHON1112test -n"$USE_LIBPCRE1$USE_LIBPCRE2"&& test_set_prereq PCRE1113test -n"$USE_LIBPCRE1"&& test_set_prereq LIBPCRE11114test -n"$USE_LIBPCRE2"&& test_set_prereq LIBPCRE21115test -z"$NO_GETTEXT"&& test_set_prereq GETTEXT11161117iftest -n"$GIT_TEST_GETTEXT_POISON_ORIG"1118then1119 GIT_TEST_GETTEXT_POISON=$GIT_TEST_GETTEXT_POISON_ORIG1120unset GIT_TEST_GETTEXT_POISON_ORIG1121fi11221123# Can we rely on git's output in the C locale?1124iftest -z"$GIT_TEST_GETTEXT_POISON"1125then1126 test_set_prereq C_LOCALE_OUTPUT1127fi11281129iftest -z"$GIT_TEST_CHECK_CACHE_TREE"1130then1131 GIT_TEST_CHECK_CACHE_TREE=true1132export GIT_TEST_CHECK_CACHE_TREE1133fi11341135test_lazy_prereq PIPE '1136 # test whether the filesystem supports FIFOs1137 test_have_prereq !MINGW,!CYGWIN &&1138 rm -f testfifo && mkfifo testfifo1139'11401141test_lazy_prereq SYMLINKS '1142 # test whether the filesystem supports symbolic links1143 ln -s x y && test -h y1144'11451146test_lazy_prereq FILEMODE '1147 test "$(git config --bool core.filemode)" = true1148'11491150test_lazy_prereq CASE_INSENSITIVE_FS '1151 echo good >CamelCase &&1152 echo bad >camelcase &&1153 test "$(cat CamelCase)" != good1154'11551156test_lazy_prereq FUNNYNAMES '1157 test_have_prereq !MINGW &&1158 touch -- \1159 "FUNNYNAMES tab embedded" \1160 "FUNNYNAMES\"quote embedded\"" \1161 "FUNNYNAMES newline1162embedded" 2>/dev/null &&1163 rm -- \1164 "FUNNYNAMES tab embedded" \1165 "FUNNYNAMES\"quote embedded\"" \1166 "FUNNYNAMES newline1167embedded" 2>/dev/null1168'11691170test_lazy_prereq UTF8_NFD_TO_NFC '1171 # check whether FS converts nfd unicode to nfc1172 auml=$(printf "\303\244")1173 aumlcdiar=$(printf "\141\314\210")1174 >"$auml" &&1175 test -f "$aumlcdiar"1176'11771178test_lazy_prereq AUTOIDENT '1179 sane_unset GIT_AUTHOR_NAME &&1180 sane_unset GIT_AUTHOR_EMAIL &&1181 git var GIT_AUTHOR_IDENT1182'11831184test_lazy_prereq EXPENSIVE '1185 test -n "$GIT_TEST_LONG"1186'11871188test_lazy_prereq EXPENSIVE_ON_WINDOWS '1189 test_have_prereq EXPENSIVE || test_have_prereq !MINGW,!CYGWIN1190'11911192test_lazy_prereq USR_BIN_TIME '1193 test -x /usr/bin/time1194'11951196test_lazy_prereq NOT_ROOT '1197 uid=$(id -u)&&1198 test "$uid" != 01199'12001201test_lazy_prereq JGIT '1202 type jgit1203'12041205# SANITY is about "can you correctly predict what the filesystem would1206# do by only looking at the permission bits of the files and1207# directories?" A typical example of !SANITY is running the test1208# suite as root, where a test may expect "chmod -r file && cat file"1209# to fail because file is supposed to be unreadable after a successful1210# chmod. In an environment (i.e. combination of what filesystem is1211# being used and who is running the tests) that lacks SANITY, you may1212# be able to delete or create a file when the containing directory1213# doesn't have write permissions, or access a file even if the1214# containing directory doesn't have read or execute permissions.12151216test_lazy_prereq SANITY '1217 mkdir SANETESTD.1 SANETESTD.2 &&12181219 chmod +w SANETESTD.1 SANETESTD.2 &&1220 >SANETESTD.1/x 2>SANETESTD.2/x &&1221 chmod -w SANETESTD.1 &&1222 chmod -r SANETESTD.1/x &&1223 chmod -rx SANETESTD.2 ||1224 error "bug in test sript: cannot prepare SANETESTD"12251226 ! test -r SANETESTD.1/x &&1227 ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x1228 status=$?12291230 chmod +rwx SANETESTD.1 SANETESTD.2 &&1231 rm -rf SANETESTD.1 SANETESTD.2 ||1232 error "bug in test sript: cannot clean SANETESTD"1233 return$status1234'12351236test FreeBSD !=$uname_s|| GIT_UNZIP=${GIT_UNZIP:-/usr/local/bin/unzip}1237GIT_UNZIP=${GIT_UNZIP:-unzip}1238test_lazy_prereq UNZIP '1239 "$GIT_UNZIP" -v1240 test $? -ne 1271241'12421243run_with_limited_cmdline () {1244(ulimit -s128&&"$@")1245}12461247test_lazy_prereq CMDLINE_LIMIT '1248 test_have_prereq !MINGW,!CYGWIN &&1249 run_with_limited_cmdline true1250'12511252run_with_limited_stack () {1253(ulimit -s128&&"$@")1254}12551256test_lazy_prereq ULIMIT_STACK_SIZE '1257 test_have_prereq !MINGW,!CYGWIN &&1258 run_with_limited_stack true1259'12601261build_option () {1262 git version --build-options|1263sed-ne"s/^$1: //p"1264}12651266test_lazy_prereq LONG_IS_64BIT '1267 test 8 -le "$(build_option sizeof-long)"1268'12691270test_lazy_prereq TIME_IS_64BIT 'test-tool date is64bit'1271test_lazy_prereq TIME_T_IS_64BIT 'test-tool date time_t-is64bit'12721273test_lazy_prereq CURL '1274 curl --version1275'12761277# SHA1 is a test if the hash algorithm in use is SHA-1. This is both for tests1278# which will not work with other hash algorithms and tests that work but don't1279# test anything meaningful (e.g. special values which cause short collisions).1280test_lazy_prereq SHA1 '1281 test$(git hash-object /dev/null)= e69de29bb2d1d6434b8b29ae775ad8c2e48c53911282'