X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/009a6a15262f045f09364569a0269ec0720e47a1..a79cd5d5eb048bdd9e78d096f7f2cbf923d85eca:/t/test-lib.sh diff --git a/t/test-lib.sh b/t/test-lib.sh index 87c143a..c1fb1b3 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -14,8 +14,8 @@ PAGER=cat TZ=UTC TERM=dumb export LANG LC_ALL PAGER TERM TZ -EDITOR=: -VISUAL=: +unset EDITOR +unset VISUAL unset GIT_EDITOR unset AUTHOR_DATE unset AUTHOR_EMAIL @@ -42,7 +42,6 @@ GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME -export EDITOR VISUAL GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u} # Protect ourselves from common misconfiguration to export @@ -285,6 +284,30 @@ test_expect_code () { echo >&3 "" } +# When running an StGit command that should exit with an error, use +# these instead of testing for any non-zero exit code with !. +exit_code () { + expected=$1 + shift + "$@" + test $? -eq $expected +} +general_error () { exit_code 1 "$@" ; } +command_error () { exit_code 2 "$@" ; } +conflict () { exit_code 3 "$@" ; } + +# Old-infrastructure commands don't exit with the proper value on +# conflicts. But we don't want half the tests to fail because of that, +# so use this instead of "conflict" for them. +conflict_old () { command_error "$@" ; } + +# Same thing, but for other commands that StGit where we just want to +# make sure that they fail instead of crashing. +must_fail () { + "$@" + test $? -gt 0 -a $? -le 129 +} + # test_cmp is a helper function to compare actual and expected output. # You can use it like: # @@ -307,13 +330,13 @@ test_cmp() { test_create_repo () { test "$#" = 1 || error "bug in the test script: not 1 parameter to test-create-repo" - owd=`pwd` + owd=$(pwd) repo="$1" mkdir "$repo" cd "$repo" || error "Cannot setup test environment" git init >/dev/null 2>&1 || error "cannot run git init" echo "empty start" | \ - git commit-tree `git write-tree` >.git/refs/heads/master 2>&4 || \ + git commit-tree $(git write-tree) >.git/refs/heads/master 2>&4 || \ error "cannot run git commit" mv .git/hooks .git/hooks-disabled cd "$owd"