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