LCOV 文件在“SF:”处有奇怪的路径

发布于 2025-01-16 10:22:25 字数 1804 浏览 1 评论 0原文

我正在使用 googletest 测试我的 cpp 应用程序,这些部分运行得很好。 为了构建并启动单元测试,我运行了一个小型 Powershell Skript。

cmake  -G "Unix Makefiles" -S . -B ${BUILD_PATH}
cmake --build $BUILD_PATH
Set-Location $BUILD_PATH
./UnitTests

CMakeLists.txt 如下所示:

cmake_minimum_required(VERSION 3.14)
project(exampleProject)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS --coverage)

# GoogleTest
include(FetchContent)
FetchContent_Declare(
    googletest
    URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()

# Testsources
file(GLOB_RECURSE TEST_SOURCES "./test/*.cc")

# Linking
# Add here the "inc" and "src" folder from the features
include_directories(
    "./Example/inc"
    "./Example/src"
    "./test/Example/mock"
)

add_executable(
    unittests 
    ${TEST_SOURCES}
)

target_link_libraries(
    unittests
    gtest_main
    gmock_main
)

include(GoogleTest)

# Run
gtest_discover_tests(unittests)

我的 .sh 脚本中的以下代码行在 MacO 上完美运行。

lcov --directory ${TEST_SOURCE_PATH} --capture --output-file ${LCOV_PATH_INFO} -rc lcov_branch_coverage=1

我将在另一个 Powershell 脚本中使用此代码在 Windows 计算机上执行相同的操作:

$LCOV = "C:\ProgramData\chocolatey\lib\lcov\tools\bin\lcov"
perl $LCOV --capture --directory ${TEST_SOURCE_PATH} --output-file ${LCOV_PATH_INFO} 

当我运行这些脚本时,.info 文件在 SF 标签处具有存储路径,例如: SF:C:\dev\exampleProject\build\test\CMakeFiles\unittests.dir\test\Example\C:/Strawberry/c/lib/gcc/x86_64-w64-mingw32/8.3.0/include/c++/ext/ alloc_traits.h

Powershell 的 geninfo 告诉我他无法打开这些文件,这是合乎逻辑的。

那么为什么我会变成这些奇怪的路径呢?

谢谢。最佳后卫 丹尼尔

我读了很多关于这个的东西,但我没有找到解决方案。

i am testing my cpp Application with googletest and these part runs very good.
To build and start the Unit-Tests i run a small Powershell Skript.

cmake  -G "Unix Makefiles" -S . -B ${BUILD_PATH}
cmake --build $BUILD_PATH
Set-Location $BUILD_PATH
./UnitTests

The CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.14)
project(exampleProject)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS --coverage)

# GoogleTest
include(FetchContent)
FetchContent_Declare(
    googletest
    URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()

# Testsources
file(GLOB_RECURSE TEST_SOURCES "./test/*.cc")

# Linking
# Add here the "inc" and "src" folder from the features
include_directories(
    "./Example/inc"
    "./Example/src"
    "./test/Example/mock"
)

add_executable(
    unittests 
    ${TEST_SOURCES}
)

target_link_libraries(
    unittests
    gtest_main
    gmock_main
)

include(GoogleTest)

# Run
gtest_discover_tests(unittests)

The following Line of Code in my .sh Script works on MacOs perfectly.

lcov --directory ${TEST_SOURCE_PATH} --capture --output-file ${LCOV_PATH_INFO} -rc lcov_branch_coverage=1

The same i will do on the Windows Machine with this Code in a another Powershell Script:

$LCOV = "C:\ProgramData\chocolatey\lib\lcov\tools\bin\lcov"
perl $LCOV --capture --directory ${TEST_SOURCE_PATH} --output-file ${LCOV_PATH_INFO} 

When i run these Script then the .info File has strage Path at the SF-Tag For Example:
SF:C:\dev\exampleProject\build\test\CMakeFiles\unittests.dir\test\Example\C:/Strawberry/c/lib/gcc/x86_64-w64-mingw32/8.3.0/include/c++/ext/alloc_traits.h

The geninfo at the Powershell says me that he cant open these Files, which is logical.

So why i became these stange Paths?

Thank you. Best Guards
Daniel

I read many stuff about this but i found no Solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪若未夕 2025-01-23 10:22:26

所以我找到了一个带有Powershell脚本的解决方案。

  • 首先,我创建一个 lcov.info 文件。
  • 之后,创建的文件的文件扩展名将被清除。
  • 最后我用替换命令清理了奇怪的路径。

所以效果很好。

So I found a Solution with a Powershell Script.

  • At first I create a lcov.info file.
  • After that the created File will be clean about the File Extensions.
  • At last I clean the strange Path with the replace Command.

So it works well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文