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-h|--h|--he|--hel|--help) 54echo"$test_description" 55exit0;; 56-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) 57 verbose=t;shift;; 58*) 59break;; 60esac 61done 62 63iftest"$verbose"="t" 64then 65exec4>&2 3>&1 66else 67exec4>/dev/null 3>/dev/null 68fi 69 70test_failure=0 71test_count=0 72 73test_debug () { 74test"$debug"==""||eval"$1" 75} 76 77test_ok () { 78 test_count=$(expr "$test_count" + 1) 79 say "ok #$test_count: $@" 80} 81 82test_failure () { 83 test_count=$(expr "$test_count" + 1) 84 test_failure=$(expr "$test_failure" + 1); 85 say "NO #$test_count: $@" 86} 87 88test_expect_failure () { 89test"$#"==2|| 90 error "bug in the test script: not 2 parameters to test-expect-failure" 91 say >&3"expecting failure:$2" 92ifeval>&3 2>&4"$2" 93then 94 test_failure "$@" 95else 96 test_ok "$1" 97fi 98} 99 100test_expect_success () { 101test"$#"==2|| 102 error "bug in the test script: not 2 parameters to test-expect-success" 103 say >&3"expecting success:$2" 104ifeval>&3 2>&4"$2" 105then 106 test_ok "$1" 107else 108 test_failure "$@" 109fi 110} 111 112test_done () { 113case"$test_failure"in 1140) 115# We could: 116# cd .. && rm -fr trash 117# but that means we forbid any tests that use their own 118# subdirectory from calling test_done without coming back 119# to where they started from. 120# The Makefile provided will clean this test area so 121# we will leave things as they are. 122 123 say "passed all$test_counttest(s)" 124exit0;; 125 126*) 127 say "failed$test_failureamong$test_counttest(s)" 128exit1;; 129 130esac 131} 132 133# Test the binaries we have just built. The tests are kept in 134# t/ subdirectory and are run in trash subdirectory. 135PATH=$(pwd)/..:$PATH 136 137# Test repository 138test=trash 139rm-fr"$test" 140mkdir"$test" 141cd"$test" 142git-init-db2>/dev/null || error "cannot run git-init-db"