changeset 51919:ceaf92d6d380

tests: always access the mercurial repo through `helpers-testrepo.sh` In some contexts the mercurial repo needs to be accessed through system hg. That's what `helpers-testrepo.sh` enforces, but some tests incorrectly use the mercurial repo without going through that script. This patch fixes those tests.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Wed, 02 Oct 2024 14:51:56 +0100
parents 813226b3b4ca
children ef7d85089952
files tests/test-check-format.t tests/test-check-help.t tests/test-check-interfaces.py tests/test-doctest.py
diffstat 4 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/tests/test-check-format.t	Wed Oct 02 14:49:07 2024 +0100
+++ b/tests/test-check-format.t	Wed Oct 02 14:51:56 2024 +0100
@@ -6,6 +6,8 @@
   $ export USERPROFILE
 #endif
 
+  $ . "$TESTDIR/helpers-testrepo.sh"
+
   $ cd $RUNTESTDIR/..
-  $ black --check --diff `hg files 'set:(**.py + grep("^#!.*python")) - mercurial/thirdparty/**'`
+  $ black --check --diff `testrepohg files 'set:(**.py + grep("^#!.*python")) - mercurial/thirdparty/**'`
 
--- a/tests/test-check-help.t	Wed Oct 02 14:49:07 2024 +0100
+++ b/tests/test-check-help.t	Wed Oct 02 14:51:56 2024 +0100
@@ -19,12 +19,11 @@
   >     stdout.write(b'%s\n' % s)
   > EOF
 
-  $ cd "$TESTDIR"/..
-
 Check if ":hg:`help TOPIC`" is valid:
 (use "xargs -n1 -t" to see which help commands are executed)
 
+  $ cd "$TESTDIR"/..
   $ testrepohg files 'glob:{hgdemandimport,hgext,mercurial}/**/*.py' \
   > | sed 's|\\|/|g' \
   > | xargs "$PYTHON" "$TESTTMP/scanhelptopics.py" \
-  > | xargs -n1 hg help --config extensions.phabricator= > /dev/null
+  > | xargs -n1 hg --cwd "$TESTTMP" help --config extensions.phabricator= > /dev/null
--- a/tests/test-check-interfaces.py	Wed Oct 02 14:49:07 2024 +0100
+++ b/tests/test-check-interfaces.py	Wed Oct 02 14:51:56 2024 +0100
@@ -9,12 +9,6 @@
 import subprocess
 import sys
 
-# Only run if tests are run in a repo
-if subprocess.call(
-    [sys.executable, '%s/hghave' % os.environ['TESTDIR'], 'test-repo']
-):
-    sys.exit(80)
-
 from mercurial.interfaces import (
     dirstate as intdirstate,
     repository,
@@ -41,7 +35,6 @@
 )
 
 testdir = os.path.dirname(__file__)
-rootdir = pycompat.fsencode(os.path.normpath(os.path.join(testdir, '..')))
 
 sys.path[0:0] = [testdir]
 import simplestorerepo
@@ -117,6 +110,14 @@
         pass
 
 
+def init_test_repo():
+    testtmp_dir = os.path.normpath(os.environ['TESTTMP'])
+    test_repo_dir = os.path.join(testtmp_dir, "test-repo")
+    subprocess.run(["hg", "init", test_repo_dir])
+    subprocess.run(["hg", "--cwd", test_repo_dir, "debugbuilddag", "+3<3+1"])
+    return test_repo_dir
+
+
 def main():
     ui = uimod.ui()
     # Needed so we can open a local repo with obsstore without a warning.
@@ -168,7 +169,8 @@
     ziverify.verifyClass(
         repository.ilocalrepositoryfilestorage, localrepo.revlogfilestorage
     )
-    repo = localrepo.makelocalrepository(ui, rootdir)
+    test_repo_dir = init_test_repo()
+    repo = localrepo.makelocalrepository(ui, pycompat.fsencode(test_repo_dir))
     checkzobject(repo)
 
     ziverify.verifyClass(
--- a/tests/test-doctest.py	Wed Oct 02 14:49:07 2024 +0100
+++ b/tests/test-doctest.py	Wed Oct 02 14:51:56 2024 +0100
@@ -72,7 +72,8 @@
     sys.exit(0)
 
 files = subprocess.check_output(
-    "hg files --print0 \"%s\"" % fileset,
+    "HGRCPATH=/dev/null . helpers-testrepo.sh; testrepohg files --print0 \"%s\""
+    % fileset,
     shell=True,
     cwd=cwd,
 ).split(b'\0')