[PATCH 1 of 2 v2] tests: more intelligently decide whether or not to use the system hg

Adam Simpkins simpkins at fb.com
Fri Jun 30 21:21:10 EDT 2017


# HG changeset patch
# User Adam Simpkins <simpkins at fb.com>
# Date 1498871646 25200
#      Fri Jun 30 18:14:06 2017 -0700
# Node ID bc44cbbfd13d88fbd2d10a7eed7c0ea26002c87c
# Parent  77e666f943a6c246d7fc970a8a36cd8b2023e03b
tests: more intelligently decide whether or not to use the system hg

Update the helpers-testrepo.sh code to try using the local hg script to
interact with the hg repository, and just use that if it works.  If that fails,
try using the system hg installation.  If the system hg command works and also
supports "hg files" use that.  Otherwise skip the test.

This also updates the test-hghave.t script to avoid sourcing
helpers-testrepo.sh, and to just directly use "$HGTEST_RESTOREENV".
This test just needs to restore the environment, and doesn't need to check if
it can interact with the local repository.

diff --git a/tests/helpers-testrepo.sh b/tests/helpers-testrepo.sh
--- a/tests/helpers-testrepo.sh
+++ b/tests/helpers-testrepo.sh
@@ -1,37 +1,58 @@
-# Invoke the system hg installation (rather than the local hg version being
-# tested).
+# This file defines syshg and syshgenv functions to use for calling
+# hg on the hg repository itself ($TESTDIR/..)
 #
-# We want to use the hg version being tested when interacting with the test
-# repository, and the system hg when interacting with the mercurial source code
-# repository.
+# Interacting with the hg repository may need to be done differently than
+# interacting with the temporary repositories created for testing purposes.
+# The hg repository will generally have been created by the user with the
+# system hg command from the user's $PATH, using the default system
+# configuration settings from /etc/mercurial.  The temporary test repositories
+# use our local hg script, with a controlled HGRCPATH that does not include the
+# standard system settings.  These two configurations may be incompatible.
 #
-# The mercurial source repository was typically orignally cloned with the
-# system mercurial installation, and may require extensions or settings from
-# the system installation.
-syshg () {
-    (
-        syshgenv
-        exec hg "$@"
-    )
-}
+# First try to use our local hg script.  If it can successfully interact with
+# the local repository we just use that.
+#
+# Otherwise try to use the system hg installation.  We ensure that it is at
+# least new enough to include the "hg files" command, since many of the check
+# tests rely on this command.
+#
+# If neither of these work, we exit with status 80 to skip the test.
 
-# Revert the environment so that running "hg" runs the system hg
-# rather than the test hg installation.
-syshgenv () {
+realsyshgenv () {
     . "$HGTEST_RESTOREENV"
     HGPLAIN=1
     export HGPLAIN
 }
 
-# Most test-check-* sourcing this file run "hg files", which is not available
-# in ancient versions of hg. So we double check if "syshg files" works and
-# fallback to hg bundled in the repo.
-syshg files -h >/dev/null 2>/dev/null
-if [ $? -ne 0 ]; then
-    syshg() {
+realsyshg () {
+    (
+        realsyshgenv
+        exec hg "$@"
+    )
+}
+
+if hg --cwd "$TESTDIR/.." log -r. -Ttest >/dev/null 2>/dev/null; then
+    # If our local hg command works with the test HGRCPATH settings,
+    # just use it.
+    syshgenv () {
+        :
+    }
+    syshg () {
         hg "$@"
     }
-    syshgenv() {
-        :
+elif realsyshg --cwd "$TESTDIR/.." log -r. -Ttest >/dev/null 2>/dev/null && \
+     realsyshg files -h >/dev/null 2>/dev/null; then
+    # Otherwise, if the local hg command does not work but hg from $PATH works
+    # with an unmodified $HGRCPATH, use it.
+    syshgenv () {
+        realsyshgenv
     }
+    syshg () {
+        realsyshg "$@"
+    }
+else
+    # We couldn't find an hg installation capable of interacting with
+    # the $TESTDIR/.. repository.  Skip the test.
+    echo "unable to find hg capable of interacting with local repository"
+    exit 80
 fi
diff --git a/tests/test-hghave.t b/tests/test-hghave.t
--- a/tests/test-hghave.t
+++ b/tests/test-hghave.t
@@ -1,5 +1,3 @@
-  $ . "$TESTDIR/helpers-testrepo.sh"
-
 Testing that hghave does not crash when checking features
 
   $ hghave --test-features 2>/dev/null
@@ -21,7 +19,7 @@
   >   foo
   > EOF
   $ ( \
-  > syshgenv; \
+  > . "$HGTEST_RESTOREENV"; \
   > $TESTDIR/run-tests.py $HGTEST_RUN_TESTS_PURE test-hghaveaddon.t \
   > )
   .


More information about the Mercurial-devel mailing list