# HG changeset patch # User Gregory Szorc # Date 2015-03-28 07:21:30 # Node ID 60bbb4079c286287595c8f5653c7c3b00bc98cbc # Parent 031947baf4d066cf82b0c50f43e8c6b3f6683e97 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%. diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -260,6 +260,10 @@ def parseargs(args, parser): parser.error("sorry, coverage options do not work when --local " "is specified") + if options.anycoverage and options.with_hg: + parser.error("sorry, coverage options do not work when --with-hg " + "is specified") + global verbose if options.verbose: verbose = '' @@ -1567,6 +1571,7 @@ class TestRunner(object): def __init__(self): self.options = None + self._hgroot = None self._testdir = None self._hgtmp = None self._installdir = None @@ -1872,6 +1877,7 @@ class TestRunner(object): # Run installer in hg root script = os.path.realpath(sys.argv[0]) hgroot = os.path.dirname(os.path.dirname(script)) + self._hgroot = hgroot os.chdir(hgroot) nohome = '--home=""' if os.name == 'nt': @@ -1996,9 +2002,13 @@ class TestRunner(object): vlog('# Producing coverage report') # chdir is the easiest way to get short, relative paths in the # output. - os.chdir(self._pythondir) + os.chdir(self._hgroot) covdir = os.path.join(self._installdir, '..', 'coverage') cov = coverage(data_file=os.path.join(covdir, 'cov')) + + # Map install directory paths back to source directory. + cov.config.paths['srcdir'] = ['.', self._pythondir] + cov.combine() omit = [os.path.join(x, '*') for x in [self._bindir, self._testdir]]