R.Omar
R.Omar

Reputation: 655

Lcov-parse usage is not clear

I found lcov-parse tool to parse lcov info file. How could I use it. The usage explained in this link: https://github.com/davglass/lcov-parse/blob/master/README.md is not clear. I need to know where could I use the code to parse and extract info.

Upvotes: 0

Views: 1183

Answers (1)

Smoguez
Smoguez

Reputation: 56

The code described in the Usage section in the README.md link is illustrating how to call the tool within javascript (I have added extra comments):

// Include the lcov-parse dependency, installed via npm
var parse = require('lcov-parse');

// Specify the path to the file to parse,
// the file contents are parsed into a JSON object, "data"
parse('./path/to/file.info', function(err, data) {
    // process the data here
    // e.g. write out to a string
});

To run and output on the command-line, the description in the Cli Usage section did not work for me, however an example of executable code may be seen in the project's github page under the bin directory:

https://github.com/davglass/lcov-parse/blob/master/bin/cli.js

The contents of this file are:

#!/usr/bin/env node
var lcov = require('../lib/index.js');
var file = process.argv[2];

lcov(file, function(err, data) {
    if (err) {
      return console.error(err)
    }

    console.log(JSON.stringify(data));
});

Again data here is the lcov file parsed into a JSON object.

To run it:

1) First install the lcov-parse tool with npm:

npm install lcov-parse

In an empty directory this will create a few files, one of which is the example javascript above for running the tool on the command-line:

./node_modules/lcov-parse/bin/cli.js

2) The script can be run like this:

./node_modules/lcov-parse/bin/cli.js ./path/to/lcovfile

E.g. test it on the coverage file of lcov-parse:

./node_modules/lcov-parse/bin/cli.js ./node_modules/lcov-parse/coverage/lcov.info

3) The default formatting of JSON.stringify is hard to read by eye, it can be improved by adding a spacing parameter (e.g. 2 spaces):

console.log(JSON.stringify(data, null, 2));

Upvotes: 2

Related Questions