run-tests: enforce the drive letter from `getcwd` to upper case
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 10 Jul 2021 01:15:03 +0200
changeset 47619 f0fbe8f4faa6
parent 47618 27ff81547d35
child 47620 724066f23e2d
run-tests: enforce the drive letter from `getcwd` to upper case For some reason os.getcwd() can return either `c:` or `C:` depending of which binary you used on Windows. We normalize this to `C:` and the like. This fix `test-run-tests.t` on windows as the drive letter in "$TESTTMP" was "wrongly" set to 'c:/' if the test path wasn't explicitly specified. Differential Revision: https://phab.mercurial-scm.org/D11035
tests/run-tests.py
--- a/tests/run-tests.py	Mon Jul 12 03:30:04 2021 +0200
+++ b/tests/run-tests.py	Sat Jul 10 01:15:03 2021 +0200
@@ -230,6 +230,18 @@
     osenvironb = os.environ
     getcwdb = os.getcwd
 
+if WINDOWS:
+    _getcwdb = getcwdb
+
+    def getcwdb():
+        cwd = _getcwdb()
+        if re.match(b'^[a-z]:', cwd):
+            # os.getcwd() is inconsistent on the capitalization of the drive
+            # letter, so adjust it. see https://bugs.python.org/issue40368
+            cwd = cwd[0:1].upper() + cwd[1:]
+        return cwd
+
+
 # For Windows support
 wifexited = getattr(os, "WIFEXITED", lambda x: False)
 
@@ -3078,7 +3090,6 @@
 
     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'])