如何使Catch2版本3的测试在Android设备上使用logcat?

huangapple go评论67阅读模式
英文:

How to make Catch2 version 3 tests use logcat on android devices?

问题

I have a cmake + Qt based project, it compiles fine and runs on my android device. i see stuff printed to logcat (inside Qt Creator), when using qDebug. But there is no output from Catch2. I suspect, that it keeps printing to stdout or stderr, which is not visible.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)

project(test LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)

set(CMAKE_CXX_STANDARD 20)

set(UNITTESTS_SOURCES
    main.cpp
)

include(FetchContent)
FetchContent_Declare(catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v3.3.2)
FetchContent_MakeAvailable(catch2)

qt_add_executable(test ${UNITTESTS_SOURCES})
target_link_libraries(test PUBLIC Catch2::Catch2 Qt::Core Qt::Gui)


install(TARGETS test
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

main.cpp

#include <catch2/catch_test_macros.hpp>
#include <catch2/catch_session.hpp>

int main( int argc, char* argv[] ) {
    int result = Catch::Session().run( argc, argv );
    std::fflush(stdout);
    return result;
}

TEST_CASE("hello from catch")
{
    CHECK(false);
}

I've seen, that there are some logcat related classes in <catch2/internal/catch_config_android_logwrite.hpp>, but breakpoints are not hit. I'm linking to qt, but in a minimal example nothing from qt is called.

How can I make it such, that Catch2 prints its outputs to logcat?

英文:

I have a cmake + Qt based project, it compiles fine and runs on my android device. i see stuff printed to logcat (inside Qt Creator), when using qDebug. But there is no output from Catch2. I suspect, that it keeps printing to stdout or stderr, which is not visible.

CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)

project(test LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)

set(CMAKE_CXX_STANDARD 20)

set(UNITTESTS_SOURCES
    main.cpp
)

include(FetchContent)
FetchContent_Declare(catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v3.3.2)
FetchContent_MakeAvailable(catch2)

qt_add_executable(test ${UNITTESTS_SOURCES})
target_link_libraries(test PUBLIC Catch2::Catch2 Qt::Core Qt::Gui)


install(TARGETS test
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

main.cpp

#include &lt;catch2/catch_test_macros.hpp&gt;
#include &lt;catch2/catch_session.hpp&gt;

int main( int argc, char* argv[] ) {
    int result = Catch::Session().run( argc, argv );
    std::fflush(stdout);
    return result;
}

TEST_CASE(&quot;hello from catch&quot;)
{
    CHECK(false);
}

I've seen, that there are some logcat related classes in <catch2/internal/catch_config_android_logwrite.hpp>, but breakpoints are not hit.
I'm linking to qt, but in a minimal example nothing from qt is called.

How can I make it such, that Catch2 prints its outputs to logcat?

答案1

得分: 0

你需要使用-o %debug作为命令行参数运行测试。

英文:

Ohh, the answer is so simple.

You have to run the test with -o %debug, that is, add that as command line parameters.

huangapple
  • 本文由 发表于 2023年5月14日 20:32:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247500.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定