You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C++项目Coveralls误报未测试文件覆盖率100%,如何修正为0%?

Fixing Coveralls Showing 100% Coverage for Untested Files

This issue occurs because cpp-coveralls only processes source files with corresponding .gcda or .gcno files by default. For files without test cases, if they weren’t compiled with coverage flags or aren’t explicitly included in the tool’s scope, Coveralls might incorrectly mark them as 100% covered instead of 0%. Here’s how to resolve it:

  • Ensure all source files use coverage compilation flags
    Double-check that every source file in your project is built with -g -O0 -fprofile-arcs -ftest-coverage. Missing these flags means the file won’t generate a .gcno file (which holds code structure information), and cpp-coveralls won’t recognize it as part of the coverage report.

  • Explicitly include all source directories in cpp-coveralls
    Use the --include parameter to force the tool to scan all your source files—even those without .gcda files (no test execution data). For example, if all your code lives in the src/ directory:

    cpp-coveralls --include src/
    

    Add multiple --include flags for separate directories (e.g., --include src/utils/ --include src/core/) if needed. This ensures untested files are included in the report and marked as 0% covered.

  • Verify GCOV output first
    Before running cpp-coveralls, confirm gcov reports 0% coverage for an untested file directly. For example:

    gcov src/untested_file.cpp
    

    If gcov shows the correct 0% coverage, the problem is cpp-coveralls not including the file. If not, you missed adding coverage flags during compilation for that file.

  • Avoid accidental exclusions
    Check that --exclude flags aren’t skipping your project’s source files. Be specific with exclusions (e.g., --exclude vendor/) to ensure only third-party code is omitted.

  • Add --gcov-options for stricter parsing
    Sometimes adding --gcov-options "-l" helps ensure accurate line-by-line coverage calculation for files with no execution data:

    cpp-coveralls --include src/ --gcov-options "-l"
    

After updating these settings, re-run your tests, generate the coverage report, and upload it to Coveralls. Untested files should now correctly show 0% coverage instead of 100%.

内容的提问来源于stack exchange,提问作者Ugnius Malūkas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:22:36