Dav*_*ria 2 c++ code-coverage gcovr
我在一个非源构建上运行 gcovr (3.3),例如:
gcovr --root=/path/to/source --object-directory=/path/to/build
现在我想从报告中排除两个不同的内容:
1) 任何.cpp名称中包含“Test”的文件
--exclude='.*Test.*' 似乎不起作用
2)目录中的所有源文件(比如/path/to/source/MyModule/)
--exclude='/path/to/source/MyModule/.*' 似乎不起作用。
--exclude-directories='/path/to/source/MyModule' 似乎也不起作用。
我的问题
a)什么是--exclude-directories因为看起来你(应该)能够排除一个传递给正确正则表达式的目录--exclude?
b) 关于为什么--excludes 不能按预期工作的任何建议?也许这些不是正确的正则表达式类型/风格?
这两个选项都没有很好的文档记录,所以主要的知识来源是源代码。
a) 什么是 --exclude-directories ,因为您似乎(应该)能够使用传递给 --exclude 的正确正则表达式排除目录?
--exclude-directoriesgcovr 用来按名称跳过目录的选项,而不是完整路径。如果您检查gcovr的源代码,则可以对其进行验证。魔术是在def link_walker(path)函数中完成的:
for root, dirs, files in os.walk(
os.path.abspath(path), followlinks=True
):
for exc in options.exclude_dirs:
for d in dirs:
m = exc.search(d)
Run Code Online (Sandbox Code Playgroud)
根据os.walk文档,dirs是子目录名称的列表。例如跳过所有以MyModuse开头的目录--exclude-directories='MyMod.*'。
b) 关于为什么 --excludes 不能按预期工作的任何建议?也许这些不是正确的正则表达式类型/风格?
你的正则表达式是正确的。这是典型的 Python 正则表达式。
要了解--exclude选项中发生了什么,启用-v输出很有用。启用此选项后,输出应该有很多行:
currdir /cygdrive/f/test/path/to/source
gcov_fname myfile.cpp.gcov
[' -', ' 0', 'Source', 'myfile.cpp\n']
source_fname /cygdrive/f/test/path/to/source/myfile.gcda
root /cygdrive/f/test/path/to/source
fname /cygdrive/f/test/path/to/source/myfile.cpp
Parsing coverage data for file /cygdrive/f/test/path/to/source/myfile.cpp
Run Code Online (Sandbox Code Playgroud)
此输出由def process_gcov_data(data_fname, covdata, source_fname, options)函数产生。如果您检查源代码,您将看到以下内容:
for exc in options.exclude:
if (filtered_fname is not None and exc.match(filtered_fname)) or \
exc.match(fname) or \
exc.match(os.path.abspath(fname))
Run Code Online (Sandbox Code Playgroud)
排除过滤器适用于fname上面打印的内容。这是绝对文件路径。它也适用于所有具有覆盖数据的文件。如果文件被排除,以下行应该在输出中(-v需要选项):
Excluding coverage data for file /cygdrive/f/test/path/to/source/myfile.cpp
Run Code Online (Sandbox Code Playgroud)