t / test-lib.shon commit test-lib: use DIFF definition from GIT-BUILD-OPTIONS (5e87eae)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6# if --tee was passed, write the output not only to the terminal, but
   7# additionally to the file test-results/$BASENAME.out, too.
   8case "$GIT_TEST_TEE_STARTED, $* " in
   9done,*)
  10        # do not redirect again
  11        ;;
  12*' --tee '*|*' --va'*)
  13        mkdir -p test-results
  14        BASE=test-results/$(basename "$0" .sh)
  15        (GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1;
  16         echo $? > $BASE.exit) | tee $BASE.out
  17        test "$(cat $BASE.exit)" = 0
  18        exit
  19        ;;
  20esac
  21
  22# Keep the original TERM for say_color
  23ORIGINAL_TERM=$TERM
  24
  25# For repeatability, reset the environment to known value.
  26LANG=C
  27LC_ALL=C
  28PAGER=cat
  29TZ=UTC
  30TERM=dumb
  31export LANG LC_ALL PAGER TERM TZ
  32EDITOR=:
  33unset VISUAL
  34unset GIT_EDITOR
  35unset AUTHOR_DATE
  36unset AUTHOR_EMAIL
  37unset AUTHOR_NAME
  38unset COMMIT_AUTHOR_EMAIL
  39unset COMMIT_AUTHOR_NAME
  40unset EMAIL
  41unset GIT_ALTERNATE_OBJECT_DIRECTORIES
  42unset GIT_AUTHOR_DATE
  43GIT_AUTHOR_EMAIL=author@example.com
  44GIT_AUTHOR_NAME='A U Thor'
  45unset GIT_COMMITTER_DATE
  46GIT_COMMITTER_EMAIL=committer@example.com
  47GIT_COMMITTER_NAME='C O Mitter'
  48unset GIT_DIFF_OPTS
  49unset GIT_DIR
  50unset GIT_WORK_TREE
  51unset GIT_EXTERNAL_DIFF
  52unset GIT_INDEX_FILE
  53unset GIT_OBJECT_DIRECTORY
  54unset GIT_CEILING_DIRECTORIES
  55unset SHA1_FILE_DIRECTORIES
  56unset SHA1_FILE_DIRECTORY
  57unset GIT_NOTES_REF
  58unset GIT_NOTES_DISPLAY_REF
  59unset GIT_NOTES_REWRITE_REF
  60unset GIT_NOTES_REWRITE_MODE
  61GIT_MERGE_VERBOSITY=5
  62export GIT_MERGE_VERBOSITY
  63export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
  64export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
  65export EDITOR
  66
  67# Protect ourselves from common misconfiguration to export
  68# CDPATH into the environment
  69unset CDPATH
  70
  71unset GREP_OPTIONS
  72
  73case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in
  74        1|2|true)
  75                echo "* warning: Some tests will not work if GIT_TRACE" \
  76                        "is set as to trace on STDERR ! *"
  77                echo "* warning: Please set GIT_TRACE to something" \
  78                        "other than 1, 2 or true ! *"
  79                ;;
  80esac
  81
  82# Convenience
  83#
  84# A regexp to match 5 and 40 hexdigits
  85_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
  86_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
  87
  88# Each test should start with something like this, after copyright notices:
  89#
  90# test_description='Description of this test...
  91# This test checks if command xyzzy does the right thing...
  92# '
  93# . ./test-lib.sh
  94[ "x$ORIGINAL_TERM" != "xdumb" ] && (
  95                TERM=$ORIGINAL_TERM &&
  96                export TERM &&
  97                [ -t 1 ] &&
  98                tput bold >/dev/null 2>&1 &&
  99                tput setaf 1 >/dev/null 2>&1 &&
 100                tput sgr0 >/dev/null 2>&1
 101        ) &&
 102        color=t
 103
 104while test "$#" -ne 0
 105do
 106        case "$1" in
 107        -d|--d|--de|--deb|--debu|--debug)
 108                debug=t; shift ;;
 109        -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
 110                immediate=t; shift ;;
 111        -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
 112                GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;;
 113        -h|--h|--he|--hel|--help)
 114                help=t; shift ;;
 115        -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
 116                verbose=t; shift ;;
 117        -q|--q|--qu|--qui|--quie|--quiet)
 118                quiet=t; shift ;;
 119        --with-dashes)
 120                with_dashes=t; shift ;;
 121        --no-color)
 122                color=; shift ;;
 123        --no-python)
 124                # noop now...
 125                shift ;;
 126        --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
 127                valgrind=t; verbose=t; shift ;;
 128        --tee)
 129                shift ;; # was handled already
 130        --root=*)
 131                root=$(expr "z$1" : 'z[^=]*=\(.*\)')
 132                shift ;;
 133        *)
 134                echo "error: unknown test option '$1'" >&2; exit 1 ;;
 135        esac
 136done
 137
 138if test -n "$color"; then
 139        say_color () {
 140                (
 141                TERM=$ORIGINAL_TERM
 142                export TERM
 143                case "$1" in
 144                        error) tput bold; tput setaf 1;; # bold red
 145                        skip)  tput bold; tput setaf 2;; # bold green
 146                        pass)  tput setaf 2;;            # green
 147                        info)  tput setaf 3;;            # brown
 148                        *) test -n "$quiet" && return;;
 149                esac
 150                shift
 151                printf "* %s" "$*"
 152                tput sgr0
 153                echo
 154                )
 155        }
 156else
 157        say_color() {
 158                test -z "$1" && test -n "$quiet" && return
 159                shift
 160                echo "* $*"
 161        }
 162fi
 163
 164error () {
 165        say_color error "error: $*"
 166        GIT_EXIT_OK=t
 167        exit 1
 168}
 169
 170say () {
 171        say_color info "$*"
 172}
 173
 174test "${test_description}" != "" ||
 175error "Test script did not set test_description."
 176
 177if test "$help" = "t"
 178then
 179        echo "$test_description"
 180        exit 0
 181fi
 182
 183exec 5>&1
 184if test "$verbose" = "t"
 185then
 186        exec 4>&2 3>&1
 187else
 188        exec 4>/dev/null 3>/dev/null
 189fi
 190
 191test_failure=0
 192test_count=0
 193test_fixed=0
 194test_broken=0
 195test_success=0
 196
 197die () {
 198        code=$?
 199        if test -n "$GIT_EXIT_OK"
 200        then
 201                exit $code
 202        else
 203                echo >&5 "FATAL: Unexpected exit with code $code"
 204                exit 1
 205        fi
 206}
 207
 208GIT_EXIT_OK=
 209trap 'die' EXIT
 210
 211# The semantics of the editor variables are that of invoking
 212# sh -c "$EDITOR \"$@\"" files ...
 213#
 214# If our trash directory contains shell metacharacters, they will be
 215# interpreted if we just set $EDITOR directly, so do a little dance with
 216# environment variables to work around this.
 217#
 218# In particular, quoting isn't enough, as the path may contain the same quote
 219# that we're using.
 220test_set_editor () {
 221        FAKE_EDITOR="$1"
 222        export FAKE_EDITOR
 223        EDITOR='"$FAKE_EDITOR"'
 224        export EDITOR
 225}
 226
 227test_decode_color () {
 228        sed     -e 's/.\[1m/<WHITE>/g' \
 229                -e 's/.\[31m/<RED>/g' \
 230                -e 's/.\[32m/<GREEN>/g' \
 231                -e 's/.\[33m/<YELLOW>/g' \
 232                -e 's/.\[34m/<BLUE>/g' \
 233                -e 's/.\[35m/<MAGENTA>/g' \
 234                -e 's/.\[36m/<CYAN>/g' \
 235                -e 's/.\[m/<RESET>/g'
 236}
 237
 238q_to_nul () {
 239        perl -pe 'y/Q/\000/'
 240}
 241
 242q_to_cr () {
 243        tr Q '\015'
 244}
 245
 246append_cr () {
 247        sed -e 's/$/Q/' | tr Q '\015'
 248}
 249
 250remove_cr () {
 251        tr '\015' Q | sed -e 's/Q$//'
 252}
 253
 254test_tick () {
 255        if test -z "${test_tick+set}"
 256        then
 257                test_tick=1112911993
 258        else
 259                test_tick=$(($test_tick + 60))
 260        fi
 261        GIT_COMMITTER_DATE="$test_tick -0700"
 262        GIT_AUTHOR_DATE="$test_tick -0700"
 263        export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
 264}
 265
 266# Call test_commit with the arguments "<message> [<file> [<contents>]]"
 267#
 268# This will commit a file with the given contents and the given commit
 269# message.  It will also add a tag with <message> as name.
 270#
 271# Both <file> and <contents> default to <message>.
 272
 273test_commit () {
 274        file=${2:-"$1.t"}
 275        echo "${3-$1}" > "$file" &&
 276        git add "$file" &&
 277        test_tick &&
 278        git commit -m "$1" &&
 279        git tag "$1"
 280}
 281
 282# Call test_merge with the arguments "<message> <commit>", where <commit>
 283# can be a tag pointing to the commit-to-merge.
 284
 285test_merge () {
 286        test_tick &&
 287        git merge -m "$1" "$2" &&
 288        git tag "$1"
 289}
 290
 291# This function helps systems where core.filemode=false is set.
 292# Use it instead of plain 'chmod +x' to set or unset the executable bit
 293# of a file in the working directory and add it to the index.
 294
 295test_chmod () {
 296        chmod "$@" &&
 297        git update-index --add "--chmod=$@"
 298}
 299
 300# Use test_set_prereq to tell that a particular prerequisite is available.
 301# The prerequisite can later be checked for in two ways:
 302#
 303# - Explicitly using test_have_prereq.
 304#
 305# - Implicitly by specifying the prerequisite tag in the calls to
 306#   test_expect_{success,failure,code}.
 307#
 308# The single parameter is the prerequisite tag (a simple word, in all
 309# capital letters by convention).
 310
 311test_set_prereq () {
 312        satisfied="$satisfied$1 "
 313}
 314satisfied=" "
 315
 316test_have_prereq () {
 317        case $satisfied in
 318        *" $1 "*)
 319                : yes, have it ;;
 320        *)
 321                ! : nope ;;
 322        esac
 323}
 324
 325# You are not expected to call test_ok_ and test_failure_ directly, use
 326# the text_expect_* functions instead.
 327
 328test_ok_ () {
 329        test_success=$(($test_success + 1))
 330        say_color "" "  ok $test_count: $@"
 331}
 332
 333test_failure_ () {
 334        test_failure=$(($test_failure + 1))
 335        say_color error "FAIL $test_count: $1"
 336        shift
 337        echo "$@" | sed -e 's/^/        /'
 338        test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
 339}
 340
 341test_known_broken_ok_ () {
 342        test_fixed=$(($test_fixed+1))
 343        say_color "" "  FIXED $test_count: $@"
 344}
 345
 346test_known_broken_failure_ () {
 347        test_broken=$(($test_broken+1))
 348        say_color skip "  still broken $test_count: $@"
 349}
 350
 351test_debug () {
 352        test "$debug" = "" || eval "$1"
 353}
 354
 355test_run_ () {
 356        eval >&3 2>&4 "$1"
 357        eval_ret="$?"
 358        return 0
 359}
 360
 361test_skip () {
 362        test_count=$(($test_count+1))
 363        to_skip=
 364        for skp in $GIT_SKIP_TESTS
 365        do
 366                case $this_test.$test_count in
 367                $skp)
 368                        to_skip=t
 369                esac
 370        done
 371        if test -z "$to_skip" && test -n "$prereq" &&
 372           ! test_have_prereq "$prereq"
 373        then
 374                to_skip=t
 375        fi
 376        case "$to_skip" in
 377        t)
 378                say_color skip >&3 "skipping test: $@"
 379                say_color skip "skip $test_count: $1"
 380                : true
 381                ;;
 382        *)
 383                false
 384                ;;
 385        esac
 386}
 387
 388test_expect_failure () {
 389        test "$#" = 3 && { prereq=$1; shift; } || prereq=
 390        test "$#" = 2 ||
 391        error "bug in the test script: not 2 or 3 parameters to test-expect-failure"
 392        if ! test_skip "$@"
 393        then
 394                say >&3 "checking known breakage: $2"
 395                test_run_ "$2"
 396                if [ "$?" = 0 -a "$eval_ret" = 0 ]
 397                then
 398                        test_known_broken_ok_ "$1"
 399                else
 400                        test_known_broken_failure_ "$1"
 401                fi
 402        fi
 403        echo >&3 ""
 404}
 405
 406test_expect_success () {
 407        test "$#" = 3 && { prereq=$1; shift; } || prereq=
 408        test "$#" = 2 ||
 409        error "bug in the test script: not 2 or 3 parameters to test-expect-success"
 410        if ! test_skip "$@"
 411        then
 412                say >&3 "expecting success: $2"
 413                test_run_ "$2"
 414                if [ "$?" = 0 -a "$eval_ret" = 0 ]
 415                then
 416                        test_ok_ "$1"
 417                else
 418                        test_failure_ "$@"
 419                fi
 420        fi
 421        echo >&3 ""
 422}
 423
 424test_expect_code () {
 425        test "$#" = 4 && { prereq=$1; shift; } || prereq=
 426        test "$#" = 3 ||
 427        error "bug in the test script: not 3 or 4 parameters to test-expect-code"
 428        if ! test_skip "$@"
 429        then
 430                say >&3 "expecting exit code $1: $3"
 431                test_run_ "$3"
 432                if [ "$?" = 0 -a "$eval_ret" = "$1" ]
 433                then
 434                        test_ok_ "$2"
 435                else
 436                        test_failure_ "$@"
 437                fi
 438        fi
 439        echo >&3 ""
 440}
 441
 442# test_external runs external test scripts that provide continuous
 443# test output about their progress, and succeeds/fails on
 444# zero/non-zero exit code.  It outputs the test output on stdout even
 445# in non-verbose mode, and announces the external script with "* run
 446# <n>: ..." before running it.  When providing relative paths, keep in
 447# mind that all scripts run in "trash directory".
 448# Usage: test_external description command arguments...
 449# Example: test_external 'Perl API' perl ../path/to/test.pl
 450test_external () {
 451        test "$#" = 4 && { prereq=$1; shift; } || prereq=
 452        test "$#" = 3 ||
 453        error >&5 "bug in the test script: not 3 or 4 parameters to test_external"
 454        descr="$1"
 455        shift
 456        if ! test_skip "$descr" "$@"
 457        then
 458                # Announce the script to reduce confusion about the
 459                # test output that follows.
 460                say_color "" " run $test_count: $descr ($*)"
 461                # Run command; redirect its stderr to &4 as in
 462                # test_run_, but keep its stdout on our stdout even in
 463                # non-verbose mode.
 464                "$@" 2>&4
 465                if [ "$?" = 0 ]
 466                then
 467                        test_ok_ "$descr"
 468                else
 469                        test_failure_ "$descr" "$@"
 470                fi
 471        fi
 472}
 473
 474# Like test_external, but in addition tests that the command generated
 475# no output on stderr.
 476test_external_without_stderr () {
 477        # The temporary file has no (and must have no) security
 478        # implications.
 479        tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi
 480        stderr="$tmp/git-external-stderr.$$.tmp"
 481        test_external "$@" 4> "$stderr"
 482        [ -f "$stderr" ] || error "Internal error: $stderr disappeared."
 483        descr="no stderr: $1"
 484        shift
 485        say >&3 "expecting no stderr from previous command"
 486        if [ ! -s "$stderr" ]; then
 487                rm "$stderr"
 488                test_ok_ "$descr"
 489        else
 490                if [ "$verbose" = t ]; then
 491                        output=`echo; echo Stderr is:; cat "$stderr"`
 492                else
 493                        output=
 494                fi
 495                # rm first in case test_failure exits.
 496                rm "$stderr"
 497                test_failure_ "$descr" "$@" "$output"
 498        fi
 499}
 500
 501# This is not among top-level (test_expect_success | test_expect_failure)
 502# but is a prefix that can be used in the test script, like:
 503#
 504#       test_expect_success 'complain and die' '
 505#           do something &&
 506#           do something else &&
 507#           test_must_fail git checkout ../outerspace
 508#       '
 509#
 510# Writing this as "! git checkout ../outerspace" is wrong, because
 511# the failure could be due to a segv.  We want a controlled failure.
 512
 513test_must_fail () {
 514        "$@"
 515        test $? -gt 0 -a $? -le 129 -o $? -gt 192
 516}
 517
 518# test_cmp is a helper function to compare actual and expected output.
 519# You can use it like:
 520#
 521#       test_expect_success 'foo works' '
 522#               echo expected >expected &&
 523#               foo >actual &&
 524#               test_cmp expected actual
 525#       '
 526#
 527# This could be written as either "cmp" or "diff -u", but:
 528# - cmp's output is not nearly as easy to read as diff -u
 529# - not all diff versions understand "-u"
 530
 531test_cmp() {
 532        $GIT_TEST_CMP "$@"
 533}
 534
 535# Most tests can use the created repository, but some may need to create more.
 536# Usage: test_create_repo <directory>
 537test_create_repo () {
 538        test "$#" = 1 ||
 539        error "bug in the test script: not 1 parameter to test-create-repo"
 540        owd=`pwd`
 541        repo="$1"
 542        mkdir -p "$repo"
 543        cd "$repo" || error "Cannot setup test environment"
 544        "$GIT_EXEC_PATH/git-init" "--template=$TEST_DIRECTORY/../templates/blt/" >&3 2>&4 ||
 545        error "cannot run git init -- have you built things yet?"
 546        mv .git/hooks .git/hooks-disabled
 547        cd "$owd"
 548}
 549
 550test_done () {
 551        GIT_EXIT_OK=t
 552        test_results_dir="$TEST_DIRECTORY/test-results"
 553        mkdir -p "$test_results_dir"
 554        test_results_path="$test_results_dir/${0%.sh}-$$"
 555
 556        echo "total $test_count" >> $test_results_path
 557        echo "success $test_success" >> $test_results_path
 558        echo "fixed $test_fixed" >> $test_results_path
 559        echo "broken $test_broken" >> $test_results_path
 560        echo "failed $test_failure" >> $test_results_path
 561        echo "" >> $test_results_path
 562
 563        if test "$test_fixed" != 0
 564        then
 565                say_color pass "fixed $test_fixed known breakage(s)"
 566        fi
 567        if test "$test_broken" != 0
 568        then
 569                say_color error "still have $test_broken known breakage(s)"
 570                msg="remaining $(($test_count-$test_broken)) test(s)"
 571        else
 572                msg="$test_count test(s)"
 573        fi
 574        case "$test_failure" in
 575        0)
 576                say_color pass "passed all $msg"
 577
 578                test -d "$remove_trash" &&
 579                cd "$(dirname "$remove_trash")" &&
 580                rm -rf "$(basename "$remove_trash")"
 581
 582                exit 0 ;;
 583
 584        *)
 585                say_color error "failed $test_failure among $msg"
 586                exit 1 ;;
 587
 588        esac
 589}
 590
 591# Test the binaries we have just built.  The tests are kept in
 592# t/ subdirectory and are run in 'trash directory' subdirectory.
 593TEST_DIRECTORY=$(pwd)
 594if test -n "$valgrind"
 595then
 596        make_symlink () {
 597                test -h "$2" &&
 598                test "$1" = "$(readlink "$2")" || {
 599                        # be super paranoid
 600                        if mkdir "$2".lock
 601                        then
 602                                rm -f "$2" &&
 603                                ln -s "$1" "$2" &&
 604                                rm -r "$2".lock
 605                        else
 606                                while test -d "$2".lock
 607                                do
 608                                        say "Waiting for lock on $2."
 609                                        sleep 1
 610                                done
 611                        fi
 612                }
 613        }
 614
 615        make_valgrind_symlink () {
 616                # handle only executables
 617                test -x "$1" || return
 618
 619                base=$(basename "$1")
 620                symlink_target=$TEST_DIRECTORY/../$base
 621                # do not override scripts
 622                if test -x "$symlink_target" &&
 623                    test ! -d "$symlink_target" &&
 624                    test "#!" != "$(head -c 2 < "$symlink_target")"
 625                then
 626                        symlink_target=../valgrind.sh
 627                fi
 628                case "$base" in
 629                *.sh|*.perl)
 630                        symlink_target=../unprocessed-script
 631                esac
 632                # create the link, or replace it if it is out of date
 633                make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
 634        }
 635
 636        # override all git executables in TEST_DIRECTORY/..
 637        GIT_VALGRIND=$TEST_DIRECTORY/valgrind
 638        mkdir -p "$GIT_VALGRIND"/bin
 639        for file in $TEST_DIRECTORY/../git* $TEST_DIRECTORY/../test-*
 640        do
 641                make_valgrind_symlink $file
 642        done
 643        OLDIFS=$IFS
 644        IFS=:
 645        for path in $PATH
 646        do
 647                ls "$path"/git-* 2> /dev/null |
 648                while read file
 649                do
 650                        make_valgrind_symlink "$file"
 651                done
 652        done
 653        IFS=$OLDIFS
 654        PATH=$GIT_VALGRIND/bin:$PATH
 655        GIT_EXEC_PATH=$GIT_VALGRIND/bin
 656        export GIT_VALGRIND
 657elif test -n "$GIT_TEST_INSTALLED" ; then
 658        GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path)  ||
 659        error "Cannot run git from $GIT_TEST_INSTALLED."
 660        PATH=$GIT_TEST_INSTALLED:$TEST_DIRECTORY/..:$PATH
 661        GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
 662else # normal case, use ../bin-wrappers only unless $with_dashes:
 663        git_bin_dir="$TEST_DIRECTORY/../bin-wrappers"
 664        if ! test -x "$git_bin_dir/git" ; then
 665                if test -z "$with_dashes" ; then
 666                        say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"
 667                fi
 668                with_dashes=t
 669        fi
 670        PATH="$git_bin_dir:$PATH"
 671        GIT_EXEC_PATH=$TEST_DIRECTORY/..
 672        if test -n "$with_dashes" ; then
 673                PATH="$TEST_DIRECTORY/..:$PATH"
 674        fi
 675fi
 676GIT_TEMPLATE_DIR=$(pwd)/../templates/blt
 677unset GIT_CONFIG
 678GIT_CONFIG_NOSYSTEM=1
 679GIT_CONFIG_NOGLOBAL=1
 680export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL
 681
 682. ../GIT-BUILD-OPTIONS
 683
 684if test -z "$GIT_TEST_CMP"
 685then
 686        if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"
 687        then
 688                GIT_TEST_CMP="$DIFF -c"
 689        else
 690                GIT_TEST_CMP="$DIFF -u"
 691        fi
 692fi
 693
 694GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git
 695export GITPERLLIB
 696test -d ../templates/blt || {
 697        error "You haven't built things yet, have you?"
 698}
 699
 700if test -z "$GIT_TEST_INSTALLED" && test -z "$NO_PYTHON"
 701then
 702        GITPYTHONLIB="$(pwd)/../git_remote_helpers/build/lib"
 703        export GITPYTHONLIB
 704        test -d ../git_remote_helpers/build || {
 705                error "You haven't built git_remote_helpers yet, have you?"
 706        }
 707fi
 708
 709if ! test -x ../test-chmtime; then
 710        echo >&2 'You need to build test-chmtime:'
 711        echo >&2 'Run "make test-chmtime" in the source (toplevel) directory'
 712        exit 1
 713fi
 714
 715# Test repository
 716test="trash directory.$(basename "$0" .sh)"
 717test -n "$root" && test="$root/$test"
 718case "$test" in
 719/*) TRASH_DIRECTORY="$test" ;;
 720 *) TRASH_DIRECTORY="$TEST_DIRECTORY/$test" ;;
 721esac
 722test ! -z "$debug" || remove_trash=$TRASH_DIRECTORY
 723rm -fr "$test" || {
 724        GIT_EXIT_OK=t
 725        echo >&5 "FATAL: Cannot prepare test area"
 726        exit 1
 727}
 728
 729test_create_repo "$test"
 730# Use -P to resolve symlinks in our working directory so that the cwd
 731# in subprocesses like git equals our $PWD (for pathname comparisons).
 732cd -P "$test" || exit 1
 733
 734this_test=${0##*/}
 735this_test=${this_test%%-*}
 736for skp in $GIT_SKIP_TESTS
 737do
 738        to_skip=
 739        for skp in $GIT_SKIP_TESTS
 740        do
 741                case "$this_test" in
 742                $skp)
 743                        to_skip=t
 744                esac
 745        done
 746        case "$to_skip" in
 747        t)
 748                say_color skip >&3 "skipping test $this_test altogether"
 749                say_color skip "skip all tests in $this_test"
 750                test_done
 751        esac
 752done
 753
 754# Provide an implementation of the 'yes' utility
 755yes () {
 756        if test $# = 0
 757        then
 758                y=y
 759        else
 760                y="$*"
 761        fi
 762
 763        while echo "$y"
 764        do
 765                :
 766        done
 767}
 768
 769# Fix some commands on Windows
 770case $(uname -s) in
 771*MINGW*)
 772        # Windows has its own (incompatible) sort and find
 773        sort () {
 774                /usr/bin/sort "$@"
 775        }
 776        find () {
 777                /usr/bin/find "$@"
 778        }
 779        sum () {
 780                md5sum "$@"
 781        }
 782        # git sees Windows-style pwd
 783        pwd () {
 784                builtin pwd -W
 785        }
 786        # no POSIX permissions
 787        # backslashes in pathspec are converted to '/'
 788        # exec does not inherit the PID
 789        ;;
 790*)
 791        test_set_prereq POSIXPERM
 792        test_set_prereq BSLASHPSPEC
 793        test_set_prereq EXECKEEPSPID
 794        ;;
 795esac
 796
 797test -z "$NO_PERL" && test_set_prereq PERL
 798test -z "$NO_PYTHON" && test_set_prereq PYTHON
 799
 800# test whether the filesystem supports symbolic links
 801ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
 802rm -f y