Bug 1252995 - Add a method to get lines and name of methods. draft
authorGreg Mierzwinski <gmierz2@outlook.com>
Fri, 11 Mar 2016 19:18:19 -0500
changeset 348547 3fd5326154e05dd8b6e6d62991e5e0c7d89fe6ed
parent 348546 38f5029d6460ab8d35be6c18d00313c8015f77c9
child 348548 2a633a435b2d284bcd21c7930550dac1508a7f2c
push id14847
push userbmo:gmierz2@outlook.com
push dateThu, 07 Apr 2016 18:44:37 +0000
bugs1252995
milestone48.0a1
Bug 1252995 - Add a method to get lines and name of methods. This method gets method names and the lines each method spans. It uses getAllOffsets to get the lines. MozReview-Commit-ID: Df4kP11obq2 * * * Bug 1252995 - GetMethodNames revision. Fixed current issues. * * * Bug 1252995 - Fixed method names.
testing/modules/CoverageUtils.jsm
--- a/testing/modules/CoverageUtils.jsm
+++ b/testing/modules/CoverageUtils.jsm
@@ -131,16 +131,50 @@ CoverageCollector.prototype._getUncovere
     for (let line of tempUncov[scriptName]){
       uncoveredLines[scriptName].add(line);
     }
   }
 
   return uncoveredLines;
 }
 
+CoverageCollector.prototype._getMethodNames = function() {
+  let methodNames = {};
+  this._scripts.forEach(s => {
+    let method = s.displayName;
+    // If the method name is undefined, we return early
+    if (!method){
+      return;
+    }
+
+    let scriptName = s.url;
+    let tempMethodCov = [];
+    let scriptOffsets = s.getAllOffsets();
+
+    if (!methodNames[scriptName]){
+      methodNames[scriptName] = {};
+    }
+
+    /**
+    * Get all lines contained within the method and
+    * push a record of the form:
+    * <method name> : <lines covered>
+    */
+    scriptOffsets.forEach(function (element, index){
+      if (!element){
+        return;
+      }
+      tempMethodCov.push(index);
+    });
+    methodNames[scriptName][method] = tempMethodCov;
+  });
+
+  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);