Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial Commit

  • Loading branch information...
commit d09db57e312ac83ad3ac5b15ac6d60f228cffc71 0 parents
@davglass authored
2  .gitignore
@@ -0,0 +1,2 @@
+node_modules
+*.swp
5 .travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+ - 0.4
+ - 0.6
+ - 0.8
96 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 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"
+ }
+}
369 tests/info/parts.info
@@ -0,0 +1,369 @@
+TN:Test #1
+SF:anim-base/anim-base-coverage.js
+FN:7,(anonymous 1)
+FN:620,(anonymous 2)
+FN:516,_end
+FN:662,_getOffset
+FN:609,_initAnimAttr
+FN:584,_lastFrame
+FN:487,_pause
+FN:501,_resume
+FN:548,_runAttrs
+FN:415,_runFrame
+FN:530,_runFrame
+FN:475,_start
+FN:398,_startTimer
+FN:404,_stopTimer
+FN:66,Anim
+FN:91,DEFAULT_EASING
+FN:153,DEFAULT_GETTER
+FN:126,DEFAULT_SETTER
+FN:681,destructor
+FN:112,get
+FN:287,getter
+FN:374,pause
+FN:453,pause
+FN:437,run
+FN:360,run
+FN:214,setter
+FN:182,setter
+FN:466,stop
+FN:389,stop
+
+FNDA:6,(anonymous 1)
+FNDA:225,(anonymous 2)
+FNDA:228,_end
+FNDA:0,_getOffset
+FNDA:231,_initAnimAttr
+FNDA:219,_lastFrame
+FNDA:6,_pause
+FNDA:3,_resume
+FNDA:4290,_runAttrs
+FNDA:4077,_runFrame
+FNDA:4287,_runFrame
+FNDA:231,_start
+FNDA:234,_startTimer
+FNDA:13,_stopTimer
+FNDA:234,Anim
+FNDA:599,DEFAULT_EASING
+FNDA:78,DEFAULT_GETTER
+FNDA:1162,DEFAULT_SETTER
+FNDA:0,destructor
+FNDA:0,get
+FNDA:252,getter
+FNDA:0,pause
+FNDA:6,pause
+FNDA:234,run
+FNDA:0,run
+FNDA:231,setter
+FNDA:234,setter
+FNDA:9,stop
+FNDA:0,stop
+
+FNF:29
+FNH:23
+DA:7,6
+DA:29,6
+DA:63,6
+DA:66,6
+DA:67,234
+DA:68,234
+DA:71,6
+DA:73,6
+DA:81,6
+DA:89,6
+DA:91,6
+DA:92,599
+DA:102,6
+DA:110,6
+DA:113,0
+DA:118,6
+DA:126,6
+DA:127,1162
+DA:131,1162
+DA:132,1162
+DA:133,1028
+DA:134,1028
+DA:135,134
+DA:136,0
+DA:137,134
+DA:138,134
+DA:140,0
+DA:141,0
+DA:142,0
+DA:143,0
+DA:153,6
+DA:154,78
+DA:158,78
+DA:159,78
+DA:160,72
+DA:161,6
+DA:162,0
+DA:163,6
+DA:164,6
+DA:166,0
+DA:167,0
+DA:168,0
+DA:169,0
+DA:172,78
+DA:175,6
+DA:183,234
+DA:184,234
+DA:185,3
+DA:189,234
+DA:190,234
+DA:192,234
+DA:215,231
+DA:216,192
+DA:288,252
+DA:360,6
+DA:361,0
+DA:362,0
+DA:363,0
+DA:364,0
+DA:374,6
+DA:375,0
+DA:376,0
+DA:377,0
+DA:381,0
+DA:389,6
+DA:390,0
+DA:391,0
+DA:392,0
+DA:395,0
+DA:398,6
+DA:399,234
+DA:400,13
+DA:404,6
+DA:405,13
+DA:406,13
+DA:415,6
+DA:416,4077
+DA:417,4077
+DA:418,4287
+DA:419,4287
+DA:420,4287
+DA:424,4077
+DA:425,13
+DA:429,6
+DA:431,6
+DA:438,234
+DA:439,3
+DA:440,231
+DA:441,231
+DA:443,234
+DA:454,6
+DA:455,6
+DA:457,6
+DA:467,9
+DA:468,9
+DA:470,9
+DA:476,231
+DA:477,231
+DA:478,231
+DA:479,231
+DA:481,231
+DA:482,231
+DA:484,231
+DA:488,6
+DA:489,6
+DA:490,6
+DA:498,6
+DA:502,3
+DA:503,3
+DA:504,3
+DA:505,3
+DA:513,3
+DA:517,228
+DA:518,228
+DA:519,3
+DA:522,228
+DA:523,228
+DA:524,228
+DA:526,228
+DA:527,228
+DA:531,4287
+DA:538,4287
+DA:539,4287
+DA:540,4287
+DA:542,4287
+DA:543,4287
+DA:544,219
+DA:549,4290
+DA:558,4290
+DA:559,222
+DA:562,4290
+DA:563,67
+DA:564,67
+DA:567,4290
+DA:568,12906
+DA:569,4326
+DA:570,4326
+DA:573,4326
+DA:574,4107
+DA:576,219
+DA:585,219
+DA:588,219
+DA:589,219
+DA:590,0
+DA:591,0
+DA:599,0
+DA:601,219
+DA:602,219
+DA:605,219
+DA:606,219
+DA:610,231
+DA:620,231
+DA:621,225
+DA:622,6
+DA:625,225
+DA:626,225
+DA:627,222
+DA:629,3
+DA:630,0
+DA:633,225
+DA:634,225
+DA:636,225
+DA:637,225
+DA:638,225
+DA:640,225
+DA:641,78
+DA:644,225
+DA:645,0
+DA:646,0
+DA:649,225
+DA:657,231
+DA:663,0
+DA:668,0
+DA:669,0
+DA:670,0
+DA:671,0
+DA:672,0
+DA:674,0
+DA:678,0
+DA:682,0
+DA:686,6
+
+LF:181
+LH:143
+end_of_record
+TN:Test #2
+SF:anim-easing/anim-easing-coverage.js
+FN:7,(anonymous 1)
+FN:292,backBoth
+FN:254,backIn
+FN:274,backOut
+FN:345,bounceBoth
+FN:312,bounceIn
+FN:325,bounceOut
+FN:82,easeBoth
+FN:125,easeBothStrong
+FN:56,easeIn
+FN:99,easeInStrong
+FN:43,easeNone
+FN:69,easeOut
+FN:112,easeOutStrong
+FN:213,elasticBoth
+FN:145,elasticIn
+FN:179,elasticOut
+
+FNDA:6,(anonymous 1)
+FNDA:33,backBoth
+FNDA:36,backIn
+FNDA:36,backOut
+FNDA:36,bounceBoth
+FNDA:51,bounceIn
+FNDA:107,bounceOut
+FNDA:36,easeBoth
+FNDA:36,easeBothStrong
+FNDA:32,easeIn
+FNDA:35,easeInStrong
+FNDA:11121,easeNone
+FNDA:35,easeOut
+FNDA:36,easeOutStrong
+FNDA:36,elasticBoth
+FNDA:35,elasticIn
+FNDA:34,elasticOut
+
+FNF:17
+FNH:17
+DA:7,6
+DA:31,6
+DA:44,11121
+DA:57,32
+DA:70,35
+DA:83,36
+DA:84,16
+DA:87,20
+DA:100,35
+DA:113,36
+DA:126,36
+DA:127,17
+DA:130,19
+DA:146,35
+DA:147,35
+DA:148,0
+DA:150,35
+DA:151,3
+DA:153,32
+DA:154,32
+DA:157,32
+DA:158,32
+DA:159,32
+DA:162,0
+DA:165,32
+DA:180,34
+DA:181,34
+DA:182,0
+DA:184,34
+DA:185,3
+DA:187,31
+DA:188,31
+DA:191,31
+DA:192,31
+DA:193,31
+DA:196,0
+DA:199,31
+DA:214,36
+DA:215,36
+DA:216,0
+DA:219,36
+DA:220,3
+DA:223,33
+DA:224,33
+DA:227,33
+DA:228,33
+DA:229,33
+DA:232,0
+DA:235,33
+DA:236,16
+DA:239,17
+DA:255,36
+DA:256,36
+DA:258,36
+DA:259,3
+DA:261,36
+DA:275,36
+DA:276,36
+DA:278,36
+DA:293,33
+DA:294,33
+DA:297,33
+DA:298,15
+DA:300,18
+DA:313,51
+DA:326,107
+DA:327,38
+DA:328,69
+DA:329,36
+DA:330,33
+DA:331,18
+DA:333,15
+DA:346,36
+DA:347,16
+DA:349,20
+DA:353,6
+
+LF:76
+LH:70
+end_of_record
85 tests/parse.js
@@ -0,0 +1,85 @@
+var vows = require('vows'),
+ path = require('path'),
+ assert = require('assert'),
+ parse = require(path.join(__dirname, '../lib')),
+ yuiFile = path.join(__dirname, 'info/parts.info');
+
+
+vows.describe('Test Loading and Bindings').addBatch({
+ 'Should be loaded': {
+ topic: function() {
+ return parse;
+ },
+ 'should be a function': function(topic) {
+ assert.isFunction(topic);
+ }
+ },
+ 'Catch bad file passing': {
+ topic: function() {
+ parse('foobar', this.callback);
+ },
+ 'should return an error': function(err, data) {
+ assert.isUndefined(data);
+ assert.isString(err);
+ }
+ },
+ 'parse the file': {
+ topic: function() {
+ parse(yuiFile, this.callback);
+ },
+ 'should return an array': function(err, data) {
+ assert.isNull(err);
+ assert.isArray(data);
+ },
+ 'should contain 2 keys': function(err, data) {
+ assert.equal(data.length, 2);
+ },
+ 'first key should have 4 properties': function(err, data) {
+ var d = data[0];
+ assert.deepEqual(Object.keys(d), [ 'title', 'file', 'functions', 'lines' ]);
+ },
+ 'verify test titles': function(err, data) {
+ assert.equal(data[0].title, 'Test #1');
+ assert.equal(data[1].title, 'Test #2');
+ },
+ 'verify test files': function(err, data) {
+ assert.equal(data[0].file, 'anim-base/anim-base-coverage.js');
+ assert.equal(data[1].file, 'anim-easing/anim-easing-coverage.js');
+ },
+ 'verify number of functions': function(err, data) {
+ assert.equal(data[0].functions.found, 29);
+ assert.equal(data[0].functions.hit, 23);
+ assert.equal(data[1].functions.found, 17);
+ assert.equal(data[1].functions.hit, 17);
+ },
+ 'verify function details': function(err, data) {
+ assert.equal(data[0].functions.details.length, 29);
+ assert.equal(data[1].functions.details.length, 17);
+ assert.deepEqual(data[0].functions.details[0], { name: '(anonymous 1)', line: 7, hit: 6 });
+ assert.deepEqual(data[0].functions.details[11], { name: '_start', line: 475, hit: 231 });
+
+ assert.deepEqual(data[0].functions.details[27], { name: 'stop', line: 466, hit: 9 });
+ assert.deepEqual(data[0].functions.details[28], { name: 'stop', line: 389, hit: 0 });
+
+ assert.deepEqual(data[1].functions.details[4], { name: 'bounceBoth', line: 345, hit: 36 });
+
+ },
+ 'verify number of lines': function(err, data) {
+ assert.equal(data[0].lines.found, 181);
+ assert.equal(data[0].lines.hit, 143);
+ assert.equal(data[1].lines.found, 76);
+ assert.equal(data[1].lines.hit, 70);
+ },
+ 'verify line details': function(err, data) {
+ assert.equal(data[0].lines.details.length, 181);
+ assert.equal(data[1].lines.details.length, 76);
+ assert.deepEqual(data[0].lines.details[0], { line: 7, hit: 6 });
+ assert.deepEqual(data[0].lines.details[10], { line: 91, hit: 6 });
+
+ assert.deepEqual(data[1].lines.details[20], { line: 157, hit: 32 });
+ assert.deepEqual(data[1].lines.details[64], { line: 313, hit: 51 });
+ },
+
+ }
+}).export(module);
+
Please sign in to comment.
Something went wrong with that request. Please try again.