per*_*iex 5 c++ code-coverage gcov lcov
我的代码中包含一些日志记录宏,内容如下:
#define LOG_MSG (pri, msg, ... ) \
if (pri > PriorityLevel ) \
printf( msg, ##\__VA_ARGS__);
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用LCOV_EXCL_START,LCOV_EXCL_STOP或LCOV_EXCL_LINE来禁止分支。但这仅在我将其调用LOG_MSG的每个位置添加时才起作用:
LOG_MSG(ERROR, "An Error has occurred\n");//LCOV_EXCL_LINE
我想在宏中包含该注释,但是如果我将其放在其中,LCOV将无法识别它。例如,此代码仍会产生分支。
#define LOG_MSG (pri, msg, ... ) \
if (pri > PriorityLevel ) \
printf( msg, ##\__VA_ARGS__);//LCOV_EXCL_LINE
Run Code Online (Sandbox Code Playgroud)
有没有一种好的方法可以抑制宏本身中的这些分支?
为什么不把宏变成函数呢?
喜欢:
template <typename ... Ts>
void LOG_MSG(int priority, const std::string& message, Ts&&...ts)
{
if (priority > PriorityLevel)
printf(message.c_str(), std::forward<Ts>(ts)...);
// Or more appropriate stuff
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3311 次 |
| 最近记录: |