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

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

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:

  1. cmake_minimum_required(VERSION 3.14)
  2. project(test LANGUAGES CXX)
  3. set(CMAKE_AUTOUIC ON)
  4. set(CMAKE_AUTOMOC ON)
  5. set(CMAKE_AUTORCC ON)
  6. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  7. find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
  8. find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)
  9. set(CMAKE_CXX_STANDARD 20)
  10. set(UNITTESTS_SOURCES
  11. main.cpp
  12. )
  13. include(FetchContent)
  14. FetchContent_Declare(catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v3.3.2)
  15. FetchContent_MakeAvailable(catch2)
  16. qt_add_executable(test ${UNITTESTS_SOURCES})
  17. target_link_libraries(test PUBLIC Catch2::Catch2 Qt::Core Qt::Gui)
  18. install(TARGETS test
  19. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  20. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  21. )

main.cpp

  1. #include <catch2/catch_test_macros.hpp>
  2. #include <catch2/catch_session.hpp>
  3. int main( int argc, char* argv[] ) {
  4. int result = Catch::Session().run( argc, argv );
  5. std::fflush(stdout);
  6. return result;
  7. }
  8. TEST_CASE("hello from catch")
  9. {
  10. CHECK(false);
  11. }

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:

  1. cmake_minimum_required(VERSION 3.14)
  2. project(test LANGUAGES CXX)
  3. set(CMAKE_AUTOUIC ON)
  4. set(CMAKE_AUTOMOC ON)
  5. set(CMAKE_AUTORCC ON)
  6. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  7. find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
  8. find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui)
  9. set(CMAKE_CXX_STANDARD 20)
  10. set(UNITTESTS_SOURCES
  11. main.cpp
  12. )
  13. include(FetchContent)
  14. FetchContent_Declare(catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2.git GIT_TAG v3.3.2)
  15. FetchContent_MakeAvailable(catch2)
  16. qt_add_executable(test ${UNITTESTS_SOURCES})
  17. target_link_libraries(test PUBLIC Catch2::Catch2 Qt::Core Qt::Gui)
  18. install(TARGETS test
  19. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  20. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  21. )

main.cpp

  1. #include &lt;catch2/catch_test_macros.hpp&gt;
  2. #include &lt;catch2/catch_session.hpp&gt;
  3. int main( int argc, char* argv[] ) {
  4. int result = Catch::Session().run( argc, argv );
  5. std::fflush(stdout);
  6. return result;
  7. }
  8. TEST_CASE(&quot;hello from catch&quot;)
  9. {
  10. CHECK(false);
  11. }

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:

确定