Merge branch 'master' of github.com:linusboyle/git
[gitweb.git] / t / test-lib.sh
index 219ca1d520e3b343685b47bd7940be6778ae152d..0f1faa24b27b90f4d246d33da9950325f8736633 100644 (file)
@@ -49,18 +49,28 @@ export ASAN_OPTIONS
 : ${LSAN_OPTIONS=abort_on_error=1}
 export LSAN_OPTIONS
 
+if test ! -f "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
+then
+       echo >&2 'error: GIT-BUILD-OPTIONS missing (has Git been built?).'
+       exit 1
+fi
+. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
+export PERL_PATH SHELL_PATH
+
 ################################################################
 # It appears that people try to run tests without building...
-"$GIT_BUILD_DIR/git" >/dev/null
+"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
 if test $? != 1
 then
-       echo >&2 'error: you do not seem to have built git yet.'
+       if test -n "$GIT_TEST_INSTALLED"
+       then
+               echo >&2 "error: there is no working Git at '$GIT_TEST_INSTALLED'"
+       else
+               echo >&2 'error: you do not seem to have built git yet.'
+       fi
        exit 1
 fi
 
-. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
-export PERL_PATH SHELL_PATH
-
 # if --tee was passed, write the output not only to the terminal, but
 # additionally to the file test-results/$BASENAME.out, too.
 case "$GIT_TEST_TEE_STARTED, $* " in
@@ -392,6 +402,10 @@ error () {
        exit 1
 }
 
+BUG () {
+       error >&7 "bug in the test script: $*"
+}
+
 say () {
        say_color info "$*"
 }
@@ -719,7 +733,7 @@ test_run_ () {
                if $(printf '%s\n' "$1" | sed -f "$GIT_BUILD_DIR/t/chainlint.sed" | grep -q '?![A-Z][A-Z]*?!') ||
                        test "OK-117" != "$(test_eval_ "(exit 117) && $1${LF}${LF}echo OK-\$?" 3>&1)"
                then
-                       error "bug in the test script: broken &&-chain or run-away HERE-DOC: $1"
+                       BUG "broken &&-chain or run-away HERE-DOC: $1"
                fi
                trace=$trace_tmp
        fi
@@ -967,7 +981,7 @@ elif test -n "$GIT_TEST_INSTALLED"
 then
        GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path)  ||
        error "Cannot run git from $GIT_TEST_INSTALLED."
-       PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR:$PATH
+       PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR/t/helper:$PATH
        GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
 else # normal case, use ../bin-wrappers only unless $with_dashes:
        git_bin_dir="$GIT_BUILD_DIR/bin-wrappers"
@@ -1221,7 +1235,7 @@ test_lazy_prereq SANITY '
        chmod -w SANETESTD.1 &&
        chmod -r SANETESTD.1/x &&
        chmod -rx SANETESTD.2 ||
-       error "bug in test sript: cannot prepare SANETESTD"
+       BUG "cannot prepare SANETESTD"
 
        ! test -r SANETESTD.1/x &&
        ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
@@ -1229,7 +1243,7 @@ test_lazy_prereq SANITY '
 
        chmod +rwx SANETESTD.1 SANETESTD.2 &&
        rm -rf SANETESTD.1 SANETESTD.2 ||
-       error "bug in test sript: cannot clean SANETESTD"
+       BUG "cannot clean SANETESTD"
        return $status
 '