PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/t/test-lib.sh

https://github.com/VonC/git
Shell | 999 lines | 820 code | 87 blank | 92 comment | 93 complexity | fb1dcc6ae1d4da55bc73d86449ba9264 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause
  1. # Test framework for git. See t/README for usage.
  2. #
  3. # Copyright (c) 2005 Junio C Hamano
  4. #
  5. # 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/ .
  17. # Keep the original TERM for say_color
  18. ORIGINAL_TERM=$TERM
  19. # Test the binaries we have just built. The tests are kept in
  20. # t/ subdirectory and are run in 'trash directory' subdirectory.
  21. if test -z "$TEST_DIRECTORY"
  22. then
  23. # We allow tests to override this, in case they want to run tests
  24. # outside of t/, e.g. for running tests on the test library
  25. # itself.
  26. TEST_DIRECTORY=$(pwd)
  27. else
  28. # ensure that TEST_DIRECTORY is an absolute path so that it
  29. # is valid even if the current working directory is changed
  30. TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1
  31. fi
  32. if test -z "$TEST_OUTPUT_DIRECTORY"
  33. then
  34. # Similarly, override this to store the test-results subdir
  35. # elsewhere
  36. TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY
  37. fi
  38. GIT_BUILD_DIR="$TEST_DIRECTORY"/..
  39. ################################################################
  40. # It appears that people try to run tests without building...
  41. "$GIT_BUILD_DIR/git" >/dev/null
  42. if test $? != 1
  43. then
  44. echo >&2 'error: you do not seem to have built git yet.'
  45. exit 1
  46. fi
  47. . "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
  48. export PERL_PATH SHELL_PATH
  49. # if --tee was passed, write the output not only to the terminal, but
  50. # additionally to the file test-results/$BASENAME.out, too.
  51. case "$GIT_TEST_TEE_STARTED, $* " in
  52. done,*)
  53. # do not redirect again
  54. ;;
  55. *' --tee '*|*' --va'*)
  56. mkdir -p "$TEST_OUTPUT_DIRECTORY/test-results"
  57. BASE="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)"
  58. (GIT_TEST_TEE_STARTED=done ${SHELL_PATH} "$0" "$@" 2>&1;
  59. echo $? > $BASE.exit) | tee $BASE.out
  60. test "$(cat $BASE.exit)" = 0
  61. exit
  62. ;;
  63. esac
  64. # For repeatability, reset the environment to known value.
  65. LANG=C
  66. LC_ALL=C
  67. PAGER=cat
  68. TZ=UTC
  69. TERM=dumb
  70. export LANG LC_ALL PAGER TERM TZ
  71. EDITOR=:
  72. # A call to "unset" with no arguments causes at least Solaris 10
  73. # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
  74. # deriving from the command substitution clustered with the other
  75. # ones.
  76. unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e '
  77. my @env = keys %ENV;
  78. my $ok = join("|", qw(
  79. TRACE
  80. DEBUG
  81. USE_LOOKUP
  82. TEST
  83. .*_TEST
  84. PROVE
  85. VALGRIND
  86. UNZIP
  87. PERF_
  88. CURL_VERBOSE
  89. ));
  90. my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
  91. print join("\n", @vars);
  92. ')
  93. unset XDG_CONFIG_HOME
  94. unset GITPERLLIB
  95. GIT_AUTHOR_EMAIL=author@example.com
  96. GIT_AUTHOR_NAME='A U Thor'
  97. GIT_COMMITTER_EMAIL=committer@example.com
  98. GIT_COMMITTER_NAME='C O Mitter'
  99. GIT_MERGE_VERBOSITY=5
  100. GIT_MERGE_AUTOEDIT=no
  101. export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
  102. export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
  103. export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
  104. export EDITOR
  105. # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
  106. GIT_TRACE_BARE=1
  107. export GIT_TRACE_BARE
  108. if test -n "${TEST_GIT_INDEX_VERSION:+isset}"
  109. then
  110. GIT_INDEX_VERSION="$TEST_GIT_INDEX_VERSION"
  111. export GIT_INDEX_VERSION
  112. fi
  113. # Add libc MALLOC and MALLOC_PERTURB test
  114. # only if we are not executing the test with valgrind
  115. if expr " $GIT_TEST_OPTS " : ".* --valgrind " >/dev/null ||
  116. test -n "$TEST_NO_MALLOC_CHECK"
  117. then
  118. setup_malloc_check () {
  119. : nothing
  120. }
  121. teardown_malloc_check () {
  122. : nothing
  123. }
  124. else
  125. setup_malloc_check () {
  126. MALLOC_CHECK_=3 MALLOC_PERTURB_=165
  127. export MALLOC_CHECK_ MALLOC_PERTURB_
  128. }
  129. teardown_malloc_check () {
  130. unset MALLOC_CHECK_ MALLOC_PERTURB_
  131. }
  132. fi
  133. # Protect ourselves from common misconfiguration to export
  134. # CDPATH into the environment
  135. unset CDPATH
  136. unset GREP_OPTIONS
  137. unset UNZIP
  138. case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in
  139. 1|2|true)
  140. echo "* warning: Some tests will not work if GIT_TRACE" \
  141. "is set as to trace on STDERR ! *"
  142. echo "* warning: Please set GIT_TRACE to something" \
  143. "other than 1, 2 or true ! *"
  144. ;;
  145. esac
  146. # Convenience
  147. #
  148. # A regexp to match 5 and 40 hexdigits
  149. _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
  150. _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
  151. # Zero SHA-1
  152. _z40=0000000000000000000000000000000000000000
  153. # Line feed
  154. LF='
  155. '
  156. export _x05 _x40 _z40 LF
  157. # Each test should start with something like this, after copyright notices:
  158. #
  159. # test_description='Description of this test...
  160. # This test checks if command xyzzy does the right thing...
  161. # '
  162. # . ./test-lib.sh
  163. [ "x$ORIGINAL_TERM" != "xdumb" ] && (
  164. TERM=$ORIGINAL_TERM &&
  165. export TERM &&
  166. [ -t 1 ] &&
  167. tput bold >/dev/null 2>&1 &&
  168. tput setaf 1 >/dev/null 2>&1 &&
  169. tput sgr0 >/dev/null 2>&1
  170. ) &&
  171. color=t
  172. while test "$#" -ne 0
  173. do
  174. case "$1" in
  175. -d|--d|--de|--deb|--debu|--debug)
  176. debug=t; shift ;;
  177. -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
  178. immediate=t; shift ;;
  179. -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
  180. GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;;
  181. -r)
  182. shift; test "$#" -ne 0 || {
  183. echo 'error: -r requires an argument' >&2;
  184. exit 1;
  185. }
  186. run_list=$1; shift ;;
  187. --run=*)
  188. run_list=$(expr "z$1" : 'z[^=]*=\(.*\)'); shift ;;
  189. -h|--h|--he|--hel|--help)
  190. help=t; shift ;;
  191. -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
  192. verbose=t; shift ;;
  193. --verbose-only=*)
  194. verbose_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
  195. shift ;;
  196. -q|--q|--qu|--qui|--quie|--quiet)
  197. # Ignore --quiet under a TAP::Harness. Saying how many tests
  198. # passed without the ok/not ok details is always an error.
  199. test -z "$HARNESS_ACTIVE" && quiet=t; shift ;;
  200. --with-dashes)
  201. with_dashes=t; shift ;;
  202. --no-color)
  203. color=; shift ;;
  204. --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
  205. valgrind=memcheck
  206. shift ;;
  207. --valgrind=*)
  208. valgrind=$(expr "z$1" : 'z[^=]*=\(.*\)')
  209. shift ;;
  210. --valgrind-only=*)
  211. valgrind_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
  212. shift ;;
  213. --tee)
  214. shift ;; # was handled already
  215. --root=*)
  216. root=$(expr "z$1" : 'z[^=]*=\(.*\)')
  217. shift ;;
  218. *)
  219. echo "error: unknown test option '$1'" >&2; exit 1 ;;
  220. esac
  221. done
  222. if test -n "$valgrind_only"
  223. then
  224. test -z "$valgrind" && valgrind=memcheck
  225. test -z "$verbose" && verbose_only="$valgrind_only"
  226. elif test -n "$valgrind"
  227. then
  228. verbose=t
  229. fi
  230. if test -n "$color"
  231. then
  232. say_color () {
  233. (
  234. TERM=$ORIGINAL_TERM
  235. export TERM
  236. case "$1" in
  237. error)
  238. tput bold; tput setaf 1;; # bold red
  239. skip)
  240. tput setaf 4;; # blue
  241. warn)
  242. tput setaf 3;; # brown/yellow
  243. pass)
  244. tput setaf 2;; # green
  245. info)
  246. tput setaf 6;; # cyan
  247. *)
  248. test -n "$quiet" && return;;
  249. esac
  250. shift
  251. printf "%s" "$*"
  252. tput sgr0
  253. echo
  254. )
  255. }
  256. else
  257. say_color() {
  258. test -z "$1" && test -n "$quiet" && return
  259. shift
  260. printf "%s\n" "$*"
  261. }
  262. fi
  263. error () {
  264. say_color error "error: $*"
  265. GIT_EXIT_OK=t
  266. exit 1
  267. }
  268. say () {
  269. say_color info "$*"
  270. }
  271. test "${test_description}" != "" ||
  272. error "Test script did not set test_description."
  273. if test "$help" = "t"
  274. then
  275. printf '%s\n' "$test_description"
  276. exit 0
  277. fi
  278. exec 5>&1
  279. exec 6<&0
  280. if test "$verbose" = "t"
  281. then
  282. exec 4>&2 3>&1
  283. else
  284. exec 4>/dev/null 3>/dev/null
  285. fi
  286. test_failure=0
  287. test_count=0
  288. test_fixed=0
  289. test_broken=0
  290. test_success=0
  291. test_external_has_tap=0
  292. die () {
  293. code=$?
  294. if test -n "$GIT_EXIT_OK"
  295. then
  296. exit $code
  297. else
  298. echo >&5 "FATAL: Unexpected exit with code $code"
  299. exit 1
  300. fi
  301. }
  302. GIT_EXIT_OK=
  303. trap 'die' EXIT
  304. # The user-facing functions are loaded from a separate file so that
  305. # test_perf subshells can have them too
  306. . "$TEST_DIRECTORY/test-lib-functions.sh"
  307. # You are not expected to call test_ok_ and test_failure_ directly, use
  308. # the test_expect_* functions instead.
  309. test_ok_ () {
  310. test_success=$(($test_success + 1))
  311. say_color "" "ok $test_count - $@"
  312. }
  313. test_failure_ () {
  314. test_failure=$(($test_failure + 1))
  315. say_color error "not ok $test_count - $1"
  316. shift
  317. printf '%s\n' "$*" | sed -e 's/^/# /'
  318. test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
  319. }
  320. test_known_broken_ok_ () {
  321. test_fixed=$(($test_fixed+1))
  322. say_color error "ok $test_count - $@ # TODO known breakage vanished"
  323. }
  324. test_known_broken_failure_ () {
  325. test_broken=$(($test_broken+1))
  326. say_color warn "not ok $test_count - $@ # TODO known breakage"
  327. }
  328. test_debug () {
  329. test "$debug" = "" || eval "$1"
  330. }
  331. match_pattern_list () {
  332. arg="$1"
  333. shift
  334. test -z "$*" && return 1
  335. for pattern_
  336. do
  337. case "$arg" in
  338. $pattern_)
  339. return 0
  340. esac
  341. done
  342. return 1
  343. }
  344. match_test_selector_list () {
  345. title="$1"
  346. shift
  347. arg="$1"
  348. shift
  349. test -z "$1" && return 0
  350. # Both commas and whitespace are accepted as separators.
  351. OLDIFS=$IFS
  352. IFS=' ,'
  353. set -- $1
  354. IFS=$OLDIFS
  355. # If the first selector is negative we include by default.
  356. include=
  357. case "$1" in
  358. !*) include=t ;;
  359. esac
  360. for selector
  361. do
  362. orig_selector=$selector
  363. positive=t
  364. case "$selector" in
  365. !*)
  366. positive=
  367. selector=${selector##?}
  368. ;;
  369. esac
  370. test -z "$selector" && continue
  371. case "$selector" in
  372. *-*)
  373. if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev/null
  374. then
  375. echo "error: $title: invalid non-numeric in range" \
  376. "start: '$orig_selector'" >&2
  377. exit 1
  378. fi
  379. if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev/null
  380. then
  381. echo "error: $title: invalid non-numeric in range" \
  382. "end: '$orig_selector'" >&2
  383. exit 1
  384. fi
  385. ;;
  386. *)
  387. if expr "z$selector" : "z[0-9]*[^0-9]" >/dev/null
  388. then
  389. echo "error: $title: invalid non-numeric in test" \
  390. "selector: '$orig_selector'" >&2
  391. exit 1
  392. fi
  393. esac
  394. # Short cut for "obvious" cases
  395. test -z "$include" && test -z "$positive" && continue
  396. test -n "$include" && test -n "$positive" && continue
  397. case "$selector" in
  398. -*)
  399. if test $arg -le ${selector#-}
  400. then
  401. include=$positive
  402. fi
  403. ;;
  404. *-)
  405. if test $arg -ge ${selector%-}
  406. then
  407. include=$positive
  408. fi
  409. ;;
  410. *-*)
  411. if test ${selector%%-*} -le $arg \
  412. && test $arg -le ${selector#*-}
  413. then
  414. include=$positive
  415. fi
  416. ;;
  417. *)
  418. if test $arg -eq $selector
  419. then
  420. include=$positive
  421. fi
  422. ;;
  423. esac
  424. done
  425. test -n "$include"
  426. }
  427. maybe_teardown_verbose () {
  428. test -z "$verbose_only" && return
  429. exec 4>/dev/null 3>/dev/null
  430. verbose=
  431. }
  432. last_verbose=t
  433. maybe_setup_verbose () {
  434. test -z "$verbose_only" && return
  435. if match_pattern_list $test_count $verbose_only
  436. then
  437. exec 4>&2 3>&1
  438. # Emit a delimiting blank line when going from
  439. # non-verbose to verbose. Within verbose mode the
  440. # delimiter is printed by test_expect_*. The choice
  441. # of the initial $last_verbose is such that before
  442. # test 1, we do not print it.
  443. test -z "$last_verbose" && echo >&3 ""
  444. verbose=t
  445. else
  446. exec 4>/dev/null 3>/dev/null
  447. verbose=
  448. fi
  449. last_verbose=$verbose
  450. }
  451. maybe_teardown_valgrind () {
  452. test -z "$GIT_VALGRIND" && return
  453. GIT_VALGRIND_ENABLED=
  454. }
  455. maybe_setup_valgrind () {
  456. test -z "$GIT_VALGRIND" && return
  457. if test -z "$valgrind_only"
  458. then
  459. GIT_VALGRIND_ENABLED=t
  460. return
  461. fi
  462. GIT_VALGRIND_ENABLED=
  463. if match_pattern_list $test_count $valgrind_only
  464. then
  465. GIT_VALGRIND_ENABLED=t
  466. fi
  467. }
  468. test_eval_ () {
  469. # This is a separate function because some tests use
  470. # "return" to end a test_expect_success block early.
  471. eval </dev/null >&3 2>&4 "$*"
  472. }
  473. test_run_ () {
  474. test_cleanup=:
  475. expecting_failure=$2
  476. setup_malloc_check
  477. test_eval_ "$1"
  478. eval_ret=$?
  479. teardown_malloc_check
  480. if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure"
  481. then
  482. setup_malloc_check
  483. test_eval_ "$test_cleanup"
  484. teardown_malloc_check
  485. fi
  486. if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
  487. then
  488. echo ""
  489. fi
  490. return "$eval_ret"
  491. }
  492. test_start_ () {
  493. test_count=$(($test_count+1))
  494. maybe_setup_verbose
  495. maybe_setup_valgrind
  496. }
  497. test_finish_ () {
  498. echo >&3 ""
  499. maybe_teardown_valgrind
  500. maybe_teardown_verbose
  501. }
  502. test_skip () {
  503. to_skip=
  504. skipped_reason=
  505. if match_pattern_list $this_test.$test_count $GIT_SKIP_TESTS
  506. then
  507. to_skip=t
  508. skipped_reason="GIT_SKIP_TESTS"
  509. fi
  510. if test -z "$to_skip" && test -n "$test_prereq" &&
  511. ! test_have_prereq "$test_prereq"
  512. then
  513. to_skip=t
  514. of_prereq=
  515. if test "$missing_prereq" != "$test_prereq"
  516. then
  517. of_prereq=" of $test_prereq"
  518. fi
  519. skipped_reason="missing $missing_prereq${of_prereq}"
  520. fi
  521. if test -z "$to_skip" && test -n "$run_list" &&
  522. ! match_test_selector_list '--run' $test_count "$run_list"
  523. then
  524. to_skip=t
  525. skipped_reason="--run"
  526. fi
  527. case "$to_skip" in
  528. t)
  529. say_color skip >&3 "skipping test: $@"
  530. say_color skip "ok $test_count # skip $1 ($skipped_reason)"
  531. : true
  532. ;;
  533. *)
  534. false
  535. ;;
  536. esac
  537. }
  538. # stub; perf-lib overrides it
  539. test_at_end_hook_ () {
  540. :
  541. }
  542. test_done () {
  543. GIT_EXIT_OK=t
  544. if test -z "$HARNESS_ACTIVE"
  545. then
  546. test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results"
  547. mkdir -p "$test_results_dir"
  548. base=${0##*/}
  549. test_results_path="$test_results_dir/${base%.sh}-$$.counts"
  550. cat >>"$test_results_path" <<-EOF
  551. total $test_count
  552. success $test_success
  553. fixed $test_fixed
  554. broken $test_broken
  555. failed $test_failure
  556. EOF
  557. fi
  558. if test "$test_fixed" != 0
  559. then
  560. say_color error "# $test_fixed known breakage(s) vanished; please update test(s)"
  561. fi
  562. if test "$test_broken" != 0
  563. then
  564. say_color warn "# still have $test_broken known breakage(s)"
  565. fi
  566. if test "$test_broken" != 0 || test "$test_fixed" != 0
  567. then
  568. test_remaining=$(( $test_count - $test_broken - $test_fixed ))
  569. msg="remaining $test_remaining test(s)"
  570. else
  571. test_remaining=$test_count
  572. msg="$test_count test(s)"
  573. fi
  574. case "$test_failure" in
  575. 0)
  576. # Maybe print SKIP message
  577. if test -n "$skip_all" && test $test_count -gt 0
  578. then
  579. error "Can't use skip_all after running some tests"
  580. fi
  581. [ -z "$skip_all" ] || skip_all=" # SKIP $skip_all"
  582. if test $test_external_has_tap -eq 0
  583. then
  584. if test $test_remaining -gt 0
  585. then
  586. say_color pass "# passed all $msg"
  587. fi
  588. say "1..$test_count$skip_all"
  589. fi
  590. test -d "$remove_trash" &&
  591. cd "$(dirname "$remove_trash")" &&
  592. rm -rf "$(basename "$remove_trash")"
  593. test_at_end_hook_
  594. exit 0 ;;
  595. *)
  596. if test $test_external_has_tap -eq 0
  597. then
  598. say_color error "# failed $test_failure among $msg"
  599. say "1..$test_count"
  600. fi
  601. exit 1 ;;
  602. esac
  603. }
  604. if test -n "$valgrind"
  605. then
  606. make_symlink () {
  607. test -h "$2" &&
  608. test "$1" = "$(readlink "$2")" || {
  609. # be super paranoid
  610. if mkdir "$2".lock
  611. then
  612. rm -f "$2" &&
  613. ln -s "$1" "$2" &&
  614. rm -r "$2".lock
  615. else
  616. while test -d "$2".lock
  617. do
  618. say "Waiting for lock on $2."
  619. sleep 1
  620. done
  621. fi
  622. }
  623. }
  624. make_valgrind_symlink () {
  625. # handle only executables, unless they are shell libraries that
  626. # need to be in the exec-path.
  627. test -x "$1" ||
  628. test "# " = "$(head -c 2 <"$1")" ||
  629. return;
  630. base=$(basename "$1")
  631. symlink_target=$GIT_BUILD_DIR/$base
  632. # do not override scripts
  633. if test -x "$symlink_target" &&
  634. test ! -d "$symlink_target" &&
  635. test "#!" != "$(head -c 2 < "$symlink_target")"
  636. then
  637. symlink_target=../valgrind.sh
  638. fi
  639. case "$base" in
  640. *.sh|*.perl)
  641. symlink_target=../unprocessed-script
  642. esac
  643. # create the link, or replace it if it is out of date
  644. make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
  645. }
  646. # override all git executables in TEST_DIRECTORY/..
  647. GIT_VALGRIND=$TEST_DIRECTORY/valgrind
  648. mkdir -p "$GIT_VALGRIND"/bin
  649. for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/test-*
  650. do
  651. make_valgrind_symlink $file
  652. done
  653. # special-case the mergetools loadables
  654. make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools"
  655. OLDIFS=$IFS
  656. IFS=:
  657. for path in $PATH
  658. do
  659. ls "$path"/git-* 2> /dev/null |
  660. while read file
  661. do
  662. make_valgrind_symlink "$file"
  663. done
  664. done
  665. IFS=$OLDIFS
  666. PATH=$GIT_VALGRIND/bin:$PATH
  667. GIT_EXEC_PATH=$GIT_VALGRIND/bin
  668. export GIT_VALGRIND
  669. GIT_VALGRIND_MODE="$valgrind"
  670. export GIT_VALGRIND_MODE
  671. GIT_VALGRIND_ENABLED=t
  672. test -n "$valgrind_only" && GIT_VALGRIND_ENABLED=
  673. export GIT_VALGRIND_ENABLED
  674. elif test -n "$GIT_TEST_INSTALLED"
  675. then
  676. GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) ||
  677. error "Cannot run git from $GIT_TEST_INSTALLED."
  678. PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR:$PATH
  679. GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
  680. else # normal case, use ../bin-wrappers only unless $with_dashes:
  681. git_bin_dir="$GIT_BUILD_DIR/bin-wrappers"
  682. if ! test -x "$git_bin_dir/git"
  683. then
  684. if test -z "$with_dashes"
  685. then
  686. say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"
  687. fi
  688. with_dashes=t
  689. fi
  690. PATH="$git_bin_dir:$PATH"
  691. GIT_EXEC_PATH=$GIT_BUILD_DIR
  692. if test -n "$with_dashes"
  693. then
  694. PATH="$GIT_BUILD_DIR:$PATH"
  695. fi
  696. fi
  697. GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt
  698. GIT_CONFIG_NOSYSTEM=1
  699. GIT_ATTR_NOSYSTEM=1
  700. export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
  701. if test -z "$GIT_TEST_CMP"
  702. then
  703. if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"
  704. then
  705. GIT_TEST_CMP="$DIFF -c"
  706. else
  707. GIT_TEST_CMP="$DIFF -u"
  708. fi
  709. fi
  710. GITPERLLIB="$GIT_BUILD_DIR"/perl/blib/lib:"$GIT_BUILD_DIR"/perl/blib/arch/auto/Git
  711. export GITPERLLIB
  712. test -d "$GIT_BUILD_DIR"/templates/blt || {
  713. error "You haven't built things yet, have you?"
  714. }
  715. if ! test -x "$GIT_BUILD_DIR"/test-chmtime
  716. then
  717. echo >&2 'You need to build test-chmtime:'
  718. echo >&2 'Run "make test-chmtime" in the source (toplevel) directory'
  719. exit 1
  720. fi
  721. # Test repository
  722. TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)"
  723. test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
  724. case "$TRASH_DIRECTORY" in
  725. /*) ;; # absolute path is good
  726. *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
  727. esac
  728. test ! -z "$debug" || remove_trash=$TRASH_DIRECTORY
  729. rm -fr "$TRASH_DIRECTORY" || {
  730. GIT_EXIT_OK=t
  731. echo >&5 "FATAL: Cannot prepare test area"
  732. exit 1
  733. }
  734. HOME="$TRASH_DIRECTORY"
  735. export HOME
  736. if test -z "$TEST_NO_CREATE_REPO"
  737. then
  738. test_create_repo "$TRASH_DIRECTORY"
  739. else
  740. mkdir -p "$TRASH_DIRECTORY"
  741. fi
  742. # Use -P to resolve symlinks in our working directory so that the cwd
  743. # in subprocesses like git equals our $PWD (for pathname comparisons).
  744. cd -P "$TRASH_DIRECTORY" || exit 1
  745. this_test=${0##*/}
  746. this_test=${this_test%%-*}
  747. if match_pattern_list "$this_test" $GIT_SKIP_TESTS
  748. then
  749. say_color info >&3 "skipping test $this_test altogether"
  750. skip_all="skip all tests in $this_test"
  751. test_done
  752. fi
  753. # Provide an implementation of the 'yes' utility
  754. yes () {
  755. if test $# = 0
  756. then
  757. y=y
  758. else
  759. y="$*"
  760. fi
  761. while echo "$y"
  762. do
  763. :
  764. done
  765. }
  766. # Fix some commands on Windows
  767. case $(uname -s) in
  768. *MINGW*)
  769. # Windows has its own (incompatible) sort and find
  770. sort () {
  771. /usr/bin/sort "$@"
  772. }
  773. find () {
  774. /usr/bin/find "$@"
  775. }
  776. sum () {
  777. md5sum "$@"
  778. }
  779. # git sees Windows-style pwd
  780. pwd () {
  781. builtin pwd -W
  782. }
  783. # no POSIX permissions
  784. # backslashes in pathspec are converted to '/'
  785. # exec does not inherit the PID
  786. test_set_prereq MINGW
  787. test_set_prereq NOT_CYGWIN
  788. test_set_prereq SED_STRIPS_CR
  789. test_set_prereq GREP_STRIPS_CR
  790. GIT_TEST_CMP=mingw_test_cmp
  791. ;;
  792. *CYGWIN*)
  793. test_set_prereq POSIXPERM
  794. test_set_prereq EXECKEEPSPID
  795. test_set_prereq NOT_MINGW
  796. test_set_prereq CYGWIN
  797. test_set_prereq SED_STRIPS_CR
  798. test_set_prereq GREP_STRIPS_CR
  799. ;;
  800. *)
  801. test_set_prereq POSIXPERM
  802. test_set_prereq BSLASHPSPEC
  803. test_set_prereq EXECKEEPSPID
  804. test_set_prereq NOT_MINGW
  805. test_set_prereq NOT_CYGWIN
  806. ;;
  807. esac
  808. ( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1
  809. test -z "$NO_PERL" && test_set_prereq PERL
  810. test -z "$NO_PYTHON" && test_set_prereq PYTHON
  811. test -n "$USE_LIBPCRE" && test_set_prereq LIBPCRE
  812. test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
  813. # Can we rely on git's output in the C locale?
  814. if test -n "$GETTEXT_POISON"
  815. then
  816. GIT_GETTEXT_POISON=YesPlease
  817. export GIT_GETTEXT_POISON
  818. test_set_prereq GETTEXT_POISON
  819. else
  820. test_set_prereq C_LOCALE_OUTPUT
  821. fi
  822. # Use this instead of test_cmp to compare files that contain expected and
  823. # actual output from git commands that can be translated. When running
  824. # under GETTEXT_POISON this pretends that the command produced expected
  825. # results.
  826. test_i18ncmp () {
  827. test -n "$GETTEXT_POISON" || test_cmp "$@"
  828. }
  829. # Use this instead of "grep expected-string actual" to see if the
  830. # output from a git command that can be translated either contains an
  831. # expected string, or does not contain an unwanted one. When running
  832. # under GETTEXT_POISON this pretends that the command produced expected
  833. # results.
  834. test_i18ngrep () {
  835. if test -n "$GETTEXT_POISON"
  836. then
  837. : # pretend success
  838. elif test "x!" = "x$1"
  839. then
  840. shift
  841. ! grep "$@"
  842. else
  843. grep "$@"
  844. fi
  845. }
  846. test_lazy_prereq PIPE '
  847. # test whether the filesystem supports FIFOs
  848. case $(uname -s) in
  849. CYGWIN*)
  850. false
  851. ;;
  852. *)
  853. rm -f testfifo && mkfifo testfifo
  854. ;;
  855. esac
  856. '
  857. test_lazy_prereq SYMLINKS '
  858. # test whether the filesystem supports symbolic links
  859. ln -s x y && test -h y
  860. '
  861. test_lazy_prereq FILEMODE '
  862. test "$(git config --bool core.filemode)" = true
  863. '
  864. test_lazy_prereq CASE_INSENSITIVE_FS '
  865. echo good >CamelCase &&
  866. echo bad >camelcase &&
  867. test "$(cat CamelCase)" != good
  868. '
  869. test_lazy_prereq UTF8_NFD_TO_NFC '
  870. # check whether FS converts nfd unicode to nfc
  871. auml=$(printf "\303\244")
  872. aumlcdiar=$(printf "\141\314\210")
  873. >"$auml" &&
  874. case "$(echo *)" in
  875. "$aumlcdiar")
  876. true ;;
  877. *)
  878. false ;;
  879. esac
  880. '
  881. test_lazy_prereq AUTOIDENT '
  882. sane_unset GIT_AUTHOR_NAME &&
  883. sane_unset GIT_AUTHOR_EMAIL &&
  884. git var GIT_AUTHOR_IDENT
  885. '
  886. test_lazy_prereq EXPENSIVE '
  887. test -n "$GIT_TEST_LONG"
  888. '
  889. test_lazy_prereq USR_BIN_TIME '
  890. test -x /usr/bin/time
  891. '
  892. # When the tests are run as root, permission tests will report that
  893. # things are writable when they shouldn't be.
  894. test -w / || test_set_prereq SANITY
  895. GIT_UNZIP=${GIT_UNZIP:-unzip}
  896. test_lazy_prereq UNZIP '
  897. "$GIT_UNZIP" -v
  898. test $? -ne 127
  899. '