From patchwork Fri Jul 9 11:48:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D11035: run-test: adjust the drive letter to upper case for TESTDIR From: phabricator X-Patchwork-Id: 49349 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Fri, 9 Jul 2021 11:48:54 +0000 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 To: marmoute, #hg-reviewers Cc: mercurial-patches, mercurial-devel 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))