Bug 1252995 - Add a method to get uncovered lines. r=chmanchester
authorGreg Mierzwinski <gmierz2@outlook.com>
Fri, 11 Mar 2016 19:13:33 -0500
changeset 351782 b72f1f574abadf0ff5c64cb8814a6b52c31d2940
parent 351781 557559847ec748518993c28da60ba2026a919aa6
child 351783 1602320ae20876e40c82b6d936dae74cf28ab02b
push id15527
push userbmo:rail@mozilla.com
push dateFri, 15 Apr 2016 01:44:41 +0000
reviewerschmanchester
bugs1252995
milestone48.0a1
Bug 1252995 - Add a method to get uncovered lines. r=chmanchester The uncovered lines are now obtained through the use of getAllOffsets and comparing against lines that were covered. MozReview-Commit-ID: DblJeEALUq5
testing/modules/CoverageUtils.jsm
--- a/testing/modules/CoverageUtils.jsm
+++ b/testing/modules/CoverageUtils.jsm
@@ -88,16 +88,45 @@ CoverageCollector.prototype._getLinesCov
         this._allCoverage[scriptName][key] = currentCoverage[scriptName][key];
       }
     }
   }
 
   return coveredLines;
 }
 
+CoverageCollector.prototype._getUncoveredLines = function() {
+  let uncoveredLines = {};
+  this._scripts.forEach(s => {
+    let scriptName = s.url;
+    let scriptOffsets = s.getAllOffsets();
+
+    if (!uncoveredLines[scriptName]){
+      uncoveredLines[scriptName] = new Set();
+    }
+
+    // Get all lines in the script
+    scriptOffsets.forEach( function(element, index) {
+      if (!element){
+        return;
+      }
+      uncoveredLines[scriptName].add(index);
+    });
+  });
+
+  // For all covered lines, delete their entry
+  for (let scriptName in this._allCoverage){
+    for (let key in this._allCoverage[scriptName]){
+      let [lineNumber, columnNumber, offset] = key.split('#');
+      uncoveredLines[scriptName].delete(parseInt(lineNumber, 10));
+    }
+  }
+
+  return uncoveredLines;
+}
 
 /**
  * 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");