tree-walk.c: ignore trailing slash on submodule in tree_entry_interesting()
[gitweb.git] / t / test-lib.sh
index c5e914a781e7aff82f712cecf2b2320320a0dc44..d303e6c943ab94e15e65fb8a51cbe871cf9ef544 100644 (file)
@@ -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
@@ -205,29 +209,17 @@ do
        --valgrind-only=*)
                valgrind_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
                shift ;;
-       --valgrind-parallel=*)
-               valgrind_parallel=$(expr "z$1" : 'z[^=]*=\(.*\)')
-               shift ;;
-       --valgrind-only-stride=*)
-               valgrind_only_stride=$(expr "z$1" : 'z[^=]*=\(.*\)')
-               shift ;;
-       --valgrind-only-offset=*)
-               valgrind_only_offset=$(expr "z$1" : 'z[^=]*=\(.*\)')
-               shift ;;
        --tee)
                shift ;; # was handled already
        --root=*)
                root=$(expr "z$1" : 'z[^=]*=\(.*\)')
                shift ;;
-       --statusprefix=*)
-               statusprefix=$(expr "z$1" : 'z[^=]*=\(.*\)')
-               shift ;;
        *)
                echo "error: unknown test option '$1'" >&2; exit 1 ;;
        esac
 done
 
-if test -n "$valgrind_only" || test -n "$valgrind_only_stride"
+if test -n "$valgrind_only"
 then
        test -z "$valgrind" && valgrind=memcheck
        test -z "$verbose" && verbose_only="$valgrind_only"
@@ -329,12 +321,12 @@ trap 'die' EXIT
 
 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; }
@@ -342,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 () {
@@ -377,9 +369,7 @@ maybe_teardown_verbose () {
 last_verbose=t
 maybe_setup_verbose () {
        test -z "$verbose_only" && return
-       if match_pattern_list $test_count $verbose_only ||
-               { test -n "$valgrind_only_stride" &&
-               expr $test_count "%" $valgrind_only_stride - $valgrind_only_offset = 0 >/dev/null; }
+       if match_pattern_list $test_count $verbose_only
        then
                exec 4>&2 3>&1
                # Emit a delimiting blank line when going from
@@ -403,17 +393,13 @@ maybe_teardown_valgrind () {
 
 maybe_setup_valgrind () {
        test -z "$GIT_VALGRIND" && return
-       if test -z "$valgrind_only" && test -z "$valgrind_only_stride"
+       if test -z "$valgrind_only"
        then
                GIT_VALGRIND_ENABLED=t
                return
        fi
        GIT_VALGRIND_ENABLED=
        if match_pattern_list $test_count $valgrind_only
-       then
-               GIT_VALGRIND_ENABLED=t
-       elif test -n "$valgrind_only_stride" &&
-               expr $test_count "%" $valgrind_only_stride - $valgrind_only_offset = 0 >/dev/null
        then
                GIT_VALGRIND_ENABLED=t
        fi
@@ -477,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
                ;;
        *)
@@ -516,11 +502,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
@@ -543,9 +529,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" &&
@@ -559,8 +545,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 ;;
@@ -568,9 +554,6 @@ test_done () {
        esac
 }
 
-
-# Set up a directory that we can put in PATH which redirects all git
-# calls to 'valgrind git ...'.
 if test -n "$valgrind"
 then
        make_symlink () {
@@ -618,42 +601,33 @@ then
                make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
        }
 
-       # In the case of --valgrind-parallel, we only need to do the
-       # wrapping once, in the main script.  The worker children all
-       # have $valgrind_only_stride set, so we can skip based on that.
-       if test -z "$valgrind_only_stride"
-       then
-               # override all git executables in TEST_DIRECTORY/..
-               GIT_VALGRIND=$TEST_DIRECTORY/valgrind
-               mkdir -p "$GIT_VALGRIND"/bin
-               for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/test-*
-               do
-                       make_valgrind_symlink $file
-               done
-               # special-case the mergetools loadables
-               make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools"
-               OLDIFS=$IFS
-               IFS=:
-               for path in $PATH
+       # override all git executables in TEST_DIRECTORY/..
+       GIT_VALGRIND=$TEST_DIRECTORY/valgrind
+       mkdir -p "$GIT_VALGRIND"/bin
+       for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/test-*
+       do
+               make_valgrind_symlink $file
+       done
+       # special-case the mergetools loadables
+       make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools"
+       OLDIFS=$IFS
+       IFS=:
+       for path in $PATH
+       do
+               ls "$path"/git-* 2> /dev/null |
+               while read file
                do
-                       ls "$path"/git-* 2> /dev/null |
-                       while read file
-                       do
-                               make_valgrind_symlink "$file"
-                       done
+                       make_valgrind_symlink "$file"
                done
-               IFS=$OLDIFS
-       fi
+       done
+       IFS=$OLDIFS
        PATH=$GIT_VALGRIND/bin:$PATH
        GIT_EXEC_PATH=$GIT_VALGRIND/bin
        export GIT_VALGRIND
        GIT_VALGRIND_MODE="$valgrind"
        export GIT_VALGRIND_MODE
        GIT_VALGRIND_ENABLED=t
-       if test -n "$valgrind_only" || test -n "$valgrind_only_stride"
-       then
-               GIT_VALGRIND_ENABLED=
-       fi
+       test -n "$valgrind_only" && GIT_VALGRIND_ENABLED=
        export GIT_VALGRIND_ENABLED
 elif test -n "$GIT_TEST_INSTALLED"
 then
@@ -700,15 +674,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:'
@@ -739,41 +704,6 @@ then
 else
        mkdir -p "$TRASH_DIRECTORY"
 fi
-
-# Gross hack to spawn N sub-instances of the tests in parallel, and
-# summarize the results.  Note that if this is enabled, the script
-# terminates at the end of this 'if' block.
-if test -n "$valgrind_parallel"
-then
-       for i in $(test_seq 1 $valgrind_parallel)
-       do
-               root="$TRASH_DIRECTORY/vgparallel-$i"
-               mkdir "$root"
-               TEST_OUTPUT_DIRECTORY="$root" \
-                       ${SHELL_PATH} "$0" \
-                       --root="$root" --statusprefix="[$i] " \
-                       --valgrind="$valgrind" \
-                       --valgrind-only-stride="$valgrind_parallel" \
-                       --valgrind-only-offset="$i" &
-               pids="$pids $!"
-       done
-       trap "kill $pids" INT TERM HUP
-       wait $pids
-       trap - INT TERM HUP
-       for i in $(test_seq 1 $valgrind_parallel)
-       do
-               root="$TRASH_DIRECTORY/vgparallel-$i"
-               eval "$(cat "$root/test-results/$(basename "$0" .sh)"-*.counts |
-                       sed 's/^\([a-z][a-z]*\) \([0-9][0-9]*\)/inner_\1=\2/')"
-               test_count=$(expr $test_count + $inner_total)
-               test_success=$(expr $test_success + $inner_success)
-               test_fixed=$(expr $test_fixed + $inner_fixed)
-               test_broken=$(expr $test_broken + $inner_broken)
-               test_failure=$(expr $test_failure + $inner_failed)
-       done
-       test_done
-fi
-
 # Use -P to resolve symlinks in our working directory so that the cwd
 # in subprocesses like git equals our $PWD (for pathname comparisons).
 cd -P "$TRASH_DIRECTORY" || exit 1
@@ -826,6 +756,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