PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/t/test-lib.sh

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