changeset 44501:9183b7dcfa8d

run-tests: add option for running with and without Rust extensions This provide a simple and clear way to run the test with or without rust.
author Raphaël Gomès <rgomes@octobus.net>
date Fri, 06 Mar 2020 11:16:15 +0100
parents 0d9ad84a28d9
children b3991b72d9f1
files tests/run-tests.py
diffstat 1 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Fri Mar 06 16:24:50 2020 +0100
+++ b/tests/run-tests.py	Fri Mar 06 11:16:15 2020 +0100
@@ -53,6 +53,7 @@
 import json
 import multiprocessing
 import os
+import platform
 import random
 import re
 import shutil
@@ -555,6 +556,16 @@
         help="use pure Python code instead of C extensions",
     )
     hgconf.add_argument(
+        "--rust",
+        action="store_true",
+        help="use Rust code alongside C extensions",
+    )
+    hgconf.add_argument(
+        "--no-rust",
+        action="store_true",
+        help="do not use Rust code even if compiled",
+    )
+    hgconf.add_argument(
         "--with-chg",
         metavar="CHG",
         help="use specified chg wrapper in place of hg",
@@ -637,6 +648,15 @@
     if 'java' in sys.platform or '__pypy__' in sys.modules:
         options.pure = True
 
+    if platform.python_implementation() != 'CPython' and options.rust:
+        parser.error('Rust extensions are only available with CPython')
+
+    if options.pure and options.rust:
+        parser.error('--rust cannot be used with --pure')
+
+    if options.rust and options.no_rust:
+        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')
@@ -3093,6 +3113,13 @@
         if self.options.pure:
             os.environ["HGTEST_RUN_TESTS_PURE"] = "--pure"
             os.environ["HGMODULEPOLICY"] = "py"
+        if self.options.rust:
+            os.environ["HGMODULEPOLICY"] = "rust+c"
+        if self.options.no_rust:
+            current_policy = os.environ.get("HGMODULEPOLICY", "")
+            if current_policy.startswith("rust+"):
+                os.environ["HGMODULEPOLICY"] = current_policy[len("rust+") :]
+            os.environ.pop("HGWITHRUSTEXT", None)
 
         if self.options.allow_slow_tests:
             os.environ["HGTEST_SLOW"] = "slow"
@@ -3426,6 +3453,10 @@
         setup_opts = b""
         if self.options.pure:
             setup_opts = b"--pure"
+        elif self.options.rust:
+            setup_opts = b"--rust"
+        elif self.options.no_rust:
+            setup_opts = b"--no-rust"
 
         # Run installer in hg root
         script = os.path.realpath(sys.argv[0])