From cce340102f10c1e56535864346412a0386402059 Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sun, 5 May 2024 15:00:30 -0500 Subject: [PATCH] Update catch2 interface to support new ansi line wrapping --- include/libassert/assert-catch2.hpp | 15 +++++++++++---- tests/CMakeLists.txt | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/libassert/assert-catch2.hpp b/include/libassert/assert-catch2.hpp index 2bb2115a..1f3770ec 100644 --- a/include/libassert/assert-catch2.hpp +++ b/include/libassert/assert-catch2.hpp @@ -5,6 +5,7 @@ #include #include +#include #if defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL != 0 #error "Libassert integration does not work with MSVC's non-conformant preprocessor. /Zc:preprocessor must be used." @@ -13,16 +14,22 @@ #define ASSERT(...) do { try { LIBASSERT_ASSERT(__VA_ARGS__); SUCCEED(); } catch(std::exception& e) { FAIL(e.what()); } } while(false) namespace libassert::detail { + // catch line wrapping can't handle ansi sequences before 3.6 https://github.com/catchorg/Catch2/issues/2833 + inline constexpr bool use_color = CATCH_VERSION_MAJOR > 3 || (CATCH_VERSION_MAJOR == 3 && CATCH_VERSION_MINOR >= 6); + inline void catch2_failure_handler(const assertion_info& info) { + if(use_color) { + enable_virtual_terminal_processing_if_needed(); + } + auto scheme = use_color ? color_scheme::ansi_rgb : color_scheme::blank; std::string message = std::string(info.action()) + " at " + info.location() + ":"; if(info.message) { message += " " + *info.message; } message += "\n"; - message += info.statement(color_scheme::blank) - + info.print_binary_diagnostics(0, color_scheme::blank) - + info.print_extra_diagnostics(0, color_scheme::blank); - // catch line wrapping has issues with ansi sequences https://github.com/catchorg/Catch2/issues/2833 + message += info.statement(scheme) + + info.print_binary_diagnostics(CATCH_CONFIG_CONSOLE_WIDTH, scheme) + + info.print_extra_diagnostics(CATCH_CONFIG_CONSOLE_WIDTH, scheme); throw std::runtime_error(std::move(message)); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e3100d54..ff98ff9f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -81,7 +81,7 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) Catch2 GIT_SHALLOW TRUE GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG 8ac8190e494a381072c89f5e161b92a08d98b37b # v3.5.3 + GIT_TAG 4e8d92bf02f7d1c8006a0e7a5ecabd8e62d98502 # v3.6.0 ) FetchContent_MakeAvailable(Catch2)