changeset 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
files tests/run-tests.py
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Sat Mar 28 00:47:58 2015 -0700
+++ b/tests/run-tests.py	Sat Mar 28 00:21:30 2015 -0700
@@ -260,6 +260,10 @@
         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 @@
 
     def __init__(self):
         self.options = None
+        self._hgroot = None
         self._testdir = None
         self._hgtmp = None
         self._installdir = None
@@ -1872,6 +1877,7 @@
         # 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 @@
         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]]