Patchwork D11307: run-tests: avoid silently switching the hg executable used

login
register
mail settings
Submitter phabricator
Date Aug. 18, 2021, 9 p.m.
Message ID <differential-rev-PHID-DREV-se43g3nywzwl7p4w2ggq-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49621/
State New
Headers show

Comments

phabricator - Aug. 18, 2021, 9 p.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I noticed an issue testing the installed pyoxidizer binary using `--with-hg`
  where it would pass more tests than if the tests are run with `--pyoxidized`.
  It turns out that `_usecorrectpython()` augments `PATH` to include the python
  binary and its `Scripts` directory on Windows, and I happen to have `pip`
  installed Mercurial in that version of python.  Therefore, the `which()` method
  picked up this installed executable, and wrote that to the generated `hg` script
  in the custom `bin` directory.
  
  There's an issue here when running `test-run-tests.t` with `--local`, as noted
  in the comments.  I suspect that some stuff from the main instance of
  `run-tests.py` is bleeding into the *.t file's instances of `run-tests.py`
  because when I print `opts.with_hg` at the point where is complains that
  "--with-hg must specify an executable hg script", the path is in the form
  "C:\\\\Users\\\\Matt\\\\...".  (Two of those slashes are escapes the test runner
  puts into printed lines.)  If I hardcode r"C:\Users\Matt\..." in `run-tests.py`,
  then it works fine.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  tests/run-tests.py

CHANGE DETAILS




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

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -3679,8 +3679,19 @@ 
     def _use_correct_mercurial(self):
         target_exec = os.path.join(self._custom_bin_dir, b'hg')
         if self._hgcommand != b'hg':
-            # shutil.which only accept bytes from 3.8
-            real_exec = which(self._hgcommand)
+            # _usecorrectpython() may have augmented PATH, so don't used `which`
+            # on the basename of the explicitly provided executable, since that
+            # may end up using another one.
+            #
+            # TODO: figure how why test-run-tests.t fails on Windows if we
+            #  unconditionally join with bindir, and run with --local.  Not
+            #  using --local will run the *.t fine.
+            if self.options.with_hg:
+                real_exec = os.path.join(self._bindir, self._hgcommand)
+            else:
+                # shutil.which only accept bytes from 3.8
+                real_exec = which(self._hgcommand)
+
             if real_exec is None:
                 raise ValueError('could not find exec path for "%s"', real_exec)
             if real_exec == target_exec: