[Pkg-javascript-commits] [node-lcov-parse] 06/45: Fixes #1 - Added Branch parsing support
Bastien Roucariès
rouca at moszumanska.debian.org
Wed Sep 6 09:46:15 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-lcov-parse.
commit ff0e6a75986275d1c55391434c03ad498efc7ada
Author: Dav Glass <davglass at gmail.com>
Date: Tue Jan 15 15:16:07 2013 -0600
Fixes #1 - Added Branch parsing support
---
lib/index.js | 39 ++++++++++++++++++++++++++++++---------
tests/info/parts.info | 26 ++++++++++++++++++++++++++
tests/parse.js | 15 +++++++++++----
3 files changed, 67 insertions(+), 13 deletions(-)
diff --git a/lib/index.js b/lib/index.js
index ad11312..66a4bbc 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,17 +1,16 @@
var fs = require('fs'),
path = require('path'),
-
exists = fs.exists || path.exists;
-var results = {};
-
var walkFile = function(str, cb) {
- var data = [];
+ var data = [], item = {};
+
str = str.split('\n');
- var item = {};
str.forEach(function(line) {
line = line.trim();
- var parts = line.split(':');
+
+ var parts = line.split(':'), lines, fn;
+
switch (parts[0].toUpperCase()) {
case 'TN':
item.title = parts[1].trim();
@@ -39,7 +38,7 @@ var walkFile = function(str, cb) {
details: []
};
}
- var lines = parts[1].split(',');
+ lines = parts[1].split(',');
item.lines.details.push({
line: Number(lines[0]),
hit: Number(lines[1])
@@ -53,14 +52,14 @@ var walkFile = function(str, cb) {
details: []
};
}
- var fn = parts[1].split(',');
+ fn = parts[1].split(',');
item.functions.details.push({
name: fn[1],
line: Number(fn[0])
});
break;
case 'FNDA':
- var fn = parts[1].split(',');
+ 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]);
@@ -68,6 +67,28 @@ var walkFile = function(str, cb) {
}
});
break;
+ case 'BRDA':
+ if (!item.branches) {
+ item.branches = {
+ hit: 0,
+ found: 0,
+ details: []
+ };
+ }
+ fn = parts[1].split(',');
+ item.branches.details.push({
+ line: Number(fn[0]),
+ block: Number(fn[1]),
+ branch: Number(fn[2]),
+ taken: ((fn[3] === '-') ? 0 : Number(fn[3]))
+ });
+ break;
+ case 'BRF':
+ item.branches.found = Number(parts[1]);
+ break;
+ case 'BRH':
+ item.branches.hit = Number(parts[1]);
+ break;
}
if (line.indexOf('end_of_record') > -1) {
diff --git a/tests/info/parts.info b/tests/info/parts.info
index d56d04a..4c1298a 100644
--- a/tests/info/parts.info
+++ b/tests/info/parts.info
@@ -366,4 +366,30 @@ DA:353,6
LF:76
LH:70
+
+BRDA:3,1,0,1
+BRDA:3,1,1,0
+BRDA:13,2,0,2
+BRDA:13,2,1,2
+BRDA:13,2,2,2
+BRDA:13,2,3,2
+BRDA:13,2,4,2
+BRDA:13,2,5,2
+BRDA:13,2,6,257
+BRDA:13,2,7,46
+BRDA:13,2,8,46
+BRDA:33,3,0,2
+BRDA:33,3,1,255
+BRDA:47,4,0,2
+BRDA:47,4,1,44
+BRDA:63,5,0,46
+BRDA:63,5,1,542
+BRDA:63,6,0,588
+BRDA:63,6,1,51
+BRDA:71,7,0,2
+BRDA:71,7,1,368
+BRDA:82,8,0,1
+BRDA:82,8,1,-
+BRF:23
+BRH:22
end_of_record
diff --git a/tests/parse.js b/tests/parse.js
index adffae1..6f6176b 100644
--- a/tests/parse.js
+++ b/tests/parse.js
@@ -1,11 +1,10 @@
var vows = require('vows'),
path = require('path'),
assert = require('assert'),
- parse = require(path.join(__dirname, '../lib')),
+ parse = require('../lib'),
yuiFile = path.join(__dirname, 'info/parts.info');
-
-vows.describe('Test Loading and Bindings').addBatch({
+var tests = {
'Should be loaded': {
topic: function() {
return parse;
@@ -52,6 +51,12 @@ vows.describe('Test Loading and Bindings').addBatch({
assert.equal(data[1].functions.found, 17);
assert.equal(data[1].functions.hit, 17);
},
+ 'verify number of branches': function(err, data) {
+ assert.equal(data[1].branches.found, 23);
+ assert.equal(data[1].branches.hit, 22);
+ assert.equal(data[1].branches.found, data[1].branches.details.length);
+ assert.equal(data[1].branches.details[data[1].branches.details.length - 1].taken, 0);
+ },
'verify function details': function(err, data) {
assert.equal(data[0].functions.details.length, 29);
assert.equal(data[1].functions.details.length, 17);
@@ -81,5 +86,7 @@ vows.describe('Test Loading and Bindings').addBatch({
},
}
-}).export(module);
+};
+
+vows.describe('Test Loading and Bindings').addBatch(tests)['export'](module);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-lcov-parse.git
More information about the Pkg-javascript-commits
mailing list