3 # Copyright (c) 2005 Junio C Hamano
6 # For repeatability, reset the environment to known value.
11 export LANG LC_ALL PAGER TZ
13 # Each test should start with something like this, after copyright notices:
15 # test_description='Description of this test...
16 # This test checks if command xyzzy does the right thing...
30 test "${test_description}" != "" ||
31 error
"Test script did not set test_description."
36 -d|
--d|
--de|
--deb|
--debu|
--debug)
38 -i|
--i|
--im|
--imm|
--imme|
--immed|
--immedi|
--immedia|
--immediat|
--immediate)
40 -h|
--h|
--he|
--hel|
--help)
41 echo "$test_description"
43 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
51 if test "$verbose" = "t"
55 exec 4>/dev
/null
3>/dev
/null
61 trap 'echo >&5 "FATAL: Unexpected exit with code $?"; exit 1' exit
63 # Test the binaries we have just built. The tests are kept in
64 # test/ subdirectory and are run in test/trash subdirectory.
65 export PATH
="$(pwd):$PATH"
68 test -e "$dep" || error
"You haven't built things yet, have you?"
72 # You are not expected to call test_ok_ and test_failure_ directly, use
73 # the text_expect_* functions instead.
76 test_count
=$
(expr "$test_count" + 1)
77 say
" ok $test_count: $@"
81 test_count
=$
(expr "$test_count" + 1)
82 test_failure
=$
(expr "$test_failure" + 1);
83 say
"FAIL $test_count: $1"
85 echo "$@" |
sed -e 's/^/ /'
86 test "$immediate" = "" ||
{ trap - exit; exit 1; }
91 test "$debug" = "" ||
eval "$1"
100 test_expect_failure
() {
102 error
"bug in the test script: not 2 parameters to test-expect-failure"
103 say
>&3 "expecting failure: $2"
105 if [ "$?" = 0 -a "$eval_ret" != 0 ]
113 test_expect_success
() {
115 error
"bug in the test script: not 2 parameters to test-expect-success"
116 say
>&3 "expecting success: $2"
118 if [ "$?" = 0 -a "$eval_ret" = 0 ]
126 test_expect_code
() {
128 error
"bug in the test script: not 3 parameters to test-expect-code"
129 say
>&3 "expecting exit code $1: $3"
131 if [ "$?" = 0 -a "$eval_ret" = "$1" ]
141 case "$test_failure" in
144 # cd .. && rm -fr trash
145 # but that means we forbid any tests that use their own
146 # subdirectory from calling test_done without coming back
147 # to where they started from.
148 # The Makefile provided will clean this test area so
149 # we will leave things as they are.
151 say
"passed all $test_count test(s)"
155 say
"failed $test_failure among $test_count test(s)"
165 cd "$test" || error
"Cannot setup test environment"