Lcov-parse的使用尚不清楚

问题描述 投票:0回答:1

我找到了lcov-parse工具来解析lcov信息文件。我怎么能用它在此链接中解释的用法:https://github.com/davglass/lcov-parse/blob/master/README.md不清楚。我需要知道在哪里可以使用代码来解析和提取信息。

code-coverage gcov lcov
1个回答
1
投票

README.md链接的Usage部分中描述的代码说明了如何在javascript中调用该工具(我添加了额外的注释):

// 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
});

要在命令行上运行和输出,Cli Usage部分中的描述对我来说不起作用,但是可以在bin目录下的项目的github页面中看到可执行代码的示例:

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

该文件的内容是:

#!/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));
});

data在这里再次解析为JSON对象的lcov文件。

要运行它:

1)首先使用npm安装lcov-parse工具:

npm install lcov-parse

在一个空目录中,这将创建一些文件,其中一个是上面的示例javascript,用于在命令行上运行该工具:

./node_modules/l co V-parse/斌/处理.就是

2)脚本可以像这样运行:

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

例如。在lcov-parse的覆盖文件上测试它:

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

3)JSON.stringify的默认格式很难通过眼睛阅读,可以通过添加间距参数(例如2个空格)来改进:

console.log(JSON.stringify(data, null, 2));
© www.soinside.com 2019 - 2024. All rights reserved.