Permalink
Browse files

Initial Commit

  • Loading branch information...
davglass committed Jul 10, 2012
0 parents commit d09db57e312ac83ad3ac5b15ac6d60f228cffc71
Showing with 586 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +5 −0 .travis.yml
  3. +96 −0 lib/index.js
  4. +29 −0 package.json
  5. +369 −0 tests/info/parts.info
  6. +85 −0 tests/parse.js
@@ -0,0 +1,2 @@
+node_modules
+*.swp
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+ - 0.4
+ - 0.6
+ - 0.8
@@ -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;
@@ -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"
+ }
+}
Oops, something went wrong.

0 comments on commit d09db57

Please sign in to comment.