]>
code.delx.au - gnu-emacs-elpa/blob - test/parse-coverage.js
3 // Copyright (C) 2014-2015 Free Software Foundation, Inc.
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 var padRight = function (value
, padding
) {
21 return value
+ new Array(Math
.max(0, padding
- String(value
).length
) + 1).join(' ');
24 var formatSourceFile = function (sourceFile
) {
25 var sourceLines
= sourceFile
.source
.split('\n');
27 padRight('Hits', 5) + ' | Source',
28 new Array(80 + 1).join('-')
31 var linesHittable
= 0;
32 results
= results
.concat(sourceFile
.coverage
.map(function (hits
, index
) {
33 var hitsValue
= hits
=== null ? 'N/A' : hits
;
34 var column
= hits
=== 0 ? '~' : '|';
41 return padRight(hitsValue
, 5) + ' ' + column
+ ' ' + sourceLines
[index
];
43 results
= results
.concat([
45 'Lines: ' + linesHit
+ ' / ' + linesHittable
,
46 'Coverage: ' + (Math
.round(linesHit
/ linesHittable
* 10000) / 100) + '%'
48 return results
.join('\n');
51 var format = function (json
) {
52 return json
.source_files
.map(formatSourceFile
).join('\n');
55 var read = function () {
58 process
.stdin
.setEncoding('utf8');
60 process
.stdin
.on('readable', function () {
61 var chunk
= process
.stdin
.read();
67 process
.stdin
.on('end', function () {
68 console
.log(format(JSON
.parse(whole
)));