diff options
| author | cainus <[email protected]> | 2013-03-27 23:48:04 -0700 |
|---|---|---|
| committer | cainus <[email protected]> | 2013-03-27 23:48:04 -0700 |
| commit | 112119e43cb048cfa0dbd98d6e03833b8ca4b619 (patch) | |
| tree | 1bdb90068b87229dfa04a7a217e907d856ed0981 /lib/parser.js | |
| parent | 86f733351d4e920a44e9682f105034628f6b0b4d (diff) | |
| download | node-coveralls-112119e43cb048cfa0dbd98d6e03833b8ca4b619.tar.xz node-coveralls-112119e43cb048cfa0dbd98d6e03833b8ca4b619.zip | |
changed to use lcov input format only.
Diffstat (limited to 'lib/parser.js')
| -rw-r--r-- | lib/parser.js | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/lib/parser.js b/lib/parser.js new file mode 100644 index 0000000..83b2c3d --- /dev/null +++ b/lib/parser.js @@ -0,0 +1,131 @@ +/* +Software License Agreement (BSD License) + +Copyright (c) 2012, Dav Glass <[email protected]>. +All rights reserved. + +Redistribution and use of this software in source and binary forms, with or without modification, are +permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* The name of Dav Glass may not be used to endorse or promote products + derived from this software without specific prior + written permission of Dav Glass. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +var lcovParse = function(str) { + var data = [], item = {}; + + str = str.split('\n'); + str.forEach(function(line) { + line = line.trim(); + + var parts = line.split(':'), lines, fn; + + 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: [] + }; + } + 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: [] + }; + } + fn = parts[1].split(','); + item.functions.details.push({ + name: fn[1], + line: Number(fn[0]) + }); + break; + case 'FNDA': + 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; + 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) { + data.push(item); + item = {}; + } + }); + return data; +}; + +module.exports = lcovParse; |
