blob: 1da3f40a31ef4e17cca90b86813c2414d7e94304 [file] [log] [blame]
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
Michal Sojka64b90322010-04-16 15:53:59 +02005# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see http://www.gnu.org/licenses/ .
Junio C Hamanoe1970ce2005-05-13 22:50:32 -070017
Johannes Schindelin44138552009-02-04 00:26:12 +010018# if --tee was passed, write the output not only to the terminal, but
19# additionally to the file test-results/$BASENAME.out, too.
20case "$GIT_TEST_TEE_STARTED, $* " in
21done,*)
22 # do not redirect again
23 ;;
Johannes Schindelin3da93652009-02-04 00:26:26 +010024*' --tee '*|*' --va'*)
Johannes Schindelin44138552009-02-04 00:26:12 +010025 mkdir -p test-results
26 BASE=test-results/$(basename "$0" .sh)
27 (GIT_TEST_TEE_STARTED=done ${SHELL-sh} "$0" "$@" 2>&1;
28 echo $? > $BASE.exit) | tee $BASE.out
29 test "$(cat $BASE.exit)" = 0
30 exit
31 ;;
32esac
33
Junio C Hamanoc2116a12008-03-06 19:04:26 -080034# Keep the original TERM for say_color
35ORIGINAL_TERM=$TERM
36
Junio C Hamanoe1970ce2005-05-13 22:50:32 -070037# For repeatability, reset the environment to known value.
38LANG=C
Junio C Hamano899460f2005-10-09 21:58:02 -070039LC_ALL=C
Pavel Roskind9bdd392005-08-10 22:10:01 -040040PAGER=cat
Junio C Hamanoe1970ce2005-05-13 22:50:32 -070041TZ=UTC
Junio C Hamanoc2116a12008-03-06 19:04:26 -080042TERM=dumb
43export LANG LC_ALL PAGER TERM TZ
Eric Wong8ff99e72006-07-11 12:01:54 -070044EDITOR=:
Jonathan Niederd33738d2009-11-11 17:56:07 -060045unset VISUAL
Josh Triplett28a94f82007-04-28 18:40:28 -070046unset EMAIL
Ævar Arnfjörð Bjarmason5e9637c2011-11-18 00:14:42 +010047unset LANGUAGE
Jonathan Nieder95a1d122011-03-15 05:10:45 -050048unset $(perl -e '
49 my @env = keys %ENV;
Jens Lehmann730477f2011-03-28 21:16:09 +020050 my $ok = join("|", qw(
51 TRACE
52 DEBUG
53 USE_LOOKUP
54 TEST
55 .*_TEST
56 PROVE
57 VALGRIND
58 ));
59 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
Jonathan Nieder95a1d122011-03-15 05:10:45 -050060 print join("\n", @vars);
61')
Junio C Hamano29e55cd2006-02-10 19:11:23 -080062GIT_AUTHOR_EMAIL=author@example.com
63GIT_AUTHOR_NAME='A U Thor'
Junio C Hamano29e55cd2006-02-10 19:11:23 -080064GIT_COMMITTER_EMAIL=committer@example.com
65GIT_COMMITTER_NAME='C O Mitter'
Shawn O. Pearce8d0fc482007-02-04 00:45:47 -050066GIT_MERGE_VERBOSITY=5
Junio C Hamanof8246282012-01-10 22:44:45 -080067GIT_MERGE_AUTOEDIT=no
68export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
Junio C Hamano29e55cd2006-02-10 19:11:23 -080069export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
70export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
Jonathan Niederd33738d2009-11-11 17:56:07 -060071export EDITOR
Junio C Hamanoe1970ce2005-05-13 22:50:32 -070072
Junio C Hamano886a3902007-04-24 11:21:47 -070073# Protect ourselves from common misconfiguration to export
74# CDPATH into the environment
75unset CDPATH
76
Bert Wesarg5565f472009-11-18 17:15:19 +010077unset GREP_OPTIONS
78
Robin Rosenberg3d5c0cc2006-09-23 00:35:20 +020079case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in
Christian Couder6ce4e612006-09-02 18:23:48 +020080 1|2|true)
81 echo "* warning: Some tests will not work if GIT_TRACE" \
82 "is set as to trace on STDERR ! *"
83 echo "* warning: Please set GIT_TRACE to something" \
84 "other than 1, 2 or true ! *"
85 ;;
86esac
87
Junio C Hamanocd3c0952009-09-20 11:10:14 -070088# Convenience
89#
90# A regexp to match 5 and 40 hexdigits
91_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
92_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
93
Junio C Hamano3749fde2011-04-23 22:34:13 -070094# Zero SHA-1
95_z40=0000000000000000000000000000000000000000
96
Junio C Hamano3f4ab622011-08-08 11:51:00 -070097# Line feed
98LF='
99'
100
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700101# Each test should start with something like this, after copyright notices:
102#
103# test_description='Description of this test...
104# This test checks if command xyzzy does the right thing...
105# '
106# . ./test-lib.sh
Junio C Hamanoc2116a12008-03-06 19:04:26 -0800107[ "x$ORIGINAL_TERM" != "xdumb" ] && (
108 TERM=$ORIGINAL_TERM &&
109 export TERM &&
110 [ -t 1 ] &&
111 tput bold >/dev/null 2>&1 &&
112 tput setaf 1 >/dev/null 2>&1 &&
113 tput sgr0 >/dev/null 2>&1
114 ) &&
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200115 color=t
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700116
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700117while test "$#" -ne 0
118do
119 case "$1" in
120 -d|--d|--de|--deb|--debu|--debug)
121 debug=t; shift ;;
Junio C Hamano886856a2005-05-14 00:24:27 -0700122 -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
123 immediate=t; shift ;;
Lea Wiemann5e2c08c2008-06-17 03:29:02 +0200124 -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
Junio C Hamano91e80b92009-02-18 11:17:27 -0800125 GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;;
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700126 -h|--h|--he|--hel|--help)
Michele Ballabio570f3222007-11-10 15:17:25 +0100127 help=t; shift ;;
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700128 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
129 verbose=t; shift ;;
Pierre Habouzit1ece1272007-10-24 22:03:39 +0200130 -q|--q|--qu|--qui|--quie|--quiet)
Ævar Arnfjörð Bjarmason092c4332010-07-31 16:40:05 +0000131 # Ignore --quiet under a TAP::Harness. Saying how many tests
132 # passed without the ok/not ok details is always an error.
133 test -z "$HARNESS_ACTIVE" && quiet=t; shift ;;
Matthew Ogilviee4597aa2009-12-02 22:14:06 -0700134 --with-dashes)
135 with_dashes=t; shift ;;
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200136 --no-color)
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +0100137 color=; shift ;;
Johannes Schindelin4e1be632009-02-04 00:25:59 +0100138 --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
Johannes Schindelin3da93652009-02-04 00:26:26 +0100139 valgrind=t; verbose=t; shift ;;
Johannes Schindelin44138552009-02-04 00:26:12 +0100140 --tee)
141 shift ;; # was handled already
Jeff Kingf423ef52009-08-09 04:39:45 -0400142 --root=*)
143 root=$(expr "z$1" : 'z[^=]*=\(.*\)')
144 shift ;;
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700145 *)
Clemens Buchacher1f729dc2009-06-01 14:14:40 +0200146 echo "error: unknown test option '$1'" >&2; exit 1 ;;
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700147 esac
148done
149
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200150if test -n "$color"; then
151 say_color () {
Junio C Hamanoc2116a12008-03-06 19:04:26 -0800152 (
153 TERM=$ORIGINAL_TERM
154 export TERM
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200155 case "$1" in
156 error) tput bold; tput setaf 1;; # bold red
157 skip) tput bold; tput setaf 2;; # bold green
158 pass) tput setaf 2;; # green
159 info) tput setaf 3;; # brown
Pierre Habouzit1ece1272007-10-24 22:03:39 +0200160 *) test -n "$quiet" && return;;
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200161 esac
162 shift
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +0000163 printf "%s" "$*"
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200164 tput sgr0
Miklos Vajnab8eecaf2008-10-10 00:07:10 +0200165 echo
Junio C Hamanoc2116a12008-03-06 19:04:26 -0800166 )
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200167 }
168else
169 say_color() {
Pierre Habouzit1ece1272007-10-24 22:03:39 +0200170 test -z "$1" && test -n "$quiet" && return
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200171 shift
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +0000172 echo "$*"
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200173 }
174fi
175
176error () {
177 say_color error "error: $*"
Clemens Buchacher6e7b5aa2009-06-01 14:14:41 +0200178 GIT_EXIT_OK=t
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200179 exit 1
180}
181
182say () {
183 say_color info "$*"
184}
185
Michele Ballabio570f3222007-11-10 15:17:25 +0100186test "${test_description}" != "" ||
187error "Test script did not set test_description."
188
189if test "$help" = "t"
190then
191 echo "$test_description"
192 exit 0
193fi
194
Pavel Roskin4d9d62f2005-08-10 23:56:21 -0400195exec 5>&1
Jeff King781f76b2011-12-15 01:55:29 -0500196exec 6<&0
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700197if test "$verbose" = "t"
198then
199 exec 4>&2 3>&1
200else
201 exec 4>/dev/null 3>/dev/null
202fi
203
204test_failure=0
205test_count=0
Junio C Hamano41ac4142008-02-01 01:50:53 -0800206test_fixed=0
207test_broken=0
Sverre Rabbelier2d84e9f2008-06-08 16:04:33 +0200208test_success=0
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700209
Ævar Arnfjörð Bjarmasond998bd42010-06-24 17:44:46 +0000210test_external_has_tap=0
211
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +0100212die () {
Clemens Buchacher6e7b5aa2009-06-01 14:14:41 +0200213 code=$?
214 if test -n "$GIT_EXIT_OK"
215 then
216 exit $code
217 else
218 echo >&5 "FATAL: Unexpected exit with code $code"
219 exit 1
220 fi
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +0100221}
222
Clemens Buchacher6e7b5aa2009-06-01 14:14:41 +0200223GIT_EXIT_OK=
Markus Heidelberg35641312009-01-20 00:43:26 +0100224trap 'die' EXIT
Pavel Roskin41184272005-08-11 12:00:40 -0400225
Thomas Rast12a29b12012-02-17 11:25:08 +0100226# The user-facing functions are loaded from a separate file so that
227# test_perf subshells can have them too
228. "${TEST_DIRECTORY:-.}"/test-lib-functions.sh
Jonathan Nieder05236a52010-10-17 02:36:58 +0800229
Junio C Hamano886856a2005-05-14 00:24:27 -0700230# You are not expected to call test_ok_ and test_failure_ directly, use
231# the text_expect_* functions instead.
232
233test_ok_ () {
Johannes Sixtd5d9de12009-02-05 20:59:27 +0100234 test_success=$(($test_success + 1))
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +0000235 say_color "" "ok $test_count - $@"
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700236}
237
Junio C Hamano886856a2005-05-14 00:24:27 -0700238test_failure_ () {
Johannes Sixtd5d9de12009-02-05 20:59:27 +0100239 test_failure=$(($test_failure + 1))
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +0000240 say_color error "not ok - $test_count $1"
Junio C Hamanobf0dd8a2005-07-22 19:09:34 -0700241 shift
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +0000242 echo "$@" | sed -e 's/^/# /'
Clemens Buchacher6e7b5aa2009-06-01 14:14:41 +0200243 test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
Junio C Hamano886856a2005-05-14 00:24:27 -0700244}
245
Junio C Hamano41ac4142008-02-01 01:50:53 -0800246test_known_broken_ok_ () {
Junio C Hamano41ac4142008-02-01 01:50:53 -0800247 test_fixed=$(($test_fixed+1))
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +0000248 say_color "" "ok $test_count - $@ # TODO known breakage"
Junio C Hamano41ac4142008-02-01 01:50:53 -0800249}
250
251test_known_broken_failure_ () {
Junio C Hamano41ac4142008-02-01 01:50:53 -0800252 test_broken=$(($test_broken+1))
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +0000253 say_color skip "not ok $test_count - $@ # TODO known breakage"
Junio C Hamano41ac4142008-02-01 01:50:53 -0800254}
Junio C Hamano886856a2005-05-14 00:24:27 -0700255
256test_debug () {
Junio C Hamano8e832eb2005-08-10 22:53:27 -0700257 test "$debug" = "" || eval "$1"
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700258}
259
Jonathan Niedera7c58f22011-08-08 03:17:09 +0200260test_eval_ () {
261 # This is a separate function because some tests use
262 # "return" to end a test_expect_success block early.
Jeff King781f76b2011-12-15 01:55:29 -0500263 eval </dev/null >&3 2>&4 "$*"
Jonathan Niedera7c58f22011-08-08 03:17:09 +0200264}
265
Pavel Roskin4d9d62f2005-08-10 23:56:21 -0400266test_run_ () {
Jonathan Niederb6b0afd2010-05-06 03:41:10 -0500267 test_cleanup=:
Junio C Hamanob5867442011-06-27 11:02:22 -0700268 expecting_failure=$2
Jonathan Niedera7c58f22011-08-08 03:17:09 +0200269 test_eval_ "$1"
Jonathan Niederb6b0afd2010-05-06 03:41:10 -0500270 eval_ret=$?
Junio C Hamanob5867442011-06-27 11:02:22 -0700271
272 if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure"
273 then
Jonathan Niedera7c58f22011-08-08 03:17:09 +0200274 test_eval_ "$test_cleanup"
Junio C Hamanob5867442011-06-27 11:02:22 -0700275 fi
Ævar Arnfjörð Bjarmason57e15382010-06-24 17:44:47 +0000276 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"; then
277 echo ""
278 fi
Jonathan Niederaa0bcf92011-08-08 03:15:34 +0200279 return "$eval_ret"
Pavel Roskin4d9d62f2005-08-10 23:56:21 -0400280}
281
Junio C Hamano04ece592006-12-28 17:58:00 -0800282test_skip () {
Johannes Sixt8586f982009-02-05 21:20:56 +0100283 test_count=$(($test_count+1))
Junio C Hamano04ece592006-12-28 17:58:00 -0800284 to_skip=
285 for skp in $GIT_SKIP_TESTS
286 do
Johannes Sixt8586f982009-02-05 21:20:56 +0100287 case $this_test.$test_count in
Junio C Hamano04ece592006-12-28 17:58:00 -0800288 $skp)
289 to_skip=t
Michael J Gruber47e67d42010-07-12 12:32:18 +0200290 break
Junio C Hamano04ece592006-12-28 17:58:00 -0800291 esac
292 done
Jonathan Nieder05236a52010-10-17 02:36:58 +0800293 if test -z "$to_skip" && test -n "$test_prereq" &&
294 ! test_have_prereq "$test_prereq"
Johannes Sixta7bb3942009-03-01 21:04:46 +0100295 then
296 to_skip=t
297 fi
Junio C Hamano04ece592006-12-28 17:58:00 -0800298 case "$to_skip" in
299 t)
Jonathan Nieder07431fc2010-08-24 02:34:10 -0500300 of_prereq=
Jonathan Nieder05236a52010-10-17 02:36:58 +0800301 if test "$missing_prereq" != "$test_prereq"
Jonathan Nieder07431fc2010-08-24 02:34:10 -0500302 then
Jonathan Nieder05236a52010-10-17 02:36:58 +0800303 of_prereq=" of $test_prereq"
Jonathan Nieder07431fc2010-08-24 02:34:10 -0500304 fi
305
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200306 say_color skip >&3 "skipping test: $@"
Jonathan Nieder07431fc2010-08-24 02:34:10 -0500307 say_color skip "ok $test_count # skip $1 (missing $missing_prereq${of_prereq})"
Junio C Hamano04ece592006-12-28 17:58:00 -0800308 : true
309 ;;
310 *)
311 false
312 ;;
313 esac
314}
315
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700316test_done () {
Clemens Buchacher6e7b5aa2009-06-01 14:14:41 +0200317 GIT_EXIT_OK=t
Sverre Rabbelier2d84e9f2008-06-08 16:04:33 +0200318
Ævar Arnfjörð Bjarmason8ef1abe2010-08-11 19:37:31 +0000319 if test -z "$HARNESS_ACTIVE"; then
320 test_results_dir="$TEST_DIRECTORY/test-results"
321 mkdir -p "$test_results_dir"
322 test_results_path="$test_results_dir/${0%.sh}-$$.counts"
323
Mathias Lafeldtc54e6be2011-04-29 14:30:30 +0200324 cat >>"$test_results_path" <<-EOF
325 total $test_count
326 success $test_success
327 fixed $test_fixed
328 broken $test_broken
329 failed $test_failure
330
331 EOF
Ævar Arnfjörð Bjarmason8ef1abe2010-08-11 19:37:31 +0000332 fi
Junio C Hamano41ac4142008-02-01 01:50:53 -0800333
334 if test "$test_fixed" != 0
335 then
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +0000336 say_color pass "# fixed $test_fixed known breakage(s)"
Junio C Hamano41ac4142008-02-01 01:50:53 -0800337 fi
338 if test "$test_broken" != 0
339 then
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +0000340 say_color error "# still have $test_broken known breakage(s)"
Junio C Hamano11d54b82008-02-03 00:23:02 -0800341 msg="remaining $(($test_count-$test_broken)) test(s)"
342 else
343 msg="$test_count test(s)"
Junio C Hamano41ac4142008-02-01 01:50:53 -0800344 fi
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700345 case "$test_failure" in
Junio C Hamano10b94e22005-12-09 17:32:18 -0800346 0)
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +0000347 # Maybe print SKIP message
348 [ -z "$skip_all" ] || skip_all=" # SKIP $skip_all"
349
Ævar Arnfjörð Bjarmasond998bd42010-06-24 17:44:46 +0000350 if test $test_external_has_tap -eq 0; then
351 say_color pass "# passed all $msg"
352 say "1..$test_count$skip_all"
353 fi
Johannes Schindelinabc5d372008-08-08 13:08:37 +0200354
355 test -d "$remove_trash" &&
356 cd "$(dirname "$remove_trash")" &&
357 rm -rf "$(basename "$remove_trash")"
358
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700359 exit 0 ;;
360
361 *)
Ævar Arnfjörð Bjarmasond998bd42010-06-24 17:44:46 +0000362 if test $test_external_has_tap -eq 0; then
363 say_color error "# failed $test_failure among $msg"
364 say "1..$test_count"
365 fi
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +0000366
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700367 exit 1 ;;
368
369 esac
370}
371
372# Test the binaries we have just built. The tests are kept in
Jakub Narebski9adefee2008-06-14 20:14:12 +0200373# t/ subdirectory and are run in 'trash directory' subdirectory.
Ævar Arnfjörð Bjarmason62f53902010-08-19 16:08:11 +0000374if test -z "$TEST_DIRECTORY"
375then
376 # We allow tests to override this, in case they want to run tests
377 # outside of t/, e.g. for running tests on the test library
378 # itself.
379 TEST_DIRECTORY=$(pwd)
380fi
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000381GIT_BUILD_DIR="$TEST_DIRECTORY"/..
382
Matthew Ogilviee4597aa2009-12-02 22:14:06 -0700383if test -n "$valgrind"
Johannes Schindelin4e1be632009-02-04 00:25:59 +0100384then
Johannes Schindelin4e1be632009-02-04 00:25:59 +0100385 make_symlink () {
386 test -h "$2" &&
387 test "$1" = "$(readlink "$2")" || {
388 # be super paranoid
389 if mkdir "$2".lock
390 then
391 rm -f "$2" &&
392 ln -s "$1" "$2" &&
393 rm -r "$2".lock
394 else
395 while test -d "$2".lock
396 do
397 say "Waiting for lock on $2."
398 sleep 1
399 done
400 fi
401 }
402 }
403
404 make_valgrind_symlink () {
Jeff King36bfb0e2011-06-17 16:36:32 -0400405 # handle only executables, unless they are shell libraries that
406 # need to be in the exec-path. We will just use "#!" as a
407 # guess for a shell-script, since we have no idea what the user
408 # may have configured as the shell path.
409 test -x "$1" ||
410 test "#!" = "$(head -c 2 <"$1")" ||
411 return;
Johannes Schindelin4e1be632009-02-04 00:25:59 +0100412
413 base=$(basename "$1")
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000414 symlink_target=$GIT_BUILD_DIR/$base
Johannes Schindelin4e1be632009-02-04 00:25:59 +0100415 # do not override scripts
416 if test -x "$symlink_target" &&
417 test ! -d "$symlink_target" &&
418 test "#!" != "$(head -c 2 < "$symlink_target")"
419 then
420 symlink_target=../valgrind.sh
421 fi
Johannes Schindelinefd92ff2009-02-04 00:26:08 +0100422 case "$base" in
423 *.sh|*.perl)
424 symlink_target=../unprocessed-script
425 esac
Johannes Schindelin4e1be632009-02-04 00:25:59 +0100426 # create the link, or replace it if it is out of date
427 make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
428 }
429
430 # override all git executables in TEST_DIRECTORY/..
431 GIT_VALGRIND=$TEST_DIRECTORY/valgrind
432 mkdir -p "$GIT_VALGRIND"/bin
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000433 for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/test-*
Johannes Schindelin4e1be632009-02-04 00:25:59 +0100434 do
435 make_valgrind_symlink $file
436 done
Thomas Rastee0d7bf2011-08-30 02:47:36 +0200437 # special-case the mergetools loadables
438 make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools"
Johannes Schindelinefd92ff2009-02-04 00:26:08 +0100439 OLDIFS=$IFS
440 IFS=:
441 for path in $PATH
442 do
443 ls "$path"/git-* 2> /dev/null |
444 while read file
445 do
446 make_valgrind_symlink "$file"
447 done
448 done
449 IFS=$OLDIFS
Johannes Schindelin4e1be632009-02-04 00:25:59 +0100450 PATH=$GIT_VALGRIND/bin:$PATH
451 GIT_EXEC_PATH=$GIT_VALGRIND/bin
452 export GIT_VALGRIND
Matthew Ogilviee4597aa2009-12-02 22:14:06 -0700453elif test -n "$GIT_TEST_INSTALLED" ; then
454 GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) ||
455 error "Cannot run git from $GIT_TEST_INSTALLED."
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000456 PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR:$PATH
Matthew Ogilviee4597aa2009-12-02 22:14:06 -0700457 GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
458else # normal case, use ../bin-wrappers only unless $with_dashes:
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000459 git_bin_dir="$GIT_BUILD_DIR/bin-wrappers"
Matthew Ogilviee4597aa2009-12-02 22:14:06 -0700460 if ! test -x "$git_bin_dir/git" ; then
461 if test -z "$with_dashes" ; then
462 say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"
463 fi
464 with_dashes=t
465 fi
466 PATH="$git_bin_dir:$PATH"
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000467 GIT_EXEC_PATH=$GIT_BUILD_DIR
Matthew Ogilviee4597aa2009-12-02 22:14:06 -0700468 if test -n "$with_dashes" ; then
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000469 PATH="$GIT_BUILD_DIR:$PATH"
Matthew Ogilviee4597aa2009-12-02 22:14:06 -0700470 fi
Johannes Schindelin4e1be632009-02-04 00:25:59 +0100471fi
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000472GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt
Jeff King8bfa6bd2008-02-06 05:11:53 -0500473unset GIT_CONFIG
Jeff King8bfa6bd2008-02-06 05:11:53 -0500474GIT_CONFIG_NOSYSTEM=1
Jonathan Nieder3c995be2011-03-15 04:05:10 -0500475GIT_ATTR_NOSYSTEM=1
Jonathan Nieder8f323c02011-03-15 04:04:49 -0500476export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
Junio C Hamano49ccb082005-12-07 21:52:28 -0800477
Ævar Arnfjörð Bjarmasonaed604c2010-08-19 16:08:09 +0000478. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
Jeff Kingac10a852009-12-07 00:32:50 -0500479
Junio C Hamano5e87eae2010-06-11 09:40:25 -0700480if test -z "$GIT_TEST_CMP"
481then
482 if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"
483 then
484 GIT_TEST_CMP="$DIFF -c"
485 else
486 GIT_TEST_CMP="$DIFF -u"
487 fi
488fi
489
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000490GITPERLLIB="$GIT_BUILD_DIR"/perl/blib/lib:"$GIT_BUILD_DIR"/perl/blib/arch/auto/Git
Petr Baudis6fcca932006-07-03 23:16:32 +0200491export GITPERLLIB
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000492test -d "$GIT_BUILD_DIR"/templates/blt || {
Junio C Hamanoeea42062005-12-10 20:55:32 -0800493 error "You haven't built things yet, have you?"
494}
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700495
Jeff Kingac10a852009-12-07 00:32:50 -0500496if test -z "$GIT_TEST_INSTALLED" && test -z "$NO_PYTHON"
Sverre Rabbelier2fe40b62009-11-18 02:42:32 +0100497then
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000498 GITPYTHONLIB="$GIT_BUILD_DIR/git_remote_helpers/build/lib"
Sverre Rabbelier2fe40b62009-11-18 02:42:32 +0100499 export GITPYTHONLIB
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000500 test -d "$GIT_BUILD_DIR"/git_remote_helpers/build || {
Sverre Rabbelier2fe40b62009-11-18 02:42:32 +0100501 error "You haven't built git_remote_helpers yet, have you?"
502 }
503fi
504
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +0000505if ! test -x "$GIT_BUILD_DIR"/test-chmtime; then
Eric Wong56cf9802007-02-24 16:59:52 -0800506 echo >&2 'You need to build test-chmtime:'
507 echo >&2 'Run "make test-chmtime" in the source (toplevel) directory'
508 exit 1
509fi
510
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700511# Test repository
Johannes Schindelinabc5d372008-08-08 13:08:37 +0200512test="trash directory.$(basename "$0" .sh)"
Jeff Kingf423ef52009-08-09 04:39:45 -0400513test -n "$root" && test="$root/$test"
514case "$test" in
515/*) TRASH_DIRECTORY="$test" ;;
516 *) TRASH_DIRECTORY="$TEST_DIRECTORY/$test" ;;
517esac
Jeff King91c8b822009-08-09 04:38:11 -0400518test ! -z "$debug" || remove_trash=$TRASH_DIRECTORY
Junio C Hamano8d14ac92008-03-18 21:58:01 -0700519rm -fr "$test" || {
Clemens Buchacher6e7b5aa2009-06-01 14:14:41 +0200520 GIT_EXIT_OK=t
Junio C Hamano8d14ac92008-03-18 21:58:01 -0700521 echo >&5 "FATAL: Cannot prepare test area"
522 exit 1
523}
524
Alex Riesen90cff962011-03-26 19:46:34 +0100525HOME="$TRASH_DIRECTORY"
526export HOME
527
Bryan Donlan4a7aacc2008-05-04 01:38:00 -0400528test_create_repo "$test"
Lea Wiemann1bd9c642008-05-31 23:11:21 +0200529# Use -P to resolve symlinks in our working directory so that the cwd
530# in subprocesses like git equals our $PWD (for pathname comparisons).
531cd -P "$test" || exit 1
Junio C Hamano04ece592006-12-28 17:58:00 -0800532
Johannes Sixtd5d9de12009-02-05 20:59:27 +0100533this_test=${0##*/}
534this_test=${this_test%%-*}
Junio C Hamano04ece592006-12-28 17:58:00 -0800535for skp in $GIT_SKIP_TESTS
536do
Michael J Gruber47e67d42010-07-12 12:32:18 +0200537 case "$this_test" in
538 $skp)
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200539 say_color skip >&3 "skipping test $this_test altogether"
Michael J Gruber637ab292010-07-12 12:33:49 +0200540 skip_all="skip all tests in $this_test"
Junio C Hamano04ece592006-12-28 17:58:00 -0800541 test_done
542 esac
543done
Johannes Sixtf17e9fb2009-03-11 21:17:26 +0100544
Brandon Casey86487322009-08-28 17:32:41 -0500545# Provide an implementation of the 'yes' utility
546yes () {
547 if test $# = 0
548 then
549 y=y
550 else
551 y="$*"
552 fi
553
554 while echo "$y"
555 do
556 :
557 done
558}
559
Johannes Sixtf17e9fb2009-03-11 21:17:26 +0100560# Fix some commands on Windows
561case $(uname -s) in
562*MINGW*)
563 # Windows has its own (incompatible) sort and find
564 sort () {
565 /usr/bin/sort "$@"
566 }
567 find () {
568 /usr/bin/find "$@"
569 }
Johannes Sixt5397ea32009-03-14 22:21:27 +0100570 sum () {
571 md5sum "$@"
572 }
Johannes Sixt41141562009-03-13 23:35:24 +0100573 # git sees Windows-style pwd
574 pwd () {
575 builtin pwd -W
576 }
Johannes Sixtee9fb682009-03-13 22:55:27 +0100577 # no POSIX permissions
Johannes Sixt6fd11062009-03-13 23:00:15 +0100578 # backslashes in pathspec are converted to '/'
Johannes Sixtfb9a2be2009-03-25 13:21:15 +0100579 # exec does not inherit the PID
Pat Thoytsa94114a2010-09-12 10:37:24 +0100580 test_set_prereq MINGW
Ramsay Jonesa31d0662010-12-14 18:32:12 +0000581 test_set_prereq SED_STRIPS_CR
582 ;;
583*CYGWIN*)
584 test_set_prereq POSIXPERM
Ramsay Jonesa31d0662010-12-14 18:32:12 +0000585 test_set_prereq EXECKEEPSPID
586 test_set_prereq NOT_MINGW
587 test_set_prereq SED_STRIPS_CR
Johannes Sixtee9fb682009-03-13 22:55:27 +0100588 ;;
589*)
590 test_set_prereq POSIXPERM
Johannes Sixt6fd11062009-03-13 23:00:15 +0100591 test_set_prereq BSLASHPSPEC
Johannes Sixtfb9a2be2009-03-25 13:21:15 +0100592 test_set_prereq EXECKEEPSPID
Pat Thoyts3ba9ba82010-09-27 22:02:57 +0100593 test_set_prereq NOT_MINGW
Johannes Sixtf17e9fb2009-03-11 21:17:26 +0100594 ;;
595esac
Johannes Sixt704a3142009-03-04 22:38:24 +0100596
Jeff King1b19ccd2009-04-03 15:33:59 -0400597test -z "$NO_PERL" && test_set_prereq PERL
Johan Herlandd4e1b472009-11-18 02:42:31 +0100598test -z "$NO_PYTHON" && test_set_prereq PYTHON
Michał Kiedrowicz8f852ce2011-05-09 23:52:07 +0200599test -n "$USE_LIBPCRE" && test_set_prereq LIBPCRE
Ævar Arnfjörð Bjarmason5e9637c2011-11-18 00:14:42 +0100600test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
Jeff King1b19ccd2009-04-03 15:33:59 -0400601
Ævar Arnfjörð Bjarmasonbb946bb2011-02-22 23:41:21 +0000602# Can we rely on git's output in the C locale?
Jonathan Nieder30955222011-02-22 23:41:22 +0000603if test -n "$GETTEXT_POISON"
604then
605 GIT_GETTEXT_POISON=YesPlease
606 export GIT_GETTEXT_POISON
Ævar Arnfjörð Bjarmason5e9637c2011-11-18 00:14:42 +0100607 test_set_prereq GETTEXT_POISON
Jonathan Nieder30955222011-02-22 23:41:22 +0000608else
609 test_set_prereq C_LOCALE_OUTPUT
610fi
Ævar Arnfjörð Bjarmasonbb946bb2011-02-22 23:41:21 +0000611
Junio C Hamanocabdee22011-04-12 11:23:23 -0700612# Use this instead of test_cmp to compare files that contain expected and
613# actual output from git commands that can be translated. When running
614# under GETTEXT_POISON this pretends that the command produced expected
615# results.
616test_i18ncmp () {
617 test -n "$GETTEXT_POISON" || test_cmp "$@"
618}
619
Junio C Hamano127df8c2011-04-12 15:57:08 -0700620# Use this instead of "grep expected-string actual" to see if the
621# output from a git command that can be translated either contains an
622# expected string, or does not contain an unwanted one. When running
623# under GETTEXT_POISON this pretends that the command produced expected
624# results.
625test_i18ngrep () {
626 if test -n "$GETTEXT_POISON"
627 then
628 : # pretend success
629 elif test "x!" = "x$1"
630 then
631 shift
632 ! grep "$@"
633 else
634 grep "$@"
635 fi
636}
637
Johannes Sixt704a3142009-03-04 22:38:24 +0100638# test whether the filesystem supports symbolic links
639ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS
640rm -f y
Ævar Arnfjörð Bjarmasonc91cfd12010-08-06 22:09:09 +0000641
642# When the tests are run as root, permission tests will report that
643# things are writable when they shouldn't be.
644test -w / || test_set_prereq SANITY