Mercurial > hg
comparison tests/run-tests.py @ 24506:60bbb4079c28
run-tests: report code coverage from source directory
As part of testing code coverage output, I noticed some files were
being reported twice: there was an entry for the file in the install
location and for the file in the source tree. I'm not sure why this
is. But it resulted in under-reporting of coverage data since some
lines weren't getting covered in both locations.
I also noticed that files in the source directory and outside the
"mercurial" and "hgext" packages were getting included in the
coverage report. Cosmetically, this seemed odd to me. It's not
difficult to filter paths from the report. But I figure this data
can be useful (we could start reporting run-tests.py coverage,
for example).
This patch switches the coverage API to report code coverage from
the source directory. It registers a path alias so that data from
the install location is merged into data from the source directory.
We now get merged results for files that were being reported in
multiple locations.
Since code coverage reporting now relies on the profiled install
now being in sync with the source tree, an additional check to
disallow code coverage when --with-hg is specified has been added.
This should have been present before, as --local was previously
disallowed for the same reasons.
Merging the paths raises our aggregate line coverage from ~60 to
81%.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 28 Mar 2015 00:21:30 -0700 |
parents | 031947baf4d0 |
children | a0668a587c04 |
comparison
equal
deleted
inserted
replaced
24505:031947baf4d0 | 24506:60bbb4079c28 |
---|---|
258 if options.anycoverage and options.local: | 258 if options.anycoverage and options.local: |
259 # this needs some path mangling somewhere, I guess | 259 # this needs some path mangling somewhere, I guess |
260 parser.error("sorry, coverage options do not work when --local " | 260 parser.error("sorry, coverage options do not work when --local " |
261 "is specified") | 261 "is specified") |
262 | 262 |
263 if options.anycoverage and options.with_hg: | |
264 parser.error("sorry, coverage options do not work when --with-hg " | |
265 "is specified") | |
266 | |
263 global verbose | 267 global verbose |
264 if options.verbose: | 268 if options.verbose: |
265 verbose = '' | 269 verbose = '' |
266 | 270 |
267 if options.tmpdir: | 271 if options.tmpdir: |
1565 ('.t', TTest), | 1569 ('.t', TTest), |
1566 ] | 1570 ] |
1567 | 1571 |
1568 def __init__(self): | 1572 def __init__(self): |
1569 self.options = None | 1573 self.options = None |
1574 self._hgroot = None | |
1570 self._testdir = None | 1575 self._testdir = None |
1571 self._hgtmp = None | 1576 self._hgtmp = None |
1572 self._installdir = None | 1577 self._installdir = None |
1573 self._bindir = None | 1578 self._bindir = None |
1574 self._tmpbinddir = None | 1579 self._tmpbinddir = None |
1870 py3 = '--c2to3' | 1875 py3 = '--c2to3' |
1871 | 1876 |
1872 # Run installer in hg root | 1877 # Run installer in hg root |
1873 script = os.path.realpath(sys.argv[0]) | 1878 script = os.path.realpath(sys.argv[0]) |
1874 hgroot = os.path.dirname(os.path.dirname(script)) | 1879 hgroot = os.path.dirname(os.path.dirname(script)) |
1880 self._hgroot = hgroot | |
1875 os.chdir(hgroot) | 1881 os.chdir(hgroot) |
1876 nohome = '--home=""' | 1882 nohome = '--home=""' |
1877 if os.name == 'nt': | 1883 if os.name == 'nt': |
1878 # The --home="" trick works only on OS where os.sep == '/' | 1884 # The --home="" trick works only on OS where os.sep == '/' |
1879 # because of a distutils convert_path() fast-path. Avoid it at | 1885 # because of a distutils convert_path() fast-path. Avoid it at |
1994 from coverage import coverage | 2000 from coverage import coverage |
1995 | 2001 |
1996 vlog('# Producing coverage report') | 2002 vlog('# Producing coverage report') |
1997 # chdir is the easiest way to get short, relative paths in the | 2003 # chdir is the easiest way to get short, relative paths in the |
1998 # output. | 2004 # output. |
1999 os.chdir(self._pythondir) | 2005 os.chdir(self._hgroot) |
2000 covdir = os.path.join(self._installdir, '..', 'coverage') | 2006 covdir = os.path.join(self._installdir, '..', 'coverage') |
2001 cov = coverage(data_file=os.path.join(covdir, 'cov')) | 2007 cov = coverage(data_file=os.path.join(covdir, 'cov')) |
2008 | |
2009 # Map install directory paths back to source directory. | |
2010 cov.config.paths['srcdir'] = ['.', self._pythondir] | |
2011 | |
2002 cov.combine() | 2012 cov.combine() |
2003 | 2013 |
2004 omit = [os.path.join(x, '*') for x in [self._bindir, self._testdir]] | 2014 omit = [os.path.join(x, '*') for x in [self._bindir, self._testdir]] |
2005 cov.report(ignore_errors=True, omit=omit) | 2015 cov.report(ignore_errors=True, omit=omit) |
2006 | 2016 |