1#!/bin/sh 2# 3# Copyright (c) 2005 Junio C Hamano 4# 5 6# For repeatability, reset the environment to known value. 7LANG=C 8LC_ALL=C 9PAGER=cat 10TZ=UTC 11export LANG LC_ALL PAGER TZ 12unset AUTHOR_DATE 13unset AUTHOR_EMAIL 14unset AUTHOR_NAME 15unset COMMIT_AUTHOR_EMAIL 16unset COMMIT_AUTHOR_NAME 17unset GIT_ALTERNATE_OBJECT_DIRECTORIES 18unset GIT_AUTHOR_DATE 19GIT_AUTHOR_EMAIL=author@example.com 20GIT_AUTHOR_NAME='A U Thor' 21unset GIT_COMMITTER_DATE 22GIT_COMMITTER_EMAIL=committer@example.com 23GIT_COMMITTER_NAME='C O Mitter' 24unset GIT_DIFF_OPTS 25unset GIT_DIR 26unset GIT_EXTERNAL_DIFF 27unset GIT_INDEX_FILE 28unset GIT_OBJECT_DIRECTORY 29unset GIT_TRACE 30unset SHA1_FILE_DIRECTORIES 31unset SHA1_FILE_DIRECTORY 32export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME 33export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME 34 35# Each test should start with something like this, after copyright notices: 36# 37# test_description='Description of this test... 38# This test checks if command xyzzy does the right thing... 39# ' 40# . ./test-lib.sh 41 42error () { 43echo"* error: $*" 44trap-exit 45exit1 46} 47 48say () { 49echo"* $*" 50} 51 52test"${test_description}"!=""|| 53error "Test script did not set test_description." 54 55whiletest"$#"-ne0 56do 57case"$1"in 58-d|--d|--de|--deb|--debu|--debug) 59 debug=t;shift;; 60-i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) 61 immediate=t;shift;; 62-h|--h|--he|--hel|--help) 63echo"$test_description" 64exit0;; 65-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) 66 verbose=t;shift;; 67--no-python) 68 no_python=t;shift;; 69*) 70break;; 71esac 72done 73 74exec5>&1 75iftest"$verbose"="t" 76then 77exec4>&2 3>&1 78else 79exec4>/dev/null 3>/dev/null 80fi 81 82test_failure=0 83test_count=0 84 85trap'echo >&5 "FATAL: Unexpected exit with code $?"; exit 1'exit 86 87 88# You are not expected to call test_ok_ and test_failure_ directly, use 89# the text_expect_* functions instead. 90 91test_ok_ () { 92 test_count=$(expr "$test_count" + 1) 93 say " ok$test_count: $@" 94} 95 96test_failure_ () { 97 test_count=$(expr "$test_count" + 1) 98 test_failure=$(expr "$test_failure" + 1); 99 say "FAIL$test_count:$1" 100shift 101echo"$@"|sed-e's/^/ /' 102test"$immediate"=""|| {trap-exit;exit1; } 103} 104 105 106test_debug () { 107test"$debug"=""||eval"$1" 108} 109 110test_run_ () { 111eval>&3 2>&4"$1" 112 eval_ret="$?" 113return0 114} 115 116test_expect_failure () { 117test"$#"=2|| 118 error "bug in the test script: not 2 parameters to test-expect-failure" 119 say >&3"expecting failure:$2" 120 test_run_ "$2" 121if["$?"=0-a"$eval_ret"!=0] 122then 123 test_ok_ "$1" 124else 125 test_failure_ "$@" 126fi 127} 128 129test_expect_success () { 130test"$#"=2|| 131 error "bug in the test script: not 2 parameters to test-expect-success" 132 say >&3"expecting success:$2" 133 test_run_ "$2" 134if["$?"=0-a"$eval_ret"=0] 135then 136 test_ok_ "$1" 137else 138 test_failure_ "$@" 139fi 140} 141 142test_expect_code () { 143test"$#"=3|| 144 error "bug in the test script: not 3 parameters to test-expect-code" 145 say >&3"expecting exit code$1:$3" 146 test_run_ "$3" 147if["$?"=0-a"$eval_ret"="$1"] 148then 149 test_ok_ "$2" 150else 151 test_failure_ "$@" 152fi 153} 154 155# Most tests can use the created repository, but some amy need to create more. 156# Usage: test_create_repo <directory> 157test_create_repo () { 158test"$#"=1|| 159 error "bug in the test script: not 1 parameter to test-create-repo" 160 owd=`pwd` 161 repo="$1" 162mkdir"$repo" 163cd"$repo"|| error "Cannot setup test environment" 164"$GIT_EXEC_PATH/git" init-db --template=$GIT_EXEC_PATH/templates/blt/2>/dev/null || 165 error "cannot run git init-db -- have you built things yet?" 166mv .git/hooks .git/hooks-disabled 167cd"$owd" 168} 169 170test_done () { 171trap-exit 172case"$test_failure"in 1730) 174# We could: 175# cd .. && rm -fr trash 176# but that means we forbid any tests that use their own 177# subdirectory from calling test_done without coming back 178# to where they started from. 179# The Makefile provided will clean this test area so 180# we will leave things as they are. 181 182 say "passed all$test_counttest(s)" 183exit0;; 184 185*) 186 say "failed$test_failureamong$test_counttest(s)" 187exit1;; 188 189esac 190} 191 192# Test the binaries we have just built. The tests are kept in 193# t/ subdirectory and are run in trash subdirectory. 194PATH=$(pwd)/..:$PATH 195GIT_EXEC_PATH=$(pwd)/.. 196export PATH GIT_EXEC_PATH 197 198# Similarly use ../compat/subprocess.py if our python does not 199# have subprocess.py on its own. 200PYTHON=`sed -e '1{ 201 s/^#!// 202 q 203}' ../git-merge-recursive`|| { 204 error "You haven't built things yet, have you?" 205} 206"$PYTHON"-c'import subprocess'2>/dev/null || { 207 PYTHONPATH=$(pwd)/../compat 208export PYTHONPATH 209} 210test -d ../templates/blt || { 211 error "You haven't built things yet, have you?" 212} 213 214# Test repository 215test=trash 216rm-fr"$test" 217test_create_repo $test 218cd"$test"