gcovr 排除问题
Trouble with gcovr exclusions
我是 运行 gcovr (3.3) 的源代码构建,例如:
gcovr --root=/path/to/source --object-directory=/path/to/build
现在我想从报告中排除两个不同的东西:
1) 名称中包含 "Test" 的任何 .cpp
个文件
--exclude='.*Test.*'
好像不行
2) 目录中的所有源文件(比如 /path/to/source/MyModule/
)
--exclude='/path/to/source/MyModule/.*'
好像不行。
--exclude-directories='/path/to/source/MyModule'
好像也不行。
我的问题
a) 什么是 --exclude-directories
,因为看起来您(应该)能够使用传递给 --exclude
的正确正则表达式排除目录?
b) 关于为什么 --exclude
没有按预期工作有什么建议吗?也许这些不是正则表达式的正确kind/style?
这两个选项都没有很好的文档记录,因此主要的知识来源是 source code。
a) what is --exclude-directories for since it seems like you (should) be able to exclude a directory with the right regex passed to --exclude?
--exclude-directories
gcovr 使用的选项通过名称跳过目录,而不是完整路径。如果你查看 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)
根据 os.walk
文档,dirs
是子目录名称的列表。例如。跳过所有以 MyMod
开头的目录使用 --exclude-directories='MyMod.*'
.
b) Any suggestions about why the --excludes do not work as expected? Perhaps these are not the right kind/style of regular expressions?
您的正则表达式是正确的。这是典型的 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
此输出由 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))
排除过滤器适用于上面打印的 fname
。这是绝对文件路径。它还适用于所有具有覆盖率数据的文件。如果文件被排除,则输出中应包含以下行(需要 -v
选项):
Excluding coverage data for file /cygdrive/f/test/path/to/source/myfile.cpp
我是 运行 gcovr (3.3) 的源代码构建,例如:
gcovr --root=/path/to/source --object-directory=/path/to/build
现在我想从报告中排除两个不同的东西:
1) 名称中包含 "Test" 的任何 .cpp
个文件
--exclude='.*Test.*'
好像不行
2) 目录中的所有源文件(比如 /path/to/source/MyModule/
)
--exclude='/path/to/source/MyModule/.*'
好像不行。
--exclude-directories='/path/to/source/MyModule'
好像也不行。
我的问题
a) 什么是 --exclude-directories
,因为看起来您(应该)能够使用传递给 --exclude
的正确正则表达式排除目录?
b) 关于为什么 --exclude
没有按预期工作有什么建议吗?也许这些不是正则表达式的正确kind/style?
这两个选项都没有很好的文档记录,因此主要的知识来源是 source code。
a) what is --exclude-directories for since it seems like you (should) be able to exclude a directory with the right regex passed to --exclude?
--exclude-directories
gcovr 使用的选项通过名称跳过目录,而不是完整路径。如果你查看 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)
根据 os.walk
文档,dirs
是子目录名称的列表。例如。跳过所有以 MyMod
开头的目录使用 --exclude-directories='MyMod.*'
.
b) Any suggestions about why the --excludes do not work as expected? Perhaps these are not the right kind/style of regular expressions?
您的正则表达式是正确的。这是典型的 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
此输出由 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))
排除过滤器适用于上面打印的 fname
。这是绝对文件路径。它还适用于所有具有覆盖率数据的文件。如果文件被排除,则输出中应包含以下行(需要 -v
选项):
Excluding coverage data for file /cygdrive/f/test/path/to/source/myfile.cpp