Code

Merge branch 'maint'
[git.git] / t / test-lib.sh
index 572301df1bb234f28bcc3d9b3f4484018a72506d..5fdc5d94a20cfcf231bf23590784c5146a3e44bc 100644 (file)
@@ -115,7 +115,7 @@ do
        --tee)
                shift ;; # was handled already
        *)
-               break ;;
+               echo "error: unknown test option '$1'" >&2; exit 1 ;;
        esac
 done
 
@@ -147,7 +147,7 @@ fi
 
 error () {
        say_color error "error: $*"
-       trap - EXIT
+       GIT_EXIT_OK=t
        exit 1
 }
 
@@ -179,10 +179,17 @@ test_broken=0
 test_success=0
 
 die () {
-       echo >&5 "FATAL: Unexpected exit with code $?"
-       exit 1
+       code=$?
+       if test -n "$GIT_EXIT_OK"
+       then
+               exit $code
+       else
+               echo >&5 "FATAL: Unexpected exit with code $code"
+               exit 1
+       fi
 }
 
+GIT_EXIT_OK=
 trap 'die' EXIT
 
 # The semantics of the editor variables are that of invoking
@@ -285,7 +292,7 @@ test_failure_ () {
        say_color error "FAIL $test_count: $1"
        shift
        echo "$@" | sed -e 's/^/        /'
-       test "$immediate" = "" || { trap - EXIT; exit 1; }
+       test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
 }
 
 test_known_broken_ok_ () {
@@ -347,7 +354,7 @@ test_expect_failure () {
                then
                        test_known_broken_ok_ "$1"
                else
-                   test_known_broken_failure_ "$1"
+                       test_known_broken_failure_ "$1"
                fi
        fi
        echo >&3 ""
@@ -491,14 +498,14 @@ test_create_repo () {
        repo="$1"
        mkdir -p "$repo"
        cd "$repo" || error "Cannot setup test environment"
-       "$GIT_EXEC_PATH/git" init "--template=$owd/../templates/blt/" >&3 2>&4 ||
+       "$GIT_EXEC_PATH/git-init" "--template=$TEST_DIRECTORY/../templates/blt/" >&3 2>&4 ||
        error "cannot run git init -- have you built things yet?"
        mv .git/hooks .git/hooks-disabled
        cd "$owd"
 }
 
 test_done () {
-       trap - EXIT
+       GIT_EXIT_OK=t
        test_results_dir="$TEST_DIRECTORY/test-results"
        mkdir -p "$test_results_dir"
        test_results_path="$test_results_dir/${0%.sh}-$$"
@@ -523,14 +530,6 @@ test_done () {
        fi
        case "$test_failure" in
        0)
-               # We could:
-               # cd .. && rm -fr 'trash directory'
-               # but that means we forbid any tests that use their own
-               # subdirectory from calling test_done without coming back
-               # to where they started from.
-               # The Makefile provided will clean this test area so
-               # we will leave things as they are.
-
                say_color pass "passed all $msg"
 
                test -d "$remove_trash" &&
@@ -551,8 +550,16 @@ test_done () {
 TEST_DIRECTORY=$(pwd)
 if test -z "$valgrind"
 then
-       PATH=$TEST_DIRECTORY/..:$PATH
-       GIT_EXEC_PATH=$TEST_DIRECTORY/..
+       if test -z "$GIT_TEST_INSTALLED"
+       then
+               PATH=$TEST_DIRECTORY/..:$PATH
+               GIT_EXEC_PATH=$TEST_DIRECTORY/..
+       else
+               GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path)  ||
+               error "Cannot run git from $GIT_TEST_INSTALLED."
+               PATH=$GIT_TEST_INSTALLED:$TEST_DIRECTORY/..:$PATH
+               GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
+       fi
 else
        make_symlink () {
                test -h "$2" &&
@@ -640,7 +647,7 @@ fi
 test="trash directory.$(basename "$0" .sh)"
 test ! -z "$debug" || remove_trash="$TEST_DIRECTORY/$test"
 rm -fr "$test" || {
-       trap - EXIT
+       GIT_EXIT_OK=t
        echo >&5 "FATAL: Cannot prepare test area"
        exit 1
 }
@@ -698,6 +705,8 @@ case $(uname -s) in
        ;;
 esac
 
+test -z "$NO_PERL" && test_set_prereq PERL
+
 # test whether the filesystem supports symbolic links
 ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
 rm -f y