comparison tests/run-tests.py @ 28142:85e28a46c7f1

run-tests: add --with-chg option to run tests using chg Unlike --with-hg=/path/to/chg, this option allows us to start and clean up command servers in isolated environment. And we can specify the hg command as well as the chg command.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 07 Feb 2016 16:34:12 +0900
parents 807bc140e915
children c754996fd41f
comparison
equal deleted inserted replaced
28141:13bb8de97f87 28142:85e28a46c7f1
247 help="external diff viewer") 247 help="external diff viewer")
248 parser.add_option("--with-hg", type="string", 248 parser.add_option("--with-hg", type="string",
249 metavar="HG", 249 metavar="HG",
250 help="test using specified hg script rather than a " 250 help="test using specified hg script rather than a "
251 "temporary installation") 251 "temporary installation")
252 parser.add_option("--with-chg", metavar="CHG",
253 help="use specified chg wrapper in place of hg")
252 parser.add_option("-3", "--py3k-warnings", action="store_true", 254 parser.add_option("-3", "--py3k-warnings", action="store_true",
253 help="enable Py3k warnings on Python 2.6+") 255 help="enable Py3k warnings on Python 2.6+")
254 parser.add_option('--extra-config-opt', action="append", 256 parser.add_option('--extra-config-opt', action="append",
255 help='set the given config opt in the test hgrc') 257 help='set the given config opt in the test hgrc')
256 parser.add_option('--random', action="store_true", 258 parser.add_option('--random', action="store_true",
289 hgbin = os.path.join(os.path.dirname(testdir), b'hg') 291 hgbin = os.path.join(os.path.dirname(testdir), b'hg')
290 if os.name != 'nt' and not os.access(hgbin, os.X_OK): 292 if os.name != 'nt' and not os.access(hgbin, os.X_OK):
291 parser.error('--local specified, but %r not found or not executable' 293 parser.error('--local specified, but %r not found or not executable'
292 % hgbin) 294 % hgbin)
293 options.with_hg = hgbin 295 options.with_hg = hgbin
296
297 if options.with_chg:
298 if os.name == 'nt':
299 parser.error('chg does not work on %s' % os.name)
300 options.with_chg = os.path.realpath(
301 os.path.expanduser(_bytespath(options.with_chg)))
302 if not (os.path.isfile(options.with_chg) and
303 os.access(options.with_chg, os.X_OK)):
304 parser.error('--with-chg must specify a chg executable')
294 305
295 options.anycoverage = options.cover or options.annotate or options.htmlcov 306 options.anycoverage = options.cover or options.annotate or options.htmlcov
296 if options.anycoverage: 307 if options.anycoverage:
297 try: 308 try:
298 import coverage 309 import coverage
1809 self._pythondir = None 1820 self._pythondir = None
1810 self._coveragefile = None 1821 self._coveragefile = None
1811 self._createdfiles = [] 1822 self._createdfiles = []
1812 self._hgcommand = None 1823 self._hgcommand = None
1813 self._hgpath = None 1824 self._hgpath = None
1825 self._chgsockdir = None
1814 self._portoffset = 0 1826 self._portoffset = 0
1815 self._ports = {} 1827 self._ports = {}
1816 1828
1817 def run(self, args, parser=None): 1829 def run(self, args, parser=None):
1818 """Run the test suite.""" 1830 """Run the test suite."""
1933 self._bindir = os.path.join(self._installdir, b"bin") 1945 self._bindir = os.path.join(self._installdir, b"bin")
1934 self._hgcommand = b'hg' 1946 self._hgcommand = b'hg'
1935 self._tmpbindir = self._bindir 1947 self._tmpbindir = self._bindir
1936 self._pythondir = os.path.join(self._installdir, b"lib", b"python") 1948 self._pythondir = os.path.join(self._installdir, b"lib", b"python")
1937 1949
1950 # set up crafted chg environment, then replace "hg" command by "chg"
1951 chgbindir = self._bindir
1952 if self.options.with_chg:
1953 self._chgsockdir = d = os.path.join(self._hgtmp, b'chgsock')
1954 os.mkdir(d)
1955 osenvironb[b'CHGSOCKNAME'] = os.path.join(d, b"server")
1956 osenvironb[b'CHGHG'] = os.path.join(self._bindir, self._hgcommand)
1957 chgbindir = os.path.dirname(os.path.realpath(self.options.with_chg))
1958 self._hgcommand = os.path.basename(self.options.with_chg)
1959
1938 osenvironb[b"BINDIR"] = self._bindir 1960 osenvironb[b"BINDIR"] = self._bindir
1939 osenvironb[b"PYTHON"] = PYTHON 1961 osenvironb[b"PYTHON"] = PYTHON
1940 1962
1941 fileb = _bytespath(__file__) 1963 fileb = _bytespath(__file__)
1942 runtestdir = os.path.abspath(os.path.dirname(fileb)) 1964 runtestdir = os.path.abspath(os.path.dirname(fileb))
1949 if os.path.islink(__file__): 1971 if os.path.islink(__file__):
1950 # test helper will likely be at the end of the symlink 1972 # test helper will likely be at the end of the symlink
1951 realfile = os.path.realpath(fileb) 1973 realfile = os.path.realpath(fileb)
1952 realdir = os.path.abspath(os.path.dirname(realfile)) 1974 realdir = os.path.abspath(os.path.dirname(realfile))
1953 path.insert(2, realdir) 1975 path.insert(2, realdir)
1976 if chgbindir != self._bindir:
1977 path.insert(1, chgbindir)
1954 if self._testdir != runtestdir: 1978 if self._testdir != runtestdir:
1955 path = [self._testdir] + path 1979 path = [self._testdir] + path
1956 if self._tmpbindir != self._bindir: 1980 if self._tmpbindir != self._bindir:
1957 path = [self._tmpbindir] + path 1981 path = [self._tmpbindir] + path
1958 osenvironb[b"PATH"] = sepb.join(path) 1982 osenvironb[b"PATH"] = sepb.join(path)
2117 t.should_reload = True 2141 t.should_reload = True
2118 return t 2142 return t
2119 2143
2120 def _cleanup(self): 2144 def _cleanup(self):
2121 """Clean up state from this test invocation.""" 2145 """Clean up state from this test invocation."""
2146 if self._chgsockdir:
2147 self._killchgdaemons()
2122 2148
2123 if self.options.keep_tmpdir: 2149 if self.options.keep_tmpdir:
2124 return 2150 return
2125 2151
2126 vlog("# Cleaning up HGTMP", self._hgtmp) 2152 vlog("# Cleaning up HGTMP", self._hgtmp)
2316 finally: 2342 finally:
2317 pipe.close() 2343 pipe.close()
2318 2344
2319 return self._hgpath 2345 return self._hgpath
2320 2346
2347 def _killchgdaemons(self):
2348 """Kill all background chg command servers spawned by tests"""
2349 for f in os.listdir(self._chgsockdir):
2350 if not f.endswith(b'.pid'):
2351 continue
2352 killdaemons(os.path.join(self._chgsockdir, f))
2353
2321 def _outputcoverage(self): 2354 def _outputcoverage(self):
2322 """Produce code coverage output.""" 2355 """Produce code coverage output."""
2323 from coverage import coverage 2356 from coverage import coverage
2324 2357
2325 vlog('# Producing coverage report') 2358 vlog('# Producing coverage report')