1 个不稳定版本
0.1.0 | 2024 年 8 月 5 日 |
---|
#1799 在 解析器实现
130 每月下载量
在 v8-to-istanbul 中使用
72KB
1.5K SLoC
LCOV2
这是一个改进的、功能更强大的用于处理 LCOV 覆盖数据的库。
功能
- 读取 LCOV 文件
- 写入 LCOV 文件
- 编辑 LCOV 文件
- 将 LCOV 文件转换为 HTML
未来功能
- 合并 LCOV 文件
截图
lib.rs
:
一个用于生成和写入 LCOV 文件,并将它们转换为 HTML 格式的库。
示例
写入 LCOV 文件
此示例将写入一个包含单个记录的信息文件,该记录对应于具有两行和单个函数的测试文件。(想象 main() 有很多空行!)
use lcov::{Records, Record};
use std::fs::write;
let mut records = Records::default();
let test_record = records.get_or_insert_mut(Path::new("/path/to/test.c"));
test_record.add_function_if_not_exists(1, 32, "main");
test_record.increment_function_data("main");
test_record.add_line_if_not_exists(1);
test_record.add_line_if_not_exists(32);
test_record.increment_line(1);
test_record.increment_line(32);
write("test.info", records.to_string()).unwrap();
读取 LCOV 文件
此示例将读取信息文件。
use lcov::Records;
use std::fs::read_to_string;
let contents = read_to_string("test.info").unwrap();
let records = Records::from_str(&contents).unwrap();
生成 HTML 报告
此示例将从记录生成一个 HTML 报告,其格式非常类似于 LCOV 风格(并非完全匹配)。
use lcov::Records;
use std::fs::{read_to_string, write};
let contents = read_to_string("test.info").unwrap();
let records = Records::from_str(&contents).unwrap();
write("test.html", records.to_html().unwrap()).unwrap();
依赖项
~4MB
~66K SLoC