changeset 46668:fb2368598281

tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py` They are mostly equivalent to the corresponding `chg` options. For now, many tests are still failing in this configuration. It is *not* run on CI. Differential Revision: https://phab.mercurial-scm.org/D10095
author Simon Sapin <simon.sapin@octobus.net>
date Tue, 02 Mar 2021 21:31:12 +0100
parents 93e9f448273c
children e8cd519a0a34
files tests/run-tests.py
diffstat 1 files changed, 57 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Mon Mar 01 20:36:06 2021 +0100
+++ b/tests/run-tests.py	Tue Mar 02 21:31:12 2021 +0100
@@ -540,6 +540,11 @@
         action="store_true",
         help="show chg debug logs",
     )
+    hgconf.add_argument(
+        "--rhg",
+        action="store_true",
+        help="install and use rhg Rust implementation in place of hg",
+    )
     hgconf.add_argument("--compiler", help="compiler to build with")
     hgconf.add_argument(
         '--extra-config-opt',
@@ -552,6 +557,7 @@
         "--local",
         action="store_true",
         help="shortcut for --with-hg=<testdir>/../hg, "
+        "--with-rhg=<testdir>/../rust/target/release/rhg if --rhg is set, "
         "and --with-chg=<testdir>/../contrib/chg/chg if --chg is set",
     )
     hgconf.add_argument(
@@ -580,6 +586,11 @@
         help="use specified chg wrapper in place of hg",
     )
     hgconf.add_argument(
+        "--with-rhg",
+        metavar="RHG",
+        help="use specified rhg Rust implementation in place of hg",
+    )
+    hgconf.add_argument(
         "--with-hg",
         metavar="HG",
         help="test using specified hg script rather than a "
@@ -667,13 +678,17 @@
         parser.error('--rust cannot be used with --no-rust')
 
     if options.local:
-        if options.with_hg or options.with_chg:
-            parser.error('--local cannot be used with --with-hg or --with-chg')
+        if options.with_hg or options.with_rhg or options.with_chg:
+            parser.error(
+                '--local cannot be used with --with-hg or --with-rhg or --with-chg'
+            )
         testdir = os.path.dirname(_sys2bytes(canonpath(sys.argv[0])))
         reporootdir = os.path.dirname(testdir)
         pathandattrs = [(b'hg', 'with_hg')]
         if options.chg:
             pathandattrs.append((b'contrib/chg/chg', 'with_chg'))
+        if options.rhg:
+            pathandattrs.append((b'rust/target/release/rhg', 'with_rhg'))
         for relpath, attr in pathandattrs:
             binpath = os.path.join(reporootdir, relpath)
             if os.name != 'nt' and not os.access(binpath, os.X_OK):
@@ -696,6 +711,8 @@
 
     if (options.chg or options.with_chg) and os.name == 'nt':
         parser.error('chg does not work on %s' % os.name)
+    if (options.rhg or options.with_rhg) and os.name == 'nt':
+        parser.error('rhg does not work on %s' % os.name)
     if options.with_chg:
         options.chg = False  # no installation to temporary location
         options.with_chg = canonpath(_sys2bytes(options.with_chg))
@@ -704,12 +721,28 @@
             and os.access(options.with_chg, os.X_OK)
         ):
             parser.error('--with-chg must specify a chg executable')
+    if options.with_rhg:
+        options.rhg = False  # no installation to temporary location
+        options.with_rhg = canonpath(_sys2bytes(options.with_rhg))
+        if not (
+            os.path.isfile(options.with_rhg)
+            and os.access(options.with_rhg, os.X_OK)
+        ):
+            parser.error('--with-rhg must specify a rhg executable')
     if options.chg and options.with_hg:
         # chg shares installation location with hg
         parser.error(
             '--chg does not work when --with-hg is specified '
             '(use --with-chg instead)'
         )
+    if options.rhg and options.with_hg:
+        # rhg shares installation location with hg
+        parser.error(
+            '--rhg does not work when --with-hg is specified '
+            '(use --with-rhg instead)'
+        )
+    if options.rhg and options.chg:
+        parser.error('--rhg and --chg do not work together')
 
     if options.color == 'always' and not pygmentspresent:
         sys.stderr.write(
@@ -934,6 +967,7 @@
         slowtimeout=None,
         usechg=False,
         chgdebug=False,
+        rhg_fallback_exe=None,
         useipv6=False,
     ):
         """Create a test from parameters.
@@ -991,6 +1025,7 @@
         self._hgcommand = hgcommand or b'hg'
         self._usechg = usechg
         self._chgdebug = chgdebug
+        self._rhg_fallback_exe = rhg_fallback_exe
         self._useipv6 = useipv6
 
         self._aborted = False
@@ -1473,6 +1508,12 @@
             hgrc.write(b'ipv6 = %r\n' % self._useipv6)
             hgrc.write(b'server-header = testing stub value\n')
 
+            if self._rhg_fallback_exe:
+                hgrc.write(b'[rhg]\n')
+                hgrc.write(
+                    b'fallback-executable = %s\n' % self._rhg_fallback_exe
+                )
+
             for opt in self._extraconfigopts:
                 section, key = _sys2bytes(opt).split(b'.', 1)
                 assert b'=' in key, (
@@ -2958,6 +2999,7 @@
         self._coveragefile = None
         self._createdfiles = []
         self._hgcommand = None
+        self._rhg_fallback_exe = None
         self._hgpath = None
         self._portoffset = 0
         self._ports = {}
@@ -3098,6 +3140,16 @@
             chgbindir = os.path.dirname(os.path.realpath(self.options.with_chg))
             self._hgcommand = os.path.basename(self.options.with_chg)
 
+        # set fallback executable path, then replace "hg" command by "rhg"
+        rhgbindir = self._bindir
+        if self.options.rhg or self.options.with_rhg:
+            self._rhg_fallback_exe = os.path.join(self._bindir, self._hgcommand)
+        if self.options.rhg:
+            self._hgcommand = b'rhg'
+        elif self.options.with_rhg:
+            rhgbindir = os.path.dirname(os.path.realpath(self.options.with_rhg))
+            self._hgcommand = os.path.basename(self.options.with_rhg)
+
         osenvironb[b"BINDIR"] = self._bindir
         osenvironb[b"PYTHON"] = PYTHON
 
@@ -3116,6 +3168,8 @@
             path.insert(2, realdir)
         if chgbindir != self._bindir:
             path.insert(1, chgbindir)
+        if rhgbindir != self._bindir:
+            path.insert(1, rhgbindir)
         if self._testdir != runtestdir:
             path = [self._testdir] + path
         if self._tmpbindir != self._bindir:
@@ -3423,6 +3477,7 @@
             hgcommand=self._hgcommand,
             usechg=bool(self.options.with_chg or self.options.chg),
             chgdebug=self.options.chg_debug,
+            rhg_fallback_exe=self._rhg_fallback_exe,
             useipv6=useipv6,
             **kwds
         )