Patchwork [1,of,2,v3] tests: more intelligently decide whether or not to use the system hg

login
register
mail settings
Submitter Adam Simpkins
Date July 1, 2017, 2:36 a.m.
Message ID <70f329188bf5fbe1f000.1498876576@devbig125.prn1.facebook.com>
Download mbox | patch
Permalink /patch/21858/
State Rejected
Headers show

Comments

Adam Simpkins - July 1, 2017, 2:36 a.m.
# HG changeset patch
# User Adam Simpkins <simpkins@fb.com>
# Date 1498876158 25200
#      Fri Jun 30 19:29:18 2017 -0700
# Node ID 70f329188bf5fbe1f0007537fb8f90b15394dfe2
# Parent  5d29c55414b3594a572ea0de94b09b55de1c26b8
tests: more intelligently decide whether or not to use the system hg

Update the helpers-testrepo.sh code to first try using the hg command from the
user's $PATH, and confirm that it supports "hg files".  If that does not work,
we try the local hg script.  If that also fails we 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.

Patch

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).
-#
-# 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.
+# This file defines syshg and syshgenv functions to use for calling
+# hg on the hg repository itself ($TESTDIR/..)
 #
-# 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 "$@"
-    )
-}
+# 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.
+#
+# We first 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 the system hg command does not work for some reason we try falling back
+# to our local hg script.  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 realsyshg --cwd "$TESTDIR/.." log -r. -Ttest >/dev/null 2>/dev/null && \
+    realsyshg files -h >/dev/null 2>/dev/null; then
+    # If the hg command from the user's PATH works and supports "hg files",
+    # use it with the user's original environment settings.
+    syshgenv () {
+        realsyshgenv
+    }
+    syshg () {
+        realsyshg "$@"
+    }
+elif hg --cwd "$TESTDIR/.." log -r. -Ttest >/dev/null 2>/dev/null; then
+    # If the system hg command does not work for some reason, or is so old
+    # that it does not support "hg files", fall back to using the local hg
+    # command.
+    syshgenv () {
+        :
+    }
+    syshg () {
         hg "$@"
     }
-    syshgenv() {
-        :
-    }
+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 \
   > )
   .