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
--- 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 = [];