首页
/ lcov 转 Cobertura XML 转换器技术文档

lcov 转 Cobertura XML 转换器技术文档

2024-12-26 16:52:23作者:钟日瑜

1. 安装指南

1.1 通过 pip 安装

你可以使用 pip 来安装 lcov_cobertura 工具:

pip install lcov_cobertura

1.2 直接下载脚本

你也可以直接下载 lcov_cobertura.py 脚本并运行:

wget https://raw.github.com/eriwen/lcov-to-cobertura-xml/master/lcov_cobertura/lcov_cobertura.py

2. 项目的使用说明

2.1 命令行使用

安装完成后,你可以通过命令行使用 lcov_cobertura 工具将 lcov 格式的代码覆盖率报告转换为 Cobertura XML 格式。

基本命令格式如下:

lcov_cobertura lcov-file.dat

可选参数

  • -b/--base-dir:指定源代码文件所在的目录,默认为当前目录。
  • -e/--excludes:指定要排除的包的正则表达式列表,用逗号分隔。
  • -o/--output:指定生成的 Cobertura XML 文件的路径,默认为 ./coverage.xml
  • -d/--demangle:解构 C++ 函数名,需要 c++filt 工具支持。

示例:

lcov_cobertura lcov-file.dat --base-dir src/dir --excludes test.lib --output build/coverage.xml --demangle

2.2 作为 Python 模块使用

你也可以在 Python 代码中直接使用 lcov_cobertura 模块进行转换:

from lcov_cobertura import LcovCobertura

LCOV_INPUT = 'SF:foo/file.ext\nDA:1,1\nDA:2,0\nend_of_record\n'
converter = LcovCobertura(LCOV_INPUT)
cobertura_xml = converter.convert()
print(cobertura_xml)

3. 项目 API 使用文档

3.1 LcovCobertura

LcovCobertura 类是 lcov_cobertura 模块的核心类,用于将 lcov 格式的输入转换为 Cobertura XML 格式。

构造函数

LcovCobertura(lcov_input, base_dir=None, excludes=None, demangle=False)
  • lcov_input:字符串形式的 lcov 格式输入。
  • base_dir:源代码文件所在的目录,默认为 None
  • excludes:要排除的包的正则表达式列表,默认为 None
  • demangle:是否解构 C++ 函数名,默认为 False

convert 方法

convert()

将 lcov 格式的输入转换为 Cobertura XML 格式,并返回生成的 XML 字符串。

4. 项目安装方式

4.1 通过 pip 安装

推荐使用 pip 安装 lcov_cobertura 工具:

pip install lcov_cobertura

4.2 直接下载脚本

你也可以直接下载 lcov_cobertura.py 脚本并运行:

wget https://raw.github.com/eriwen/lcov-to-cobertura-xml/master/lcov_cobertura/lcov_cobertura.py

4.3 环境要求

lcov_cobertura 工具支持 Python 3.8 及以上版本。如果你需要使用 Python 2.x,请安装 lcov_cobertura 的 1.6 版本。

pip install lcov_cobertura==1.6

总结

本文档详细介绍了 lcov_cobertura 工具的安装、使用方式以及 API 文档。通过本文档,用户可以轻松地将 lcov 格式的代码覆盖率报告转换为 Cobertura XML 格式,以便在 CI 服务器上进行进一步的分析和处理。

登录后查看全文
热门项目推荐