Codecov 中的路径修复:有些文件有效,有些无效

Path fixing in Codecov: some files work others not

我有一个项目可以随意使用 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) 但我无法让它在另一个源文件上工作 (src/version/version.cpp ),即使 codecov.io 正确显示路径和上传的 codecov.xml 文件中的路径(我在 CI 运行时将其打印到控制台,因此也可以在 GitHub 动作)在概念上看起来完全一样:

(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>

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

在 codecov.io 中,单击文件 src/version/version.cpp 出现错误

GitHub API: Not Found

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

fixes:
   - "test_repository/::"

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

Well this is embarassing, looks like we had an error.

我不依赖此功能对我的所有文件起作用,但这种行为(文件之间的差异)对我来说很奇怪。有什么想法吗?

这里是来自 Codecov 的 Tom。我想你可能需要做

fixes:
  - "::/test_repository"

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

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

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