tests: use the system hg for examining the local repository
authorAdam Simpkins <simpkins@fb.com>
Tue, 27 Jun 2017 17:24:31 -0700
changeset 33116 6c113a7dec52
parent 33115 fa9a90d5ad89
child 33117 6ef5f0c95d64
tests: use the system hg for examining the local repository Most test scripts use "hg" to interact with a temporary test repository. However a few tests also want to run hg commands to interact with the local repository containing the mercurial source code. Notably, many of the test-check-* tests want to check local files and commit messages. These tests were previously using the version of hg being tested to query the source repository. However, this will fail if the source repository requires extensions or other settings not supported by the version of mercurial being tested. The source repository was typically initially cloned using the system hg installation, so we should use the system hg installation to query it. There was already a helpers-testrepo.sh script designed to help cope with different requirements for the source repository versus the test repositories. However, it only handled the evolve extension. This new behavior works with any extensions that are different between the system installation and the test installation.
tests/helpers-testrepo.sh
tests/test-check-code.t
tests/test-check-commit.t
tests/test-check-config.t
tests/test-check-execute.t
tests/test-check-help.t
tests/test-check-module-imports.t
tests/test-check-py3-compat.t
tests/test-check-pyflakes.t
tests/test-check-shbang.t
tests/test-contrib-perf.t
tests/test-debian-packages.t
tests/test-docker-packaging.t
tests/test-hghave.t
tests/test-imports-checker.t
tests/test-install.t
tests/test-mac-packages.t
--- a/tests/helpers-testrepo.sh	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/helpers-testrepo.sh	Tue Jun 27 17:24:31 2017 -0700
@@ -1,19 +1,27 @@
-# The test-repo is a live hg repository which may have evolution
-# markers created, e.g. when a ~/.hgrc enabled evolution.
+# Invoke the system hg installation (rather than the local hg version being
+# tested).
 #
-# Tests are run using a custom HGRCPATH, which do not
-# enable evolution markers by default.
+# 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.
 #
-# If test-repo includes evolution markers, and we do not
-# enable evolution markers, hg will occasionally complain
-# when it notices them, which disrupts tests resulting in
-# sporadic failures.
-#
-# Since we aren't performing any write operations on the
-# test-repo, there's no harm in telling hg that we support
-# evolution markers, which is what the following lines
-# for the hgrc file do:
-cat >> $HGRCPATH << EOF
-[experimental]
-evolution=createmarkers
-EOF
+# 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 "$@"
+    )
+}
+
+# Revert the environment so that running "hg" runs the system hg
+# rather than the test hg installation.
+syshgenv () {
+    PATH="$ORIG_PATH"
+    PYTHONPATH="$ORIG_PYTHONPATH"
+    JYTHONPATH="$ORIG_JYTHONPATH"
+    unset HGRCPATH
+    HGPLAIN=1
+    export HGPLAIN
+}
--- a/tests/test-check-code.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-check-code.t	Tue Jun 27 17:24:31 2017 -0700
@@ -7,7 +7,7 @@
 New errors are not allowed. Warnings are strongly discouraged.
 (The writing "no-che?k-code" is for not skipping this file when checking.)
 
-  $ hg locate -X contrib/python-zstandard -X hgext/fsmonitor/pywatchman |
+  $ syshg locate -X contrib/python-zstandard -X hgext/fsmonitor/pywatchman |
   > sed 's-\\-/-g' | "$check_code" --warnings --per-file=0 - || false
   Skipping i18n/polib.py it has no-che?k-code (glob)
   Skipping mercurial/httpclient/__init__.py it has no-che?k-code (glob)
@@ -33,7 +33,7 @@
 
 Prevent adding new files in the root directory accidentally.
 
-  $ hg files 'glob:*'
+  $ syshg files 'glob:*'
   .editorconfig
   .hgignore
   .hgsigs
--- a/tests/test-check-commit.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-check-commit.t	Tue Jun 27 17:24:31 2017 -0700
@@ -8,8 +8,8 @@
 
   $ cd $TESTDIR/..
 
-  $ for node in `hg log --rev 'not public() and ::. and not desc("# no-check-commit")' --template '{node|short}\n'`; do
-  >    hg export --git $node | contrib/check-commit > ${TESTTMP}/check-commit.out
+  $ for node in `syshg log --rev 'not public() and ::. and not desc("# no-check-commit")' --template '{node|short}\n'`; do
+  >    syshg export --git $node | contrib/check-commit > ${TESTTMP}/check-commit.out
   >    if [ $? -ne 0 ]; then
   >        echo "Revision $node does not comply with rules"
   >        echo '------------------------------------------------------'
--- a/tests/test-check-config.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-check-config.t	Tue Jun 27 17:24:31 2017 -0700
@@ -31,7 +31,7 @@
 
 New errors are not allowed. Warnings are strongly discouraged.
 
-  $ hg files "set:(**.py or **.txt) - tests/**" | sed 's|\\|/|g' |
+  $ syshg files "set:(**.py or **.txt) - tests/**" | sed 's|\\|/|g' |
   >   $PYTHON contrib/check-config.py
               limit = ui.configwith(fraction, 'profiling', 'showmin', 0.05)
   
--- a/tests/test-check-execute.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-check-execute.t	Tue Jun 27 17:24:31 2017 -0700
@@ -5,20 +5,20 @@
 
 look for python scripts without the execute bit
 
-  $ hg files 'set:**.py and not exec() and grep(r"^#!.*?python")'
+  $ syshg files 'set:**.py and not exec() and grep(r"^#!.*?python")'
   [1]
 
 look for python scripts with execute bit but not shebang
 
-  $ hg files 'set:**.py and exec() and not grep(r"^#!.*?python")'
+  $ syshg files 'set:**.py and exec() and not grep(r"^#!.*?python")'
   [1]
 
 look for shell scripts with execute bit but not shebang
 
-  $ hg files 'set:**.sh and exec() and not grep(r"^#!.*(ba)?sh")'
+  $ syshg files 'set:**.sh and exec() and not grep(r"^#!.*(ba)?sh")'
   [1]
 
 look for non scripts with no shebang
 
-  $ hg files 'set:exec() and not **.sh and not **.py and not grep(r"^#!")'
+  $ syshg files 'set:exec() and not **.sh and not **.py and not grep(r"^#!")'
   [1]
--- a/tests/test-check-help.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-check-help.t	Tue Jun 27 17:24:31 2017 -0700
@@ -23,6 +23,7 @@
 Check if ":hg:`help TOPIC`" is valid:
 (use "xargs -n1 -t" to see which help commands are executed)
 
-  $ hg files 'glob:{hgdemandimport,hgext,mercurial}/**/*.py' | sed 's|\\|/|g' \
+  $ syshg files 'glob:{hgdemandimport,hgext,mercurial}/**/*.py' \
+  > | sed 's|\\|/|g' \
   > | xargs $PYTHON "$TESTTMP/scanhelptopics.py" \
   > | xargs -n1 hg help > /dev/null
--- a/tests/test-check-module-imports.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-check-module-imports.t	Tue Jun 27 17:24:31 2017 -0700
@@ -14,7 +14,7 @@
 Known-bad files are excluded by -X as some of them would produce unstable
 outputs, which should be fixed later.
 
-  $ hg locate 'set:**.py or grep(r"^#!.*?python")' \
+  $ syshg locate 'set:**.py or grep(r"^#!.*?python")' \
   > 'tests/**.t' \
   > -X contrib/debugshell.py \
   > -X contrib/python-zstandard/ \
--- a/tests/test-check-py3-compat.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-check-py3-compat.t	Tue Jun 27 17:24:31 2017 -0700
@@ -3,7 +3,7 @@
   $ . "$TESTDIR/helpers-testrepo.sh"
   $ cd "$TESTDIR"/..
 
-  $ hg files 'set:(**.py)' | sed 's|\\|/|g' | xargs $PYTHON contrib/check-py3-compat.py
+  $ syshg files 'set:(**.py)' | sed 's|\\|/|g' | xargs $PYTHON contrib/check-py3-compat.py
   contrib/python-zstandard/setup.py not using absolute_import
   contrib/python-zstandard/setup_zstd.py not using absolute_import
   contrib/python-zstandard/tests/common.py not using absolute_import
@@ -22,7 +22,7 @@
   tests/test-demandimport.py not using absolute_import
 
 #if py3exe
-  $ hg files 'set:(**.py) - grep(pygments)' -X hgext/fsmonitor/pywatchman \
+  $ syshg files 'set:(**.py) - grep(pygments)' -X hgext/fsmonitor/pywatchman \
   > | sed 's|\\|/|g' | xargs $PYTHON3 contrib/check-py3-compat.py \
   > | sed 's/[0-9][0-9]*)$/*)/'
   hgext/convert/transport.py: error importing: <*Error> No module named 'svn.client' (error at transport.py:*) (glob)
@@ -38,7 +38,7 @@
 #endif
 
 #if py3exe py3pygments
-  $ hg files 'set:(**.py) and grep(pygments)' | sed 's|\\|/|g' \
+  $ syshg files 'set:(**.py) and grep(pygments)' | sed 's|\\|/|g' \
   > | xargs $PYTHON3 contrib/check-py3-compat.py \
   > | sed 's/[0-9][0-9]*)$/*)/'
 #endif
--- a/tests/test-check-pyflakes.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-check-pyflakes.t	Tue Jun 27 17:24:31 2017 -0700
@@ -6,7 +6,8 @@
 run pyflakes on all tracked files ending in .py or without a file ending
 (skipping binary file random-seed)
 
-  $ hg locate 'set:**.py or grep("^#!.*python")' -X hgext/fsmonitor/pywatchman \
+  $ syshg locate 'set:**.py or grep("^#!.*python")' \
+  > -X hgext/fsmonitor/pywatchman \
   > -X mercurial/pycompat.py -X contrib/python-zstandard \
   > 2>/dev/null \
   > | xargs pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py"
--- a/tests/test-check-shbang.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-check-shbang.t	Tue Jun 27 17:24:31 2017 -0700
@@ -5,11 +5,11 @@
 
 look for python scripts that do not use /usr/bin/env
 
-  $ hg files 'set:grep(r"^#!.*?python") and not grep(r"^#!/usr/bi{1}n/env python") - **/*.t'
+  $ syshg files 'set:grep(r"^#!.*?python") and not grep(r"^#!/usr/bi{1}n/env python") - **/*.t'
   [1]
 
 In tests, enforce $PYTHON and *not* /usr/bin/env python or similar:
-  $ hg files 'set:grep(r"#!.*?python") and **/*.t' \
+  $ syshg files 'set:grep(r"#!.*?python") and **/*.t' \
   > -X tests/test-check-execute.t \
   > -X tests/test-check-module-imports.t \
   > -X tests/test-check-pyflakes.t \
@@ -21,5 +21,5 @@
 
 look for shell scripts that do not use /bin/sh
 
-  $ hg files 'set:grep(r"^#!.*/bi{1}n/sh") and not grep(r"^#!/bi{1}n/sh")'
+  $ syshg files 'set:grep(r"^#!.*/bi{1}n/sh") and not grep(r"^#!/bi{1}n/sh")'
   [1]
--- a/tests/test-contrib-perf.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-contrib-perf.t	Tue Jun 27 17:24:31 2017 -0700
@@ -170,6 +170,6 @@
 
   $ cd "$TESTDIR/.."
 
-  $ (hg files -r 1.2 glob:mercurial/*.c glob:mercurial/*.py;
-  >  hg files -r tip glob:mercurial/*.c glob:mercurial/*.py) |
+  $ (syshg files -r 1.2 glob:mercurial/*.c glob:mercurial/*.py;
+  >  syshg files -r tip glob:mercurial/*.c glob:mercurial/*.py) |
   > "$TESTDIR"/check-perf-code.py contrib/perf.py
--- a/tests/test-debian-packages.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-debian-packages.t	Tue Jun 27 17:24:31 2017 -0700
@@ -1,6 +1,7 @@
 #require test-repo slow debhelper
 
   $ . "$TESTDIR/helpers-testrepo.sh"
+  $ syshgenv
 
 Ensure debuild doesn't run the testsuite, as that could get silly.
   $ DEB_BUILD_OPTIONS=nocheck
--- a/tests/test-docker-packaging.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-docker-packaging.t	Tue Jun 27 17:24:31 2017 -0700
@@ -1,6 +1,7 @@
 #require test-repo slow docker
 
   $ . "$TESTDIR/helpers-testrepo.sh"
+  $ syshgenv
 
 Ensure debuild doesn't run the testsuite, as that could get silly.
   $ DEB_BUILD_OPTIONS=nocheck
--- a/tests/test-hghave.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-hghave.t	Tue Jun 27 17:24:31 2017 -0700
@@ -1,3 +1,5 @@
+  $ . "$TESTDIR/helpers-testrepo.sh"
+
 Testing that hghave does not crash when checking features
 
   $ hghave --test-features 2>/dev/null
@@ -18,7 +20,10 @@
   >   $ echo foo
   >   foo
   > EOF
-  $ run-tests.py $HGTEST_RUN_TESTS_PURE test-hghaveaddon.t
+  $ ( \
+  > syshgenv; \
+  > $TESTDIR/run-tests.py $HGTEST_RUN_TESTS_PURE test-hghaveaddon.t \
+  > )
   .
   # Ran 1 tests, 0 skipped, 0 failed.
 
--- a/tests/test-imports-checker.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-imports-checker.t	Tue Jun 27 17:24:31 2017 -0700
@@ -1,6 +1,7 @@
 #require test-repo
 
   $ . "$TESTDIR/helpers-testrepo.sh"
+  $ syshgenv
   $ import_checker="$TESTDIR"/../contrib/import-checker.py
 
 Run the doctests from the import checker, and make sure
--- a/tests/test-install.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-install.t	Tue Jun 27 17:24:31 2017 -0700
@@ -159,7 +159,7 @@
   >     print('  %s' % f)
   > EOF
 
-  $ $PYTHON wixxml.py help
+  $ (syshgenv; $PYTHON wixxml.py help )
   Not installed:
     help/common.txt
     help/hg-ssh.8.txt
@@ -168,7 +168,7 @@
     help/hgrc.5.txt
   Not tracked:
 
-  $ $PYTHON wixxml.py templates
+  $ ( syshgenv; $PYTHON wixxml.py templates )
   Not installed:
   Not tracked:
 
--- a/tests/test-mac-packages.t	Tue Jun 27 17:24:31 2017 -0700
+++ b/tests/test-mac-packages.t	Tue Jun 27 17:24:31 2017 -0700
@@ -1,6 +1,7 @@
 #require test-repo slow osx osxpackaging
 
   $ . "$TESTDIR/helpers-testrepo.sh"
+  $ syshgenv
 
   $ OUTPUTDIR="`pwd`"
   $ export OUTPUTDIR