Bug 1252995 - Add method anmes and uncovered lines to per-test coverage.
MozReview-Commit-ID: 62tSQZwwLPW
--- a/testing/modules/CoverageUtils.jsm
+++ b/testing/modules/CoverageUtils.jsm
@@ -221,26 +221,87 @@ CoverageCollector.prototype._getMethodNa
/**
* 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 methods = this._getMethodNames(testName);
+ let uncoveredLines = this._getUncoveredLines(testName);
let result = [];
+
for (let scriptName in rawLines) {
let rec = {
testUrl: testName,
sourceFile: scriptName,
- covered: []
+ method: [],
+ covered: [],
+ uncovered: []
+ };
+
+ /**
+ * Get the last record in finalRec.
+ * This is needed because we push records into rec
+ * everytime we find a new method name.
+ */
+ let finalRec = {
+ methodName: "null",
+ cov: []
};
+ let covering = [];
+ let methodTest = null;
+ for (let methodKey in methods[scriptName]){
+ let [lineNumber, methodJoin] = methodKey.split("#");
+ //Get a method name
+ if (!methodTest){
+ methodTest = methodJoin;
+ }
+ else if (methodTest !== methodJoin){
+ //If we have a new method name, push the current record
+ let methodRec = { methodName: methodTest, cov: covering };
+ rec.method.push(methodRec);
+ covering = [];
+ methodTest = methodJoin;
+ }
+
+ /**
+ * Add the current line to the lines this method covers
+ * if the current method has lines covered, otherwise,
+ * push a new record with an empty covered array for the
+ * uncovered method.
+ */
+ if (parseInt(lineNumber, 10) !== -1){
+ covering.push(parseInt(lineNumber, 10));
+ }
+ else{
+ let methodRec = {methodName: methodTest, cov: [] };
+ rec.method.push(methodRec);
+ methodTest = null;
+ }
+ //Record the current coverage just in case we are at the last method
+ finalRec.cov = covering;
+ finalRec.methodName = methodJoin;
+ }
+
+ /**
+ * Don't record the final one if there are no methods covered or
+ * the method covered has no covered lines since it was already pushed.
+ */
+ if (finalRec.methodName != "null" && finalRec.cov.length != 0){
+ rec.method.push(finalRec);
+ }
+
for (let line of rawLines[scriptName]) {
rec.covered.push(line);
}
+ for (let line in uncoveredLines[scriptName]){
+ rec.uncovered.push(parseInt(line, 10));
+ }
result.push(rec);
}
let arr = this._encoder.encode(JSON.stringify(result, null, 2));
let path = this._prefix + '/' + 'jscov_' + Date.now() + '.json';
dump("Writing coverage to: " + path + "\n");
return OS.File.writeAtomic(path, arr, {tmpPath: path + '.tmp'});
}