sapling/tests/testutil

58 lines
1.9 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# This file holds logic that is used in many tests.
# It can be called in a test like this:
# $ . "$TESTDIR/testutil"
# Activate extensions
echo "[extensions]" >> $HGRCPATH
echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH
# Not needed in Mercurial 2.3+, as graphlog was integrated into core
echo 'graphlog=' >> $HGRCPATH
echo 'mq=' >> $HGRCPATH
tests: extract git command-line client and dulwich requirements into testutil One or both of these requirements were in almost every test in exactly the same way. Now, these checks are performed in every test that uses the testutil. This makes it easier for test authors to add these checks into new tests (just add a reference to the testutil, which you'd probably want anyway). We considered having each test declare their requirements (currently, either "git" or "dulwich"), but in this case, preferred the simplicity of having the check always performed (even if a particular test doesn't need one or the other). You can't perform any meaningful testing of Hg-Git without both of these dependencies properly configured. The main value to checking for them in the tests (rather than just letting the tests fail) is that it gives a meaningful error message to help people figure out how to fix their environment. In the case that either git or dulwich is missing, the information will be just as clearly conveyed regardless of whether its all the tests that are skipped, or just most of them. I didn't add dulwich to hghave (even though this is clearly the sort of thing that hghave is intended for) because hghave is currently pulled from Mercurial completely unchanged, and it's probably best to keep it that way. Tested by running the tests in three configurations: * No dulwich installed (ran 0, skipped 28, failed 0, output: Skipped *: missing feature: dulwich) * Bad git on path (ran 1, skipped 27, failed 0, output: Skipped *: missing feature: git command line client) * Working git and correct version of dulwich installed (ran 28, skipped 0, failed 0) Thanks to Felipe Contreras for the idea to extract this logic into a library.
2012-11-04 03:11:50 +04:00
# Standard checks for external dependencies
# We use the git command-line client and dulwich in pretty much all the tests.
# Thus, to avoid repetitively declaring that requirement in almost every test,
# we just call the checks in all tests that include this library.
python -c 'import dulwich' || {
echo "skipped: missing feature: dulwich" && exit 80
}
"$TESTDIR/hghave" git || exit 80
GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL
GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME
GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE
# Functions to commit and tag in Mercurial and Git in a predictable manner
count=10
fn_git_commit() {
GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000"
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
git commit "$@" >/dev/null || echo "git commit error"
count=`expr $count + 1`
}
fn_hg_commit() {
HGDATE="2007-01-01 00:00:$count +0000"
hg commit -d "$HGDATE" "$@" >/dev/null || echo "hg commit error"
count=`expr $count + 1`
}
fn_git_tag() {
GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000"
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
git tag "$@" >/dev/null || echo "git tag error"
count=`expr $count + 1`
}
fn_hg_tag() {
HGDATE="2007-01-01 00:00:$count +0000"
hg tag -d "$HGDATE" "$@" >/dev/null || echo "hg tag error"
count=`expr $count + 1`
}