Bug 1252995 - Add method names and uncovered lines to per-test coverage output. draft
authorGregory Mierzwinski <gmierz1@live.ca>
Wed, 02 Mar 2016 18:51:53 -0500
changeset 336522 8ac57d35710eb14072a48cd6b3fb156768162f34
parent 336521 8a9b4501f4777da3dc4ecf78cd5e0de216604702
child 336523 e16f94083da62176a4787f54a2f5d88bec14660f
child 338378 a28c64549f05c7fa509c9ad3a0d34004969576ef
child 338383 9b7c032c6105017f46064d94bf533d793fa8ac83
push id12098
push userbmo:gmierz2@outlook.com
push dateThu, 03 Mar 2016 15:03:30 +0000
bugs1252995
milestone46.0a1
Bug 1252995 - Add method names and uncovered lines to per-test coverage output. This function is used to get the method names contained in the scripts. It returns an array containing keys in the form "lineNumber#methodName" that has each line number associated to a method. If the method is found to have an undefined name, we give it a name "undefined_integer" and every time we find a new undefined method, we increment the integer. There is the possibility that multiple functions can be caught on the same line. If a method has not been covered at all, we use lineNumber == '-1' to designate that it will not have any lines covered. This is needed to be able to have an empty covered array for the uncovered method. MozReview-Commit-ID: HnB7Zowy1OU
testing/modules/CoverageUtils.jsm
--- a/testing/modules/CoverageUtils.jsm
+++ b/testing/modules/CoverageUtils.jsm
@@ -162,16 +162,68 @@ CoverageCollector.prototype._getUncovere
       }
     }                                             
   }
   return uncoveredLines;
 }
 
 
 /**
+* Returns an array containing keys in the form "lineNumber#methodName" that
+* has each line number associated to a method. If the method is found to have
+* an undefined name, we give it a name "undefined_integer" and every time we find
+* a new undefined method, we increment the integer. There is the possibility that
+* multiple functions can be caught on the same line. If a method has not been covered
+* at all, we use lineNumber == '-1' to designate that it will not have any lines covered.
+* This is needed to be able to have an empty covered array for the uncovered method.
+*/
+CoverageCollector.prototype._getMethodNames = function() {
+  let methodNames = {};
+  let temp = 0;
+  this._scripts.forEach(s => {
+    let method = s.displayName;
+    let scriptName = s.url;
+    let cov = s.getOffsetsCoverage();
+    
+    if (!methodNames[scriptName]){
+      methodNames[scriptName] = new Set();
+    }
+    if (!method){
+      method = "undefined_" + temp++; 
+    }
+    if (!cov) {
+      let key = [-1, method].join('#');
+      if(!methodNames[scriptName][key]){
+        methodNames[scriptName][key] = key;
+      }
+      return;
+    }
+
+    cov.forEach(covered => {
+      //Record each line number that was covered
+      let {lineNumber, columnNumber, offset, count} = covered;
+      if (!count) {
+        return;
+      }
+
+      if (!this._allCoverage[scriptName]) {
+        this._allCoverage[scriptName] = {};
+      }
+      //Join the method's name with the line number
+      let key = [lineNumber, method].join('#');
+      if (!methodNames[scriptName][key]) {
+        methodNames[scriptName][key] = key;
+      }
+    });
+  });
+  return methodNames;
+}
+
+
+/**
  * Records lines covered since the last time coverage was recorded,
  * associating them with the given test name. The result is written
  * to a json file in a specified directory.
  */
 CoverageCollector.prototype.recordTestCoverage = function (testName) {
   dump("Collecting coverage for: " + testName + "\n");
   let rawLines = this._getLinesCovered(testName);
   let result = [];