# HG changeset patch # User David M. Carr <david@carrclan.us> # Date 1351984310 14400 # Sat Nov 03 19:11:50 2012 -0400 # Node ID 675f19af79cafd4a95677bf73c4d2663f5cc8022 # Parent 935c4fb1bbfcce3f3c235b1918c55b1bc1f054b9 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. diff --git a/tests/test-bookmark-workflow.t b/tests/test-bookmark-workflow.t --- 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 diff --git a/tests/test-clone.t b/tests/test-clone.t --- 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 diff --git a/tests/test-conflict-1.t b/tests/test-conflict-1.t --- 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 diff --git a/tests/test-conflict-2.t b/tests/test-conflict-2.t --- 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 diff --git a/tests/test-convergedmerge.t b/tests/test-convergedmerge.t --- 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 diff --git a/tests/test-empty-working-tree.t b/tests/test-empty-working-tree.t --- 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 diff --git a/tests/test-encoding.t b/tests/test-encoding.t --- 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 diff --git a/tests/test-file-removal.t b/tests/test-file-removal.t --- 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 diff --git a/tests/test-git-clone.t b/tests/test-git-clone.t --- 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 diff --git a/tests/test-git-submodules.t b/tests/test-git-submodules.t --- 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 diff --git a/tests/test-git-tags.t b/tests/test-git-tags.t --- 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 diff --git a/tests/test-git-workflow.t b/tests/test-git-workflow.t --- 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 diff --git a/tests/test-hg-author.t b/tests/test-hg-author.t --- 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 diff --git a/tests/test-hg-branch.t b/tests/test-hg-branch.t --- 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/" diff --git a/tests/test-hg-tags.t b/tests/test-hg-tags.t --- 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 diff --git a/tests/test-incoming.t b/tests/test-incoming.t --- 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 diff --git a/tests/test-keywords.t b/tests/test-keywords.t --- 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 diff --git a/tests/test-merge.t b/tests/test-merge.t --- 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 diff --git a/tests/test-octopus.t b/tests/test-octopus.t --- 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 diff --git a/tests/test-outgoing.t b/tests/test-outgoing.t --- 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 diff --git a/tests/test-pull-after-strip.t b/tests/test-pull-after-strip.t --- 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 diff --git a/tests/test-pull.t b/tests/test-pull.t --- 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 diff --git a/tests/test-push-r.t b/tests/test-push-r.t --- 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 diff --git a/tests/test-push.t b/tests/test-push.t --- 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 diff --git a/tests/test-subrepos.t b/tests/test-subrepos.t --- 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 diff --git a/tests/test-tree-decomposition.t b/tests/test-tree-decomposition.t --- 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 diff --git a/tests/testutil b/tests/testutil --- 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