comparison tests/run-tests.py @ 47588:eb611ecb435c

run-tests: rely on an actual executable in PATH instead of alias for `hg` The alias approach is poorly inherited by other process that the test might spawn. To solve this we use the same approach as for `python`/`python3` we write an executable file explicitly. Doing this fixes `which hg` invocation that now returns the same location as `hg`. Using chg server side has some minor effect on some stdout/stderr ordering when using `chg` as the server too. Differential Revision: https://phab.mercurial-scm.org/D11053
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 09 Jul 2021 22:37:24 +0200
parents a8e33ab50c4f
children f0fbe8f4faa6
comparison
equal deleted inserted replaced
47587:be496e3489b9 47588:eb611ecb435c
355 defaults = default_defaults.copy() 355 defaults = default_defaults.copy()
356 356
357 357
358 def canonpath(path): 358 def canonpath(path):
359 return os.path.realpath(os.path.expanduser(path)) 359 return os.path.realpath(os.path.expanduser(path))
360
361
362 def which(exe):
363 if PYTHON3:
364 # shutil.which only accept bytes from 3.8
365 cmd = _bytes2sys(exe)
366 real_exec = shutil.which(cmd)
367 return _sys2bytes(real_exec)
368 else:
369 # let us do the os work
370 for p in osenvironb[b'PATH'].split(os.pathsep):
371 f = os.path.join(p, exe)
372 if os.path.isfile(f):
373 return f
374 return None
360 375
361 376
362 def parselistfiles(files, listtype, warn=True): 377 def parselistfiles(files, listtype, warn=True):
363 entries = dict() 378 entries = dict()
364 for filename in files: 379 for filename in files:
1827 # can generate the surrounding doctest magic. 1842 # can generate the surrounding doctest magic.
1828 inpython = False 1843 inpython = False
1829 1844
1830 if self._debug: 1845 if self._debug:
1831 script.append(b'set -x\n') 1846 script.append(b'set -x\n')
1832 if self._hgcommand != b'hg':
1833 script.append(b'alias hg="%s"\n' % self._hgcommand)
1834 if os.getenv('MSYSTEM'): 1847 if os.getenv('MSYSTEM'):
1835 script.append(b'alias pwd="pwd -W"\n') 1848 script.append(b'alias pwd="pwd -W"\n')
1836 1849
1837 if hgcatapult and hgcatapult != os.devnull: 1850 if hgcatapult and hgcatapult != os.devnull:
1838 if PYTHON3: 1851 if PYTHON3:
3434 assert self._installdir 3447 assert self._installdir
3435 self._installchg() 3448 self._installchg()
3436 if self.options.rhg: 3449 if self.options.rhg:
3437 assert self._installdir 3450 assert self._installdir
3438 self._installrhg() 3451 self._installrhg()
3452 self._use_correct_mercurial()
3439 3453
3440 log( 3454 log(
3441 'running %d tests using %d parallel processes' 3455 'running %d tests using %d parallel processes'
3442 % (num_tests, jobs) 3456 % (num_tests, jobs)
3443 ) 3457 )
3625 3639
3626 os.environ['PATH'] = os.pathsep.join(extra_paths + path) 3640 os.environ['PATH'] = os.pathsep.join(extra_paths + path)
3627 for pyexename in pyexe_names: 3641 for pyexename in pyexe_names:
3628 if not self._findprogram(pyexename): 3642 if not self._findprogram(pyexename):
3629 print("WARNING: Cannot find %s in search path" % pyexename) 3643 print("WARNING: Cannot find %s in search path" % pyexename)
3644
3645 def _use_correct_mercurial(self):
3646 target_exec = os.path.join(self._custom_bin_dir, b'hg')
3647 if self._hgcommand != b'hg':
3648 # shutil.which only accept bytes from 3.8
3649 real_exec = which(self._hgcommand)
3650 if real_exec is None:
3651 raise ValueError('could not find exec path for "%s"', real_exec)
3652 if real_exec == target_exec:
3653 # do not overwrite something with itself
3654 return
3655 if WINDOWS:
3656 with open(target_exec, 'wb') as f:
3657 f.write(b'#!/bin/sh\n')
3658 escaped_exec = shellquote(_bytes2sys(real_exec))
3659 f.write(b'%s "$@"\n' % _sys2bytes(escaped_exec))
3660 else:
3661 os.symlink(real_exec, target_exec)
3662 self._createdfiles.append(target_exec)
3630 3663
3631 def _installhg(self): 3664 def _installhg(self):
3632 """Install hg into the test environment. 3665 """Install hg into the test environment.
3633 3666
3634 This will also configure hg with the appropriate testing settings. 3667 This will also configure hg with the appropriate testing settings.