Mercurial > hg > hg-git
changeset 579:675f19af79ca
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.
author | David M. Carr <david@carrclan.us> |
---|---|
date | Sat, 03 Nov 2012 19:11:50 -0400 |
parents | 935c4fb1bbfc |
children | 6cc99298b69e |
files | tests/test-bookmark-workflow.t tests/test-clone.t tests/test-conflict-1.t tests/test-conflict-2.t tests/test-convergedmerge.t tests/test-empty-working-tree.t tests/test-encoding.t tests/test-file-removal.t tests/test-git-clone.t tests/test-git-submodules.t tests/test-git-tags.t tests/test-git-workflow.t tests/test-hg-author.t tests/test-hg-branch.t tests/test-hg-tags.t tests/test-incoming.t tests/test-keywords.t tests/test-merge.t tests/test-octopus.t tests/test-outgoing.t tests/test-pull-after-strip.t tests/test-pull.t tests/test-push-r.t tests/test-push.t tests/test-subrepos.t tests/test-tree-decomposition.t tests/testutil |
diffstat | 27 files changed, 9 insertions(+), 153 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/test-bookmark-workflow.t +++ b/tests/test-bookmark-workflow.t @@ -12,12 +12,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -Bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - Skip if Mercurial < 2.1; workflow was different before that $ python -c 'from mercurial import util ; assert \ > util.version() != "unknown" and util.version() >= "2.1"' || exit 80
--- a/tests/test-clone.t +++ b/tests/test-clone.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-conflict-1.t +++ b/tests/test-conflict-1.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ hg init hgrepo1 $ cd hgrepo1 $ echo A > afile
--- a/tests/test-conflict-2.t +++ b/tests/test-conflict-2.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ hg init hgrepo1 $ cd hgrepo1 $ echo A > afile
--- a/tests/test-convergedmerge.t +++ b/tests/test-convergedmerge.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ hg init hgrepo1 $ cd hgrepo1 $ echo A > afile
--- a/tests/test-empty-working-tree.t +++ b/tests/test-empty-working-tree.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-encoding.t +++ b/tests/test-encoding.t @@ -3,12 +3,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || 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
--- a/tests/test-file-removal.t +++ b/tests/test-file-removal.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-git-clone.t +++ b/tests/test-git-clone.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-git-submodules.t +++ b/tests/test-git-submodules.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo1 Initialized empty Git repository in $TESTTMP/gitrepo1/.git/ $ cd gitrepo1
--- a/tests/test-git-tags.t +++ b/tests/test-git-tags.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-git-workflow.t +++ b/tests/test-git-workflow.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ hg init hgrepo $ cd hgrepo $ echo alpha > alpha
--- a/tests/test-hg-author.t +++ b/tests/test-hg-author.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-hg-branch.t +++ b/tests/test-hg-branch.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - TODO stop using this when we're 1.5 only $ filterhash="sed s/71414c4e3c6f/a31e374801c9/;s/698615204564/d93a72262a83/" $ filterhash="$filterhash;s/d93a72262a83/05aed681ccb3/"
--- a/tests/test-hg-tags.t +++ b/tests/test-hg-tags.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-incoming.t +++ b/tests/test-incoming.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - This test only works on hg 1.7 and later $ python -c 'from mercurial import util ; assert \ > util.version() != "unknown" and util.version() > "1.7"' || exit 80
--- a/tests/test-keywords.t +++ b/tests/test-keywords.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-merge.t +++ b/tests/test-merge.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-octopus.t +++ b/tests/test-octopus.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-outgoing.t +++ b/tests/test-outgoing.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-pull-after-strip.t +++ b/tests/test-pull-after-strip.t @@ -1,9 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - this test is busted on hg < 1.5. I'm not sure how to fix it. $ cat > tmp.py <<EOF > import sys @@ -15,9 +12,6 @@ $ hg version | grep version | sed 's/.*(version //' | python tmp.py || exit 80 -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-pull.t +++ b/tests/test-pull.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - set up a git repo with some commits, branches and a tag $ git init -q gitrepo $ cd gitrepo
--- a/tests/test-push-r.t +++ b/tests/test-push-r.t @@ -1,9 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ hg init test $ cd test $ cat >>afile <<EOF
--- a/tests/test-push.t +++ b/tests/test-push.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/test-subrepos.t +++ b/tests/test-subrepos.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitsubrepo Initialized empty Git repository in $TESTTMP/gitsubrepo/.git/ $ cd gitsubrepo
--- a/tests/test-tree-decomposition.t +++ b/tests/test-tree-decomposition.t @@ -1,12 +1,6 @@ Load commonly used test logic $ . "$TESTDIR/testutil" -bail if the user does not have git command-line client - $ "$TESTDIR/hghave" git || exit 80 - -bail if the user does not have dulwich - $ python -c 'import dulwich, dulwich.repo' || exit 80 - $ git init gitrepo Initialized empty Git repository in $TESTTMP/gitrepo/.git/ $ cd gitrepo
--- a/tests/testutil +++ b/tests/testutil @@ -11,6 +11,15 @@ echo 'graphlog=' >> $HGRCPATH echo 'mq=' >> $HGRCPATH +# 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