tests/run-tests.py
changeset 21368 a884548f5421
parent 21367 522e3d24a461
child 21369 1d0aa8bccc87
equal deleted inserted replaced
21367:522e3d24a461 21368:a884548f5421
  1017     def run(self, tests):
  1017     def run(self, tests):
  1018         """Run the test suite."""
  1018         """Run the test suite."""
  1019         return self._run(tests)
  1019         return self._run(tests)
  1020 
  1020 
  1021     def _run(self, tests):
  1021     def _run(self, tests):
       
  1022         if self.options.with_hg:
       
  1023             self.inst = None
       
  1024             self.bindir = os.path.dirname(os.path.realpath(
       
  1025                                           self.options.with_hg))
       
  1026             self.tmpbindir = os.path.join(self.hgtmp, 'install', 'bin')
       
  1027             os.makedirs(self.tmpbindir)
       
  1028 
       
  1029             # This looks redundant with how Python initializes sys.path from
       
  1030             # the location of the script being executed.  Needed because the
       
  1031             # "hg" specified by --with-hg is not the only Python script
       
  1032             # executed in the test suite that needs to import 'mercurial'
       
  1033             # ... which means it's not really redundant at all.
       
  1034             self.pythondir = self.bindir
       
  1035         else:
       
  1036             self.inst = os.path.join(self.hgtmp, "install")
       
  1037             self.bindir = os.environ["BINDIR"] = os.path.join(self.inst,
       
  1038                                                               "bin")
       
  1039             self.tmpbindir = self.bindir
       
  1040             self.pythondir = os.path.join(self.inst, "lib", "python")
       
  1041 
       
  1042         os.environ["BINDIR"] = self.bindir
       
  1043         os.environ["PYTHON"] = PYTHON
       
  1044 
       
  1045         path = [self.bindir] + os.environ["PATH"].split(os.pathsep)
       
  1046         if self.tmpbindir != self.bindir:
       
  1047             path = [self.tmpbindir] + path
       
  1048         os.environ["PATH"] = os.pathsep.join(path)
       
  1049 
  1022         # Include TESTDIR in PYTHONPATH so that out-of-tree extensions
  1050         # Include TESTDIR in PYTHONPATH so that out-of-tree extensions
  1023         # can run .../tests/run-tests.py test-foo where test-foo
  1051         # can run .../tests/run-tests.py test-foo where test-foo
  1024         # adds an extension to HGRC. Also include run-test.py directory to
  1052         # adds an extension to HGRC. Also include run-test.py directory to
  1025         # import modules like heredoctest.
  1053         # import modules like heredoctest.
  1026         pypath = [self.pythondir, self.testdir,
  1054         pypath = [self.pythondir, self.testdir,
  1432             # in all lowercase, which causes troubles with paths (issue3490)
  1460             # in all lowercase, which causes troubles with paths (issue3490)
  1433             d = os.getenv('TMP')
  1461             d = os.getenv('TMP')
  1434         tmpdir = tempfile.mkdtemp('', 'hgtests.', d)
  1462         tmpdir = tempfile.mkdtemp('', 'hgtests.', d)
  1435     runner.hgtmp = os.environ['HGTMP'] = os.path.realpath(tmpdir)
  1463     runner.hgtmp = os.environ['HGTMP'] = os.path.realpath(tmpdir)
  1436 
  1464 
  1437     if options.with_hg:
       
  1438         runner.inst = None
       
  1439         runner.bindir = os.path.dirname(os.path.realpath(options.with_hg))
       
  1440         runner.tmpbindir = os.path.join(runner.hgtmp, 'install', 'bin')
       
  1441         os.makedirs(runner.tmpbindir)
       
  1442 
       
  1443         # This looks redundant with how Python initializes sys.path from
       
  1444         # the location of the script being executed.  Needed because the
       
  1445         # "hg" specified by --with-hg is not the only Python script
       
  1446         # executed in the test suite that needs to import 'mercurial'
       
  1447         # ... which means it's not really redundant at all.
       
  1448         runner.pythondir = runner.bindir
       
  1449     else:
       
  1450         runner.inst = os.path.join(runner.hgtmp, "install")
       
  1451         runner.bindir = os.environ["BINDIR"] = os.path.join(runner.inst,
       
  1452                                                             "bin")
       
  1453         runner.tmpbindir = runner.bindir
       
  1454         runner.pythondir = os.path.join(runner.inst, "lib", "python")
       
  1455 
       
  1456     os.environ["BINDIR"] = runner.bindir
       
  1457     os.environ["PYTHON"] = PYTHON
       
  1458 
       
  1459     path = [runner.bindir] + os.environ["PATH"].split(os.pathsep)
       
  1460     if runner.tmpbindir != runner.bindir:
       
  1461         path = [runner.tmpbindir] + path
       
  1462     os.environ["PATH"] = os.pathsep.join(path)
       
  1463 
       
  1464     return runner.run(tests)
  1465     return runner.run(tests)
  1465 
  1466 
  1466 if __name__ == '__main__':
  1467 if __name__ == '__main__':
  1467     sys.exit(main(sys.argv[1:]))
  1468     sys.exit(main(sys.argv[1:]))