1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | var processFile = function processFile(out, fileName, fileInfos) {
|
17 | fileName = fileName.replace(/\\/g, '/');
|
18 | out.push('SF:' + fileName);
|
19 | var statements = fileInfos.code.src;
|
20 | var execCount;
|
21 | var realLines = {};
|
22 | var lineNumber = 0;
|
23 | var statementDetails = fileInfos.statements.detail;
|
24 | for (var i = 1, l = statements.length; i <= l; i++) {
|
25 | var curStatement = statements[i - 1];
|
26 | var statementKey = curStatement.l;
|
27 | if (statementKey) {
|
28 | execCount = statementDetails[statementKey];
|
29 |
|
30 |
|
31 | var matchLineNumber = /^[^0-9]*([0-9]+)_[0-9]+$/.exec(statementKey);
|
32 | lineNumber = 1 + parseInt(matchLineNumber[1], 10);
|
33 |
|
34 | var currentNumber = realLines[lineNumber];
|
35 |
|
36 | if (currentNumber == null || execCount < currentNumber) {
|
37 |
|
38 | realLines[lineNumber] = execCount;
|
39 | }
|
40 | }
|
41 | }
|
42 | var linesInstrumented = 0;
|
43 | var linesCovered = 0;
|
44 | for (lineNumber in realLines) {
|
45 | execCount = realLines[lineNumber];
|
46 | if (execCount > 0) {
|
47 | linesCovered++;
|
48 | }
|
49 | linesInstrumented++;
|
50 | out.push('DA:' + lineNumber + ',' + execCount);
|
51 | }
|
52 | out.push('LH:' + linesCovered);
|
53 | out.push('LF:' + linesInstrumented);
|
54 | out.push('end_of_record');
|
55 | };
|
56 |
|
57 | module.exports = function (coverage) {
|
58 | var out = [];
|
59 | var files = coverage.files;
|
60 | for (var curFile in files) {
|
61 | if (files.hasOwnProperty(curFile)) {
|
62 | processFile(out, curFile, files[curFile]);
|
63 | }
|
64 | }
|
65 | return out.join('\n');
|
66 | };
|