Commits

David Carr committed 675f19a

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.

  • Participants
  • Parent commits 935c4fb

Comments (0)

Files changed (27)

File tests/test-bookmark-workflow.t

 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

File tests/test-clone.t

 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

File tests/test-conflict-1.t

 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

File tests/test-conflict-2.t

 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

File tests/test-convergedmerge.t

 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

File tests/test-empty-working-tree.t

 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

File tests/test-encoding.t

 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

File tests/test-file-removal.t

 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

File tests/test-git-clone.t

 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

File tests/test-git-submodules.t

 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

File tests/test-git-tags.t

 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

File tests/test-git-workflow.t

 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

File tests/test-hg-author.t

 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

File tests/test-hg-branch.t

 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/"

File tests/test-hg-tags.t

 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

File tests/test-incoming.t

 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

File tests/test-keywords.t

 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

File tests/test-merge.t

 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

File tests/test-octopus.t

 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

File tests/test-outgoing.t

 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

File tests/test-pull-after-strip.t

 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
 
   $ 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

File tests/test-pull.t

 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

File tests/test-push-r.t

 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

File tests/test-push.t

 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

File tests/test-subrepos.t

 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

File tests/test-tree-decomposition.t

 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

File tests/testutil

 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