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