D11035: run-test: adjust the drive letter to upper case for TESTDIR

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Fri Jul 9 11:48:54 UTC 2021


marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  There is an inconsistency between running:
  
  A) run-tests.py tests/test-foo.t
  B) run-tests.py
  
  In the (A) case TESTDIR starts with `c:` while in the (B) case it starts with
  `C:`. After trying to find out why, I am now blindly adjusting the drive letter
  to upper case. This makes `tests/test-run-tests.t` pass on windows.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D11035

AFFECTED FILES
  tests/run-tests.py

CHANGE DETAILS

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -326,6 +326,8 @@
     return p
 
 
+WINDOWS = os.name == r'nt'
+
 if sys.executable:
     sysexecutable = sys.executable
 elif os.environ.get('PYTHONEXECUTABLE'):
@@ -351,6 +353,24 @@
 defaults = default_defaults.copy()
 
 
+LOWER_DRIVE_RE_BYTES = re.compile(b'^[a-z]:')
+LOWER_DRIVE_RE_STR = re.compile(b'^[a-z]:')
+
+
+# run-test something put either "c:" or "C:" depending of how the test file
+# is specified. This is annoying for testing run-tests.py. After chassing
+# the rabbit for a while, I am just doing this stupid hack.
+def adjust_drive(path):
+    if WINDOWS:
+        if isinstance(path, bytes):
+            has_drive = LOWER_DRIVE_RE_BYTES.match(path)
+        else:
+            has_drive = LOWER_DRIVE_RE_STR.match(path)
+        if has_drive:
+            path = path[0:1].upper() + path[1:]
+    return path
+
+
 def canonpath(path):
     return os.path.realpath(os.path.expanduser(path))
 
@@ -3057,12 +3077,12 @@
 
     def _run(self, testdescs):
         testdir = getcwdb()
-        self._testdir = osenvironb[b'TESTDIR'] = getcwdb()
         # assume all tests in same folder for now
         if testdescs:
             pathname = os.path.dirname(testdescs[0]['path'])
             if pathname:
                 testdir = os.path.join(testdir, pathname)
+        testdir = adjust_drive(testdir)
         self._testdir = osenvironb[b'TESTDIR'] = testdir
         if self.options.outputdir:
             self._outputdir = canonpath(_sys2bytes(self.options.outputdir))



To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel


More information about the Mercurial-devel mailing list