forked from codeclimate/javascript-test-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gocover_parse.js
50 lines (40 loc) · 1.11 KB
/
gocover_parse.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict'
module.exports = function(data, cb) {
var memo = {};
var parsedData = [];
var lines = data.split('\n');
// Skip mode line
lines.shift();
lines.forEach(function(line) {
// coverage line syntax:
// Filename:<start line>.<start column>,<end line>.<end column>.<# of statements>.<hit count>
var data = line.match(/(.*?):(\d+).\d+,(\d+).\d+ \d+ (\d+)/);
if (!data) {
return;
}
// filename is given relative to $GOPATH/src, so tack $GOPATH/src on the
// front. Converting it to a relative filenae is handled by the formatter.
var filename = process.env.GOPATH + '/src/' + data[1];
var startLine = data[2];
var endLine = data[3];
var hitCount = data[4];
if (!memo[filename]) {
memo[filename] = {
file: filename,
lines: {
details: []
}
}
parsedData.push(memo[filename])
}
var lineData = memo[filename].lines;
var i = startLine;
for(var i = startLine; i <= endLine; i++) {
lineData.details.push({
line: i*1,
hit: hitCount*1
})
}
});
cb(null, parsedData);
}