t4018: convert perl pattern tests to the new infrastructure
[gitweb.git] / t / test-lib.sh
index cff781b092b1612562565a46fe026fdfb86be9e5..1531c241c08f0fad1a8e0789dbed2675b0fe5e56 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/sh
+# Test framework for git.  See t/README for usage.
 #
 # Copyright (c) 2005 Junio C Hamano
 #
@@ -26,6 +26,10 @@ then
        # outside of t/, e.g. for running tests on the test library
        # itself.
        TEST_DIRECTORY=$(pwd)
+else
+       # ensure that TEST_DIRECTORY is an absolute path so that it
+       # is valid even if the current working directory is changed
+       TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1
 fi
 if test -z "$TEST_OUTPUT_DIRECTORY"
 then
@@ -210,9 +214,6 @@ do
        --root=*)
                root=$(expr "z$1" : 'z[^=]*=\(.*\)')
                shift ;;
-       --statusprefix=*)
-               statusprefix=$(expr "z$1" : 'z[^=]*=\(.*\)')
-               shift ;;
        *)
                echo "error: unknown test option '$1'" >&2; exit 1 ;;
        esac
@@ -316,16 +317,16 @@ trap 'die' EXIT
 . "$TEST_DIRECTORY/test-lib-functions.sh"
 
 # You are not expected to call test_ok_ and test_failure_ directly, use
-# the text_expect_* functions instead.
+# the test_expect_* functions instead.
 
 test_ok_ () {
        test_success=$(($test_success + 1))
-       say_color "" "${statusprefix}ok $test_count - $@"
+       say_color "" "ok $test_count - $@"
 }
 
 test_failure_ () {
        test_failure=$(($test_failure + 1))
-       say_color error "${statusprefix}not ok $test_count - $1"
+       say_color error "not ok $test_count - $1"
        shift
        echo "$@" | sed -e 's/^/#       /'
        test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
@@ -333,12 +334,12 @@ test_failure_ () {
 
 test_known_broken_ok_ () {
        test_fixed=$(($test_fixed+1))
-       say_color error "${statusprefix}ok $test_count - $@ # TODO known breakage vanished"
+       say_color error "ok $test_count - $@ # TODO known breakage vanished"
 }
 
 test_known_broken_failure_ () {
        test_broken=$(($test_broken+1))
-       say_color warn "${statusprefix}not ok $test_count - $@ # TODO known breakage"
+       say_color warn "not ok $test_count - $@ # TODO known breakage"
 }
 
 test_debug () {
@@ -462,8 +463,8 @@ test_skip () {
                        of_prereq=" of $test_prereq"
                fi
 
-               say_color skip >&3 "${statusprefix}skipping test: $@"
-               say_color skip "${statusprefix}ok $test_count # skip $1 (missing $missing_prereq${of_prereq})"
+               say_color skip >&3 "skipping test: $@"
+               say_color skip "ok $test_count # skip $1 (missing $missing_prereq${of_prereq})"
                : true
                ;;
        *)
@@ -480,8 +481,6 @@ test_at_end_hook_ () {
 test_done () {
        GIT_EXIT_OK=t
 
-       # Note: t0000 relies on $HARNESS_ACTIVE disabling the .counts
-       # output file
        if test -z "$HARNESS_ACTIVE"
        then
                test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results"
@@ -501,11 +500,11 @@ test_done () {
 
        if test "$test_fixed" != 0
        then
-               say_color error "${statusprefix}# $test_fixed known breakage(s) vanished; please update test(s)"
+               say_color error "# $test_fixed known breakage(s) vanished; please update test(s)"
        fi
        if test "$test_broken" != 0
        then
-               say_color warn "${statusprefix}# still have $test_broken known breakage(s)"
+               say_color warn "# still have $test_broken known breakage(s)"
        fi
        if test "$test_broken" != 0 || test "$test_fixed" != 0
        then
@@ -528,9 +527,9 @@ test_done () {
                then
                        if test $test_remaining -gt 0
                        then
-                               say_color pass "${statusprefix}# passed all $msg"
+                               say_color pass "# passed all $msg"
                        fi
-                       say "${statusprefix}1..$test_count$skip_all"
+                       say "1..$test_count$skip_all"
                fi
 
                test -d "$remove_trash" &&
@@ -544,8 +543,8 @@ test_done () {
        *)
                if test $test_external_has_tap -eq 0
                then
-                       say_color error "${statusprefix}# failed $test_failure among $msg"
-                       say "${statusprefix}1..$test_count"
+                       say_color error "# failed $test_failure among $msg"
+                       say "1..$test_count"
                fi
 
                exit 1 ;;
@@ -576,11 +575,9 @@ then
 
        make_valgrind_symlink () {
                # handle only executables, unless they are shell libraries that
-               # need to be in the exec-path.  We will just use "#!" as a
-               # guess for a shell-script, since we have no idea what the user
-               # may have configured as the shell path.
+               # need to be in the exec-path.
                test -x "$1" ||
-               test "#!" = "$(head -c 2 <"$1")" ||
+               test "# " = "$(head -c 2 <"$1")" ||
                return;
 
                base=$(basename "$1")
@@ -673,15 +670,6 @@ test -d "$GIT_BUILD_DIR"/templates/blt || {
        error "You haven't built things yet, have you?"
 }
 
-if test -z "$GIT_TEST_INSTALLED" && test -z "$NO_PYTHON"
-then
-       GITPYTHONLIB="$GIT_BUILD_DIR/git_remote_helpers/build/lib"
-       export GITPYTHONLIB
-       test -d "$GIT_BUILD_DIR"/git_remote_helpers/build || {
-               error "You haven't built git_remote_helpers yet, have you?"
-       }
-fi
-
 if ! test -x "$GIT_BUILD_DIR"/test-chmtime
 then
        echo >&2 'You need to build test-chmtime:'
@@ -764,6 +752,7 @@ case $(uname -s) in
        test_set_prereq NOT_CYGWIN
        test_set_prereq SED_STRIPS_CR
        test_set_prereq GREP_STRIPS_CR
+       GIT_TEST_CMP=mingw_test_cmp
        ;;
 *CYGWIN*)
        test_set_prereq POSIXPERM
@@ -841,6 +830,10 @@ test_lazy_prereq SYMLINKS '
        ln -s x y && test -h y
 '
 
+test_lazy_prereq FILEMODE '
+       test "$(git config --bool core.filemode)" = true
+'
+
 test_lazy_prereq CASE_INSENSITIVE_FS '
        echo good >CamelCase &&
        echo bad >camelcase &&