# Test framework for git. See t/README for usage. # # Copyright (c) 2005 Junio C Hamano # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/ . # Test the binaries we have just built. The tests are kept in # t/ subdirectory and are run in 'trash directory' subdirectory. if test -z $TEST_DIRECTORY { # We allow tests to override this, in case they want to run tests # outside of t/, e.g. for running tests on the test library # itself. setvar 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 setvar TEST_DIRECTORY = $(cd "$TEST_DIRECTORY" && pwd) || exit 1 } if test -z $TEST_OUTPUT_DIRECTORY { # Similarly, override this to store the test-results subdir # elsewhere setvar TEST_OUTPUT_DIRECTORY = "$TEST_DIRECTORY" } setvar GIT_BUILD_DIR = ""$TEST_DIRECTORY"/.." ################################################################ # It appears that people try to run tests without building... "$GIT_BUILD_DIR/git" >/dev/null if test $? != 1 { echo >&2 'error: you do not seem to have built git yet.>&2 'error: you do not seem to have built git yet.' exit 1 } source "$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{ done,* { # do not redirect again } *' --tee '*|*' --va'*|*' --verbose-log '* { mkdir -p "$TEST_OUTPUT_DIRECTORY/test-results" setvar BASE = ""$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)"" # Make this filename available to the sub-process in case it is using # --verbose-log. setvar GIT_TEST_TEE_OUTPUT_FILE = "$BASE.out" export GIT_TEST_TEE_OUTPUT_FILE # Truncate before calling "tee -a" to get rid of the results # from any previous runs. >"$GIT_TEST_TEE_OUTPUT_FILE" shell {'GIT_TEST_TEE_STARTED=done' ${SHELL_PATH} $0 @ARGV 2>&1; echo $? >"$BASE.exit"} | tee -a $GIT_TEST_TEE_OUTPUT_FILE test $(cat "$BASE.exit") = 0 exit } } # For repeatability, reset the environment to known value. # TERM is sanitized below, after saving color control sequences. setvar LANG = 'C' setvar LC_ALL = 'C' setvar PAGER = 'cat' setvar TZ = 'UTC' export LANG LC_ALL PAGER TZ setvar EDITOR = ':' # A call to "unset" with no arguments causes at least Solaris 10 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets # deriving from the command substitution clustered with the other # ones. unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e ' my @env = keys %ENV; my $ok = join("|", qw( TRACE DEBUG USE_LOOKUP TEST .*_TEST PROVE VALGRIND UNZIP PERF_ CURL_VERBOSE TRACE_CURL )); my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env); print join("\n", @vars); ') unset XDG_CONFIG_HOME unset GITPERLLIB setvar GIT_AUTHOR_EMAIL = "author@example.com" setvar GIT_AUTHOR_NAME = ''A U Thor'' setvar GIT_COMMITTER_EMAIL = "committer@example.com" setvar GIT_COMMITTER_NAME = ''C O Mitter'' setvar GIT_MERGE_VERBOSITY = '5' setvar GIT_MERGE_AUTOEDIT = 'no' export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export EDITOR # Tests using GIT_TRACE typically don't want : output setvar GIT_TRACE_BARE = '1' export GIT_TRACE_BARE if test -n ${TEST_GIT_INDEX_VERSION:+isset} { setvar GIT_INDEX_VERSION = "$TEST_GIT_INDEX_VERSION" export GIT_INDEX_VERSION } # Add libc MALLOC and MALLOC_PERTURB test # only if we are not executing the test with valgrind if expr " $GIT_TEST_OPTS " : ".* --valgrind " >/dev/null || test -n $TEST_NO_MALLOC_CHECK { proc setup_malloc_check { : nothing } proc teardown_malloc_check { : nothing } } else { proc setup_malloc_check { setvar MALLOC_CHECK_ = '3', MALLOC_PERTURB_ = '165' export MALLOC_CHECK_ MALLOC_PERTURB_ } proc teardown_malloc_check { unset MALLOC_CHECK_ MALLOC_PERTURB_ } } : ${ASAN_OPTIONS=detect_leaks=0} export ASAN_OPTIONS # Protect ourselves from common misconfiguration to export # CDPATH into the environment unset CDPATH unset GREP_OPTIONS unset UNZIP case{ 1|2|true { setvar GIT_TRACE = '4' } } # Convenience # # A regexp to match 5 and 40 hexdigits setvar _x05 = ''[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'' setvar _x40 = ""$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"" # Zero SHA-1 setvar _z40 = '0000000000000000000000000000000000000000' setvar EMPTY_TREE = '4b825dc642cb6eb9a060e54bf8d69288fbee4904' setvar EMPTY_BLOB = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391' # Line feed setvar LF = '' '' # UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores # when case-folding filenames setvar u200c = $(printf '\342\200\214') export _x05 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB # Each test should start with something like this, after copyright notices: # # test_description='Description of this test... # This test checks if command xyzzy does the right thing... # ' # . ./test-lib.sh test "x$TERM" != "xdumb" && shell { test -t 1 && tput bold >/dev/null 2>&1 && tput setaf 1 >/dev/null 2>&1 && tput sgr0 >/dev/null 2>&1 } && setvar color = 't' while test "$#" -ne 0 { case (1) { -d|--d|--de|--deb|--debu|--debug { setvar debug = 't'; shift } -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate { setvar immediate = 't'; shift } -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests { setvar GIT_TEST_LONG = 't'; export GIT_TEST_LONG; shift } -r { shift; test "$Argc" -ne 0 || do { echo 'error: -r requires an argument' >&2; exit 1; } setvar run_list = "$1"; shift } --run=* { setvar run_list = ${1#--*=}; shift } -h|--h|--he|--hel|--help { setvar help = 't'; shift } -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose { setvar verbose = 't'; shift } --verbose-only=* { setvar verbose_only = ${1#--*=} shift } -q|--q|--qu|--qui|--quie|--quiet { # Ignore --quiet under a TAP::Harness. Saying how many tests # passed without the ok/not ok details is always an error. test -z $HARNESS_ACTIVE && setvar quiet = 't'; shift } --with-dashes { setvar with_dashes = 't'; shift } --no-color { setvar color = ''; shift } --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind { setvar valgrind = 'memcheck' shift } --valgrind=* { setvar valgrind = ${1#--*=} shift } --valgrind-only=* { setvar valgrind_only = ${1#--*=} shift } --tee { shift } # was handled already --root=* { setvar root = ${1#--*=} shift } --chain-lint { setvar GIT_TEST_CHAIN_LINT = '1' shift } --no-chain-lint { setvar GIT_TEST_CHAIN_LINT = '0' shift } -x { setvar trace = 't' setvar verbose = 't' shift } --verbose-log { setvar verbose_log = 't' shift } * { echo "error: unknown test option '$1'" >&2; exit 1 } } } if test -n $valgrind_only { test -z $valgrind && setvar valgrind = 'memcheck' test -z $verbose && setvar verbose_only = "$valgrind_only" } elif test -n $valgrind { setvar verbose = 't' } if test -n $color { # Save the color control sequences now rather than run tput # each time say_color() is called. This is done for two # reasons: # * TERM will be changed to dumb # * HOME will be changed to a temporary directory and tput # might need to read ~/.terminfo from the original HOME # directory to get the control sequences # Note: This approach assumes the control sequences don't end # in a newline for any terminal of interest (command # substitutions strip trailing newlines). Given that most # (all?) terminals in common use are related to ECMA-48, this # shouldn't be a problem. setvar say_color_error = $(tput bold; tput setaf 1) # bold red setvar say_color_skip = $(tput setaf 4) # blue setvar say_color_warn = $(tput setaf 3) # brown/yellow setvar say_color_pass = $(tput setaf 2) # green setvar say_color_info = $(tput setaf 6) # cyan setvar say_color_reset = $(tput sgr0) setvar say_color_ = """" # no formatting for normal text proc say_color { test -z $1 && test -n $quiet && return eval "say_color_color=\$say_color_$1" shift printf "%s\\n" "$say_color_color$[join(ARGV)]$say_color_reset" } } else { proc say_color { test -z $1 && test -n $quiet && return shift printf "%s\n" "$[join(ARGV)]" } } setvar TERM = 'dumb' export TERM proc error { say_color error "error: $[join(ARGV)]" setvar GIT_EXIT_OK = 't' exit 1 } proc say { say_color info "$[join(ARGV)]" } if test -n $HARNESS_ACTIVE { if test $verbose = t || test -n $verbose_only { printf 'Bail out! %s\n' \ 'verbose mode forbidden under TAP harness; try --verbose-log' exit 1 } } test ${test_description} != "" || error "Test script did not set test_description." if test $help = "t" { printf '%s\n' $test_description exit 0 } exec 5>&1 exec 6<&0 if test $verbose_log = "t" { exec 3>>"$GIT_TEST_TEE_OUTPUT_FILE" 4>&3 } elif test $verbose = "t" { exec 4>&2 3>&1 } else { exec 4>/dev/null 3>/dev/null } # Send any "-x" output directly to stderr to avoid polluting tests # which capture stderr. We can do this unconditionally since it # has no effect if tracing isn't turned on. # # Note that this sets up the trace fd as soon as we assign the variable, so it # must come after the creation of descriptor 4 above. Likewise, we must never # unset this, as it has the side effect of closing descriptor 4, which we # use to show verbose tests to the user. # # Note also that we don't need or want to export it. The tracing is local to # this shell, and we would not want to influence any shells we exec. setvar BASH_XTRACEFD = '4' setvar test_failure = '0' setvar test_count = '0' setvar test_fixed = '0' setvar test_broken = '0' setvar test_success = '0' setvar test_external_has_tap = '0' proc die { setvar code = ""$? if test -n $GIT_EXIT_OK { exit $code } else { echo >&5 "FATAL: Unexpected exit with code $code>&5 "FATAL: Unexpected exit with code $code" exit 1 } } setvar GIT_EXIT_OK = '' trap 'die' EXIT trap 'exit $?' INT # The user-facing functions are loaded from a separate file so that # test_perf subshells can have them too source "$TEST_DIRECTORY/test-lib-functions.sh" # You are not expected to call test_ok_ and test_failure_ directly, use # the test_expect_* functions instead. proc test_ok_ { setvar test_success = $(($test_success + 1)) say_color "" "ok $test_count - $[join(ARGV)]" } proc test_failure_ { setvar test_failure = $(($test_failure + 1)) say_color error "not ok $test_count - $1" shift printf '%s\n' "$[join(ARGV)]" | sed -e 's/^/# /' test $immediate = "" || do { setvar GIT_EXIT_OK = 't'; exit 1; } } proc test_known_broken_ok_ { setvar test_fixed = $(($test_fixed+1)) say_color error "ok $test_count - $[join(ARGV)] # TODO known breakage vanished" } proc test_known_broken_failure_ { setvar test_broken = $(($test_broken+1)) say_color warn "not ok $test_count - $[join(ARGV)] # TODO known breakage" } proc test_debug { test $debug = "" || eval $1 } proc match_pattern_list { setvar arg = "$1" shift test -z "$[join(ARGV)]for pattern_ in @ARGV { case (arg) { $pattern_ { return 0 } } } return 1 } proc match_test_selector_list { setvar title = "$1" shift setvar arg = "$1" shift test -z $1 && return 0 # Both commas and whitespace are accepted as separators. setvar OLDIFS = "$IFS" setvar IFS = '' ,'' set -- $1 setvar IFS = "$OLDIFS" # If the first selector is negative we include by default. setvar include = '' case (1) { !* { setvar include = 't' } }for selector in @ARGV { setvar orig_selector = "$selector" setvar positive = 't' case (selector) { !* { setvar positive = '' setvar selector = ${selector##?} } } test -z $selector && continue case (selector) { *-* { if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev/null { echo "error: $title: invalid non-numeric in range" \ "start: '$orig_selector'" >&2 exit 1 } if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev/null { echo "error: $title: invalid non-numeric in range" \ "end: '$orig_selector'" >&2 exit 1 } } * { if expr "z$selector" : "z[0-9]*[^0-9]" >/dev/null { echo "error: $title: invalid non-numeric in test" \ "selector: '$orig_selector'" >&2 exit 1 } } } # Short cut for "obvious" cases test -z $include && test -z $positive && continue test -n $include && test -n $positive && continue case (selector) { -* { if test $arg -le ${selector#-} { setvar include = "$positive" } } *- { if test $arg -ge ${selector%-} { setvar include = "$positive" } } *-* { if test ${selector%%-*} -le $arg \ && test $arg -le ${selector#*-} { setvar include = "$positive" } } * { if test $arg -eq $selector { setvar include = "$positive" } } } } test -n $include } proc maybe_teardown_verbose { test -z $verbose_only && return exec 4>/dev/null 3>/dev/null setvar verbose = '' } setvar last_verbose = 't' proc maybe_setup_verbose { test -z $verbose_only && return if match_pattern_list $test_count $verbose_only { exec 4>&2 3>&1 # Emit a delimiting blank line when going from # non-verbose to verbose. Within verbose mode the # delimiter is printed by test_expect_*. The choice # of the initial $last_verbose is such that before # test 1, we do not print it. test -z $last_verbose && echo >&3 >&3 "" setvar verbose = 't' } else { exec 4>/dev/null 3>/dev/null setvar verbose = '' } setvar last_verbose = "$verbose" } proc maybe_teardown_valgrind { test -z $GIT_VALGRIND && return setvar GIT_VALGRIND_ENABLED = '' } proc maybe_setup_valgrind { test -z $GIT_VALGRIND && return if test -z $valgrind_only { setvar GIT_VALGRIND_ENABLED = 't' return } setvar GIT_VALGRIND_ENABLED = '' if match_pattern_list $test_count $valgrind_only { setvar GIT_VALGRIND_ENABLED = 't' } } proc want_trace { test $trace = t && test $verbose = t } # This is a separate function because some tests use # "return" to end a test_expect_success block early # (and we want to make sure we run any cleanup like # "set +x"). proc test_eval_inner_ { # Do not add anything extra (including LF) after '$*' eval " want_trace && set -x $[join(ARGV)]" } proc test_eval_ { # We run this block with stderr redirected to avoid extra cruft # during a "-x" trace. Once in "set -x" mode, we cannot prevent # the shell from printing the "set +x" to turn it off (nor the saving # of $? before that). But we can make sure that the output goes to # /dev/null. # # The test itself is run with stderr put back to &4 (so either to # /dev/null, or to the original stderr if --verbose was used). do { test_eval_inner_ @ARGV &3 2>&4 setvar test_eval_ret_ = ""$? if want_trace { set +x if test $test_eval_ret_ != 0 { say_color error >&4 "error: last command exited with \$?=$test_eval_ret_>&4 "error: last command exited with \$?=$test_eval_ret_" } } } 2>/dev/null return $test_eval_ret_ } proc test_run_ { setvar test_cleanup = ':' setvar expecting_failure = "$2" if test ${GIT_TEST_CHAIN_LINT:-1} != 0 { # turn off tracing for this test-eval, as it simply creates # confusing noise in the "-x" output setvar trace_tmp = "$trace" setvar trace = '' # 117 is magic because it is unlikely to match the exit # code of other programs test_eval_ "(exit 117) && $1" if test "$?" != 117 { error "bug in the test script: broken &&-chain: $1" } setvar trace = "$trace_tmp" } setup_malloc_check test_eval_ $1 setvar eval_ret = ""$? teardown_malloc_check if test -z $immediate || test $eval_ret = 0 || test -n $expecting_failure && test $test_cleanup != ":" { setup_malloc_check test_eval_ $test_cleanup teardown_malloc_check } if test $verbose = "t" && test -n $HARNESS_ACTIVE { echo "" } return "$eval_ret" } proc test_start_ { setvar test_count = $(($test_count+1)) maybe_setup_verbose maybe_setup_valgrind } proc test_finish_ { echo >&3 >&3 "" maybe_teardown_valgrind maybe_teardown_verbose } proc test_skip { setvar to_skip = '' setvar skipped_reason = '' if match_pattern_list $this_test.$test_count $GIT_SKIP_TESTS { setvar to_skip = 't' setvar skipped_reason = ""GIT_SKIP_TESTS"" } if test -z $to_skip && test -n $test_prereq && ! test_have_prereq $test_prereq { setvar to_skip = 't' setvar of_prereq = '' if test $missing_prereq != $test_prereq { setvar of_prereq = "" of $test_prereq"" } setvar skipped_reason = ""missing $missing_prereq${of_prereq}"" } if test -z $to_skip && test -n $run_list && ! match_test_selector_list '--run' $test_count $run_list { setvar to_skip = 't' setvar skipped_reason = ""--run"" } case (to_skip) { t { say_color skip >&3 "skipping test: $[join(ARGV)]>&3 "skipping test: $@" say_color skip "ok $test_count # skip $1 ($skipped_reason)" : true } * { false } } } # stub; perf-lib overrides it proc test_at_end_hook_ { : } proc test_done { setvar GIT_EXIT_OK = 't' if test -z $HARNESS_ACTIVE { setvar test_results_dir = ""$TEST_OUTPUT_DIRECTORY/test-results"" mkdir -p $test_results_dir setvar base = ${0##*/} setvar test_results_path = ""$test_results_dir/${base%.sh}.counts"" cat >"$test_results_path" <<< """ total $test_count success $test_success fixed $test_fixed broken $test_broken failed $test_failure """ } if test $test_fixed != 0 { say_color error "# $test_fixed known breakage(s) vanished; please update test(s)" } if test $test_broken != 0 { say_color warn "# still have $test_broken known breakage(s)" } if test $test_broken != 0 || test $test_fixed != 0 { setvar test_remaining = $(( $test_count - $test_broken - $test_fixed )) setvar msg = ""remaining $test_remaining test(s)"" } else { setvar test_remaining = "$test_count" setvar msg = ""$test_count test(s)"" } case (test_failure) { 0 { # Maybe print SKIP message if test -n $skip_all && test $test_count -gt 0 { error "Can't use skip_all after running some tests" } test -z $skip_all || setvar skip_all = "" # SKIP $skip_all"" if test $test_external_has_tap -eq 0 { if test $test_remaining -gt 0 { say_color pass "# passed all $msg" } say "1..$test_count$skip_all" } test -d $remove_trash && cd $(dirname "$remove_trash") && rm -rf $(basename "$remove_trash") test_at_end_hook_ exit 0 } * { if test $test_external_has_tap -eq 0 { say_color error "# failed $test_failure among $msg" say "1..$test_count" } exit 1 } } } if test -n $valgrind { proc make_symlink { test -h $2 && test $1 = $(readlink "$2") || do { # be super paranoid if mkdir "$2".lock { rm -f $2 && ln -s $1 $2 && rm -r "$2".lock } else { while test -d "$2".lock { say "Waiting for lock on $2." sleep 1 } } } } proc make_valgrind_symlink { # handle only executables, unless they are shell libraries that # need to be in the exec-path. test -x $1 || test "# " = $(head -c 2 <"$1") || return; setvar base = $(basename "$1") setvar symlink_target = "$GIT_BUILD_DIR/$base" # do not override scripts if test -x $symlink_target && test ! -d $symlink_target && test "#!" != $(head -c 2 < "$symlink_target") { setvar symlink_target = "../valgrind.sh" } case (base) { *.sh|*.perl { setvar symlink_target = "../unprocessed-script" } } # create the link, or replace it if it is out of date make_symlink $symlink_target "$GIT_VALGRIND/bin/$base" || exit } # override all git executables in TEST_DIRECTORY/.. setvar GIT_VALGRIND = "$TEST_DIRECTORY/valgrind" mkdir -p "$GIT_VALGRIND"/bin for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/t/helper/test-* { make_valgrind_symlink $file } # special-case the mergetools loadables make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools" setvar OLDIFS = "$IFS" setvar IFS = ':' for path in $PATH { ls "$path"/git-* 2> /dev/null | while read file { make_valgrind_symlink $file } } setvar IFS = "$OLDIFS" setvar PATH = "$GIT_VALGRIND/bin:$PATH" setvar GIT_EXEC_PATH = "$GIT_VALGRIND/bin" export GIT_VALGRIND setvar GIT_VALGRIND_MODE = "$valgrind" export GIT_VALGRIND_MODE setvar GIT_VALGRIND_ENABLED = 't' test -n $valgrind_only && setvar GIT_VALGRIND_ENABLED = '' export GIT_VALGRIND_ENABLED } elif test -n $GIT_TEST_INSTALLED { setvar GIT_EXEC_PATH = $($GIT_TEST_INSTALLED/git --exec-path) || error "Cannot run git from $GIT_TEST_INSTALLED." setvar PATH = "$GIT_TEST_INSTALLED:$GIT_BUILD_DIR:$PATH" setvar GIT_EXEC_PATH = ${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH} } else { # normal case, use ../bin-wrappers only unless $with_dashes: setvar git_bin_dir = ""$GIT_BUILD_DIR/bin-wrappers"" if ! test -x "$git_bin_dir/git" { if test -z $with_dashes { say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH" } setvar with_dashes = 't' } setvar PATH = ""$git_bin_dir:$PATH"" setvar GIT_EXEC_PATH = "$GIT_BUILD_DIR" if test -n $with_dashes { setvar PATH = ""$GIT_BUILD_DIR:$PATH"" } } setvar GIT_TEMPLATE_DIR = ""$GIT_BUILD_DIR"/templates/blt" setvar GIT_CONFIG_NOSYSTEM = '1' setvar GIT_ATTR_NOSYSTEM = '1' export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM if test -z $GIT_TEST_CMP { if test -n $GIT_TEST_CMP_USE_COPIED_CONTEXT { setvar GIT_TEST_CMP = ""$DIFF -c"" } else { setvar GIT_TEST_CMP = ""$DIFF -u"" } } setvar GITPERLLIB = ""$GIT_BUILD_DIR"/perl/blib/lib:"$GIT_BUILD_DIR"/perl/blib/arch/auto/Git" export GITPERLLIB test -d "$GIT_BUILD_DIR"/templates/blt || do { error "You haven't built things yet, have you?" } if ! test -x "$GIT_BUILD_DIR"/t/helper/test-chmtime { echo >&2 'You need to build test-chmtime:>&2 'You need to build test-chmtime:' echo >&2 'Run "make t/helper/test-chmtime" in the source (toplevel) directory>&2 'Run "make t/helper/test-chmtime" in the source (toplevel) directory' exit 1 } # Test repository setvar TRASH_DIRECTORY = ""trash directory.$(basename "$0" .sh)"" test -n $root && setvar TRASH_DIRECTORY = ""$root/$TRASH_DIRECTORY"" case (TRASH_DIRECTORY) { /* { } # absolute path is good * { setvar TRASH_DIRECTORY = ""$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY"" } } test ! -z $debug || setvar remove_trash = "$TRASH_DIRECTORY" rm -fr $TRASH_DIRECTORY || do { setvar GIT_EXIT_OK = 't' echo >&5 "FATAL: Cannot prepare test area>&5 "FATAL: Cannot prepare test area" exit 1 } setvar HOME = "$TRASH_DIRECTORY" setvar GNUPGHOME = ""$HOME/gnupg-home-not-used"" export HOME GNUPGHOME if test -z $TEST_NO_CREATE_REPO { test_create_repo $TRASH_DIRECTORY } else { mkdir -p $TRASH_DIRECTORY } # 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 setvar this_test = ${0##*/} setvar this_test = ${this_test%%-*} if match_pattern_list $this_test $GIT_SKIP_TESTS { say_color info >&3 "skipping test $this_test altogether>&3 "skipping test $this_test altogether" setvar skip_all = ""skip all tests in $this_test"" test_done } # Provide an implementation of the 'yes' utility proc yes { if test $Argc = 0 { setvar y = 'y' } else { setvar y = ""$[join(ARGV)]"" } setvar i = '0' while test $i -lt 99 { echo $y setvar i = $(($i+1)) } } # Fix some commands on Windows case{ *MINGW* { # Windows has its own (incompatible) sort and find proc sort { /usr/bin/sort @ARGV } proc find { /usr/bin/find @ARGV } proc sum { md5sum @ARGV } # git sees Windows-style pwd proc pwd { builtin pwd -W } # no POSIX permissions # backslashes in pathspec are converted to '/' # exec does not inherit the PID test_set_prereq MINGW test_set_prereq NATIVE_CRLF test_set_prereq SED_STRIPS_CR test_set_prereq GREP_STRIPS_CR setvar GIT_TEST_CMP = 'mingw_test_cmp' } *CYGWIN* { test_set_prereq POSIXPERM test_set_prereq EXECKEEPSPID test_set_prereq CYGWIN test_set_prereq SED_STRIPS_CR test_set_prereq GREP_STRIPS_CR } * { test_set_prereq POSIXPERM test_set_prereq BSLASHPSPEC test_set_prereq EXECKEEPSPID } } shell { setvar COLUMNS = '1' && test $COLUMNS = 1 } && test_set_prereq COLUMNS_CAN_BE_1 test -z $NO_PERL && test_set_prereq PERL test -z $NO_PYTHON && test_set_prereq PYTHON test -n $USE_LIBPCRE && test_set_prereq LIBPCRE test -z $NO_GETTEXT && test_set_prereq GETTEXT # Can we rely on git's output in the C locale? if test -n $GETTEXT_POISON { setvar GIT_GETTEXT_POISON = 'YesPlease' export GIT_GETTEXT_POISON test_set_prereq GETTEXT_POISON } else { test_set_prereq C_LOCALE_OUTPUT } # Use this instead of test_cmp to compare files that contain expected and # actual output from git commands that can be translated. When running # under GETTEXT_POISON this pretends that the command produced expected # results. proc test_i18ncmp { test -n $GETTEXT_POISON || test_cmp @ARGV } # Use this instead of "grep expected-string actual" to see if the # output from a git command that can be translated either contains an # expected string, or does not contain an unwanted one. When running # under GETTEXT_POISON this pretends that the command produced expected # results. proc test_i18ngrep { if test -n $GETTEXT_POISON { : # pretend success } elif test "x!" = "x$1" { shift ! grep @ARGV } else { grep @ARGV } } test_lazy_prereq PIPE ' # test whether the filesystem supports FIFOs case $(uname -s) in CYGWIN*|MINGW*) false ;; *) rm -f testfifo && mkfifo testfifo ;; esac ' test_lazy_prereq SYMLINKS ' # test whether the filesystem supports symbolic links 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 && test "$(cat CamelCase)" != good ' test_lazy_prereq UTF8_NFD_TO_NFC ' # check whether FS converts nfd unicode to nfc auml=$(printf "\303\244") aumlcdiar=$(printf "\141\314\210") >"$auml" && case "$(echo *)" in "$aumlcdiar") true ;; *) false ;; esac ' test_lazy_prereq AUTOIDENT ' sane_unset GIT_AUTHOR_NAME && sane_unset GIT_AUTHOR_EMAIL && git var GIT_AUTHOR_IDENT ' test_lazy_prereq EXPENSIVE ' test -n "$GIT_TEST_LONG" ' test_lazy_prereq USR_BIN_TIME ' test -x /usr/bin/time ' test_lazy_prereq NOT_ROOT ' uid=$(id -u) && test "$uid" != 0 ' test_lazy_prereq JGIT ' type jgit ' # SANITY is about "can you correctly predict what the filesystem would # do by only looking at the permission bits of the files and # directories?" A typical example of !SANITY is running the test # suite as root, where a test may expect "chmod -r file && cat file" # to fail because file is supposed to be unreadable after a successful # chmod. In an environment (i.e. combination of what filesystem is # being used and who is running the tests) that lacks SANITY, you may # be able to delete or create a file when the containing directory # doesn't have write permissions, or access a file even if the # containing directory doesn't have read or execute permissions. test_lazy_prereq SANITY ' mkdir SANETESTD.1 SANETESTD.2 && chmod +w SANETESTD.1 SANETESTD.2 && >SANETESTD.1/x 2>SANETESTD.2/x && chmod -w SANETESTD.1 && chmod -r SANETESTD.1/x && chmod -rx SANETESTD.2 || error "bug in test sript: cannot prepare SANETESTD" ! test -r SANETESTD.1/x && ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x status=$? chmod +rwx SANETESTD.1 SANETESTD.2 && rm -rf SANETESTD.1 SANETESTD.2 || error "bug in test sript: cannot clean SANETESTD" return $status ' setvar GIT_UNZIP = ${GIT_UNZIP:-unzip} test_lazy_prereq UNZIP ' "$GIT_UNZIP" -v test $? -ne 127 ' proc run_with_limited_cmdline { shell {ulimit -s 128 && @ARGV} } test_lazy_prereq CMDLINE_LIMIT 'run_with_limited_cmdline true' proc build_option { git version --build-options | sed -ne "s/^$1: //p" } test_lazy_prereq LONG_IS_64BIT ' test 8 -le "$(build_option sizeof-long)" '