1#!/bin/sh 2# 3# Copyright (c) 2005 Junio C Hamano 4# 5 6# For repeatability, reset the environment to known value. 7LANG=C 8TZ=UTC 9export LANG TZ 10unset AUTHOR_DATE 11unset AUTHOR_EMAIL 12unset AUTHOR_NAME 13unset COMMIT_AUTHOR_EMAIL 14unset COMMIT_AUTHOR_NAME 15unset GIT_ALTERNATE_OBJECT_DIRECTORIES 16unset GIT_AUTHOR_DATE 17unset GIT_AUTHOR_EMAIL 18unset GIT_AUTHOR_NAME 19unset GIT_COMMITTER_EMAIL 20unset GIT_COMMITTER_NAME 21unset GIT_DIFF_OPTS 22unset GIT_DIR 23unset GIT_EXTERNAL_DIFF 24unset GIT_INDEX_FILE 25unset GIT_OBJECT_DIRECTORY 26unset SHA1_FILE_DIRECTORIES 27unset SHA1_FILE_DIRECTORY 28 29# Each test should start with something like this, after copyright notices: 30# 31# test_description='Description of this test... 32# This test checks if command xyzzy does the right thing... 33# ' 34# . ./test-lib.sh 35 36error () { 37echo"* error: $*" 38exit1 39} 40 41say () { 42echo"* $*" 43} 44 45test"${test_description}"!=""|| 46error "Test script did not set test_description." 47 48whiletest"$#"-ne0 49do 50case"$1"in 51-d|--d|--de|--deb|--debu|--debug) 52 debug=t;shift;; 53-i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) 54 immediate=t;shift;; 55-h|--h|--he|--hel|--help) 56echo"$test_description" 57exit0;; 58-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) 59 verbose=t;shift;; 60*) 61break;; 62esac 63done 64 65iftest"$verbose"="t" 66then 67exec4>&2 3>&1 68else 69exec4>/dev/null 3>/dev/null 70fi 71 72test_failure=0 73test_count=0 74 75 76# You are not expected to call test_ok_ and test_failure_ directly, use 77# the text_expect_* functions instead. 78 79test_ok_ () { 80 test_count=$(expr "$test_count" + 1) 81 say " ok$test_count: $@" 82} 83 84test_failure_ () { 85 test_count=$(expr "$test_count" + 1) 86 test_failure=$(expr "$test_failure" + 1); 87 say "FAIL$test_count: $@" 88test"$immediate"==""||exit1 89} 90 91 92test_debug () { 93test"$debug"==""||eval"$1" 94} 95 96test_expect_failure () { 97test"$#"==2|| 98 error "bug in the test script: not 2 parameters to test-expect-failure" 99 say >&3"expecting failure:$2" 100ifeval>&3 2>&4"$2" 101then 102 test_failure_ "$@" 103else 104 test_ok_ "$1" 105fi 106} 107 108test_expect_success () { 109test"$#"==2|| 110 error "bug in the test script: not 2 parameters to test-expect-success" 111 say >&3"expecting success:$2" 112ifeval>&3 2>&4"$2" 113then 114 test_ok_ "$1" 115else 116 test_failure_ "$@" 117fi 118} 119 120test_done () { 121case"$test_failure"in 1220) 123# We could: 124# cd .. && rm -fr trash 125# but that means we forbid any tests that use their own 126# subdirectory from calling test_done without coming back 127# to where they started from. 128# The Makefile provided will clean this test area so 129# we will leave things as they are. 130 131 say "passed all$test_counttest(s)" 132exit0;; 133 134*) 135 say "failed$test_failureamong$test_counttest(s)" 136exit1;; 137 138esac 139} 140 141# Test the binaries we have just built. The tests are kept in 142# t/ subdirectory and are run in trash subdirectory. 143PATH=$(pwd)/..:$PATH 144 145# Test repository 146test=trash 147rm-fr"$test" 148mkdir"$test" 149cd"$test" 150git-init-db2>/dev/null || error "cannot run git-init-db"