0

我有一个项目可以随意使用 C++ 测试覆盖率。(https://github.com/adomasbaliuka/test_repository,问题指的是提交 58e2802f76e8eb7819209c9d518b0ffe76690d15 和 ca36a4fd0e38bc47204a155614c498936d43dc90)

这个问题涉及 GitHub 和 Codecov.io,所以也许我应该请求他们的支持,但是 StackOverflor 有这些东西的标签,所以我认为没关系。

codecov.io 的覆盖范围正在发挥作用( https://app.codecov.io/gh/adomasbaliuka/test_repository )。但是,我想看看实际的源代码和行覆盖率来测试 codecov.io 的这个特性。它在我test/test_main.cpp的一个文件(我的 CI 运行,因此它们也可以在 GitHub Actions 中查看)在概念上看起来完全相同:src/version/version.cppcodecov.xml

codecov.xml文件内容:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE coverage SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-04.dtd'>
<coverage line-rate="0.7613636363636364" branch-rate="0.33962264150943394" lines-covered="67" lines-valid="88" branches-covered="36" branches-valid="106" complexity="0.0" timestamp="1631309448" version="gcovr 4.2">
  <sources>
    <source>../../</source>
  </sources>
  <packages>
    <package name="test_repository.build._deps.googletest-src.googletest.include.gtest" line-rate="0.2857142857142857" branch-rate="0.0" complexity="0.0">
      <classes>
        <class name="gtest_h" filename="test_repository/build/_deps/googletest-src/googletest/include/gtest/gtest.h" line-rate="0.2857142857142857" branch-rate="0.0" complexity="0.0">
          <methods/>
          <lines>
            <line number="427" hits="0" branch="false"/>
            <line number="435" hits="0" branch="false"/>
            <line number="440" hits="0" branch="false"/>
            <line number="441" hits="0" branch="false"/>
            <line number="522" hits="0" branch="false"/>
            <line number="2489" hits="2" branch="false"/>
            <line number="2490" hits="2" branch="false"/>
          </lines>
        </class>
      </classes>
    </package>
    <package name="test_repository.build._deps.googletest-src.googletest.include.gtest.internal" line-rate="0.85" branch-rate="0.2" complexity="0.0">
      <classes>
        <class name="gtest-internal_h" filename="test_repository/build/_deps/googletest-src/googletest/include/gtest/internal/gtest-internal.h" line-rate="0.8947368421052632" branch-rate="0.2" complexity="0.0">
          <methods/>
          <lines>
            <line number="454" hits="8" branch="false"/>
            <line number="461" hits="4" branch="false"/>
            <line number="472" hits="4" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="493" hits="4" branch="false"/>
            <line number="494" hits="4" branch="false"/>
            <line number="506" hits="16" branch="false"/>
            <line number="508" hits="16" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="521" hits="4" branch="false"/>
            <line number="525" hits="4" branch="false"/>
            <line number="527" hits="4" branch="false"/>
            <line number="529" hits="4" branch="true" condition-coverage="33% (2/6)">
              <conditions>
                <condition number="0" type="jump" coverage="33%"/>
              </conditions>
            </line>
            <line number="532" hits="0" branch="true" condition-coverage="0% (0/10)">
              <conditions>
                <condition number="0" type="jump" coverage="0%"/>
              </conditions>
            </line>
            <line number="534" hits="4" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="542" hits="4" branch="false"/>
            <line number="546" hits="4" branch="false"/>
            <line number="548" hits="4" branch="false"/>
            <line number="550" hits="4" branch="true" condition-coverage="33% (2/6)">
              <conditions>
                <condition number="0" type="jump" coverage="33%"/>
              </conditions>
            </line>
            <line number="553" hits="0" branch="true" condition-coverage="0% (0/10)">
              <conditions>
                <condition number="0" type="jump" coverage="0%"/>
              </conditions>
            </line>
            <line number="555" hits="4" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
          </lines>
        </class>
        <class name="gtest-port_h" filename="test_repository/build/_deps/googletest-src/googletest/include/gtest/internal/gtest-port.h" line-rate="0.0" branch-rate="0.0" complexity="0.0">
          <methods/>
          <lines>
            <line number="974" hits="0" branch="false"/>
          </lines>
        </class>
      </classes>
    </package>
    <package name="test_repository.test_repository.src.version" line-rate="0.717391304347826" branch-rate="0.4107142857142857" complexity="0.0">
      <classes>
        <class name="version_cpp" filename="test_repository/test_repository/src/version/version.cpp" line-rate="0.717391304347826" branch-rate="0.4107142857142857" complexity="0.0">
          <methods/>
          <lines>
            <line number="22" hits="3" branch="false"/>
            <line number="24" hits="6" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="25" hits="6" branch="false"/>
            <line number="26" hits="3" branch="false"/>
            <line number="27" hits="6" branch="true" condition-coverage="66% (4/6)">
              <conditions>
                <condition number="0" type="jump" coverage="66%"/>
              </conditions>
            </line>
            <line number="28" hits="3" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="30" hits="6" branch="false"/>
            <line number="34" hits="1" branch="false"/>
            <line number="36" hits="1" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="37" hits="1" branch="false"/>
            <line number="40" hits="1" branch="false"/>
            <line number="42" hits="1" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="43" hits="1" branch="false"/>
            <line number="46" hits="1" branch="false"/>
            <line number="48" hits="2" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="50" hits="1" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="52" hits="0" branch="false"/>
            <line number="56" hits="2" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="58" hits="1" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="59" hits="0" branch="false"/>
            <line number="62" hits="1" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="63" hits="1" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="64" hits="0" branch="false"/>
            <line number="66" hits="1" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="71" hits="1" branch="false"/>
            <line number="73" hits="2" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="75" hits="1" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="77" hits="0" branch="false"/>
            <line number="81" hits="2" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="83" hits="1" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="84" hits="1" branch="false"/>
            <line number="87" hits="0" branch="true" condition-coverage="0% (0/2)">
              <conditions>
                <condition number="0" type="jump" coverage="0%"/>
              </conditions>
            </line>
            <line number="89" hits="0" branch="true" condition-coverage="0% (0/2)">
              <conditions>
                <condition number="0" type="jump" coverage="0%"/>
              </conditions>
            </line>
            <line number="90" hits="0" branch="false"/>
            <line number="92" hits="0" branch="true" condition-coverage="0% (0/2)">
              <conditions>
                <condition number="0" type="jump" coverage="0%"/>
              </conditions>
            </line>
            <line number="97" hits="1" branch="false"/>
            <line number="99" hits="2" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="101" hits="1" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="103" hits="0" branch="false"/>
            <line number="107" hits="2" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="109" hits="1" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="110" hits="1" branch="false"/>
            <line number="113" hits="0" branch="true" condition-coverage="0% (0/2)">
              <conditions>
                <condition number="0" type="jump" coverage="0%"/>
              </conditions>
            </line>
            <line number="115" hits="0" branch="true" condition-coverage="0% (0/2)">
              <conditions>
                <condition number="0" type="jump" coverage="0%"/>
              </conditions>
            </line>
            <line number="116" hits="0" branch="false"/>
            <line number="118" hits="0" branch="true" condition-coverage="0% (0/2)">
              <conditions>
                <condition number="0" type="jump" coverage="0%"/>
              </conditions>
            </line>
          </lines>
        </class>
      </classes>
    </package>
    <package name="test_repository.test_repository.tests" line-rate="1.0" branch-rate="0.5" complexity="0.0">
      <classes>
        <class name="test_main_cpp" filename="test_repository/test_repository/tests/test_main.cpp" line-rate="1.0" branch-rate="0.5" complexity="0.0">
          <methods/>
          <lines>
            <line number="12" hits="2" branch="false"/>
            <line number="14" hits="2" branch="false"/>
            <line number="15" hits="2" branch="false"/>
            <line number="18" hits="8" branch="false"/>
            <line number="21" hits="2" branch="false"/>
            <line number="22" hits="2" branch="true" condition-coverage="50% (1/2)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="23" hits="2" branch="false"/>
            <line number="24" hits="2" branch="false"/>
            <line number="26" hits="8" branch="false"/>
            <line number="27" hits="2" branch="true" condition-coverage="50% (2/4)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="28" hits="2" branch="true" condition-coverage="50% (2/4)">
              <conditions>
                <condition number="0" type="jump" coverage="50%"/>
              </conditions>
            </line>
            <line number="30" hits="2" branch="false"/>
            <line number="31" hits="2" branch="false"/>
            <line number="32" hits="2" branch="false"/>
            <line number="33" hits="2" branch="false"/>
          </lines>
        </class>
      </classes>
    </package>
  </packages>
</coverage>

特别是其中文件的路径xmltest_repository/tests/test_main.cpptest_repository/src/version/version.cpp。我完全不明白 codecov.io 可能在那里看到的问题或差异。

在 codecov.io 中,单击文件src/version/version.cpp会给我一个错误

GitHub API:未找到

我尝试按照 codecov.io 的建议进行一些“路径修复”,这意味着包括一个顶级文件codecov.yml。我把这个文件里面

fixes:
   - "test_repository/::"

我假设用路径中的“无”替换存储库的名称。结果是第一个文件仍然有效,而第二个文件的错误消息变为

好吧,这很尴尬,看起来我们有一个错误。

我不依赖于在我的所有文件上使用此功能,但是这种行为(文件之间的差异)对我来说很奇怪。有任何想法吗?

4

2 回答 2

1

答案是有问题的文件甚至根本不在存储库中。它由 CMake 生成(“配置”),以包含从 git 信息中提取的当前版本。

事后看来,我的问题真的很愚蠢,我很抱歉浪费了任何人的时间。不幸的是,这个问题中可能没有任何可以让您学习的东西。

于 2021-09-11T13:34:30.770 回答
1

来自 Codecov 的汤姆在这里。我想你可能需要做

fixes:
  - "::/test_repository"

但老实说,我认为您根本不需要路径修复。

于 2021-09-10T22:47:01.280 回答