Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Jul 10, 2012
0 parents commit d09db57
Show file tree
Hide file tree
Showing 6 changed files with 586 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
node_modules
*.swp
5 changes: 5 additions & 0 deletions .travis.yml
@@ -0,0 +1,5 @@
language: node_js
node_js:
- 0.4
- 0.6
- 0.8
96 changes: 96 additions & 0 deletions lib/index.js
@@ -0,0 +1,96 @@
var fs = require('fs'),
path = require('path'),

exists = fs.exists || path.exists;

var results = {};

var walkFile = function(str, cb) {
var data = [];
str = str.split('\n');
var item = {};
str.forEach(function(line) {
line = line.trim();
var parts = line.split(':');
switch (parts[0].toUpperCase()) {
case 'TN':
item.title = parts[1].trim();
break;
case 'SF':
item.file = parts[1].trim();
break;
case 'FNF':
item.functions.found = Number(parts[1].trim());
break;
case 'FNH':
item.functions.hit = Number(parts[1].trim());
break;
case 'LF':
item.lines.found = Number(parts[1].trim());
break;
case 'LH':
item.lines.hit = Number(parts[1].trim());
break;
case 'DA':
if (!item.lines) {
item.lines = {
found: 0,
hit: 0,
details: []
};
}
var lines = parts[1].split(',');
item.lines.details.push({
line: Number(lines[0]),
hit: Number(lines[1])
});
break;
case 'FN':
if (!item.functions) {
item.functions = {
hit: 0,
found: 0,
details: []
};
}
var fn = parts[1].split(',');
item.functions.details.push({
name: fn[1],
line: Number(fn[0])
});
break;
case 'FNDA':
var fn = parts[1].split(',');
item.functions.details.some(function(i, k) {
if (i.name === fn[1] && i.hit === undefined) {
item.functions.details[k].hit = Number(fn[0]);
return true;
}
});
break;
}

if (line.indexOf('end_of_record') > -1) {
data.push(item);
item = {};
}
});
cb(null, data);
};

var parse = function(file, cb) {

exists(file, function(x) {
if (!x) {
cb("Failed to find file: " + file);
return;
}
fs.readFile(file, 'utf8', function(err, str) {
walkFile(str, cb);
});
});

};


module.exports = parse;
29 changes: 29 additions & 0 deletions package.json
@@ -0,0 +1,29 @@
{
"name": "lcov-parse",
"description": "Parse lcov results files and return JSON",
"version": "0.0.1",
"author": "Dav Glass <davglass@gmail.com>",
"bugs": { "url" : "http://github.com/davglass/lcov-parse/issues" },
"main": "./lib/index",
"tags": [
"lcov",
"json",
"coverage",
"parser"
],
"devDependencies": {
"vows": "*"
},
"scripts": {
"test": "./node_modules/.bin/vows ./tests/*.js"
},
"licenses":[
{
"type" : "BSD"
}
],
"repository": {
"type":"git",
"url":"http://github.com/davglass/lcov-parse.git"
}
}

0 comments on commit d09db57

Please sign in to comment.