androidc++catch2

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?


Solution

  • Ohh, the answer is so simple.

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