From 45a5936fce414dc0fbfcd62e787dce00476d2a04 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 30 Jun 2024 20:02:44 +0700 Subject: [PATCH] feat: allow stacking sections (#117) * feat: indent messages inside section * test: test section message indentation --- CMakeLists.txt | 5 +++++ cmake/Assertion.cmake | 2 ++ test/SectionCreation.cmake | 13 +++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 test/SectionCreation.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 034d05d..9fcc0bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,11 @@ if(ASSERT_ENABLE_TESTS) NAME "internal assertion message formatting" COMMAND "${CMAKE_COMMAND}" -P ${CMAKE_CURRENT_SOURCE_DIR}/test/InternalFormatMessage.cmake) + + add_test( + NAME "section creation" + COMMAND "${CMAKE_COMMAND}" + -P ${CMAKE_CURRENT_SOURCE_DIR}/test/SectionCreation.cmake) endif() if(ASSERT_ENABLE_INSTALL) diff --git a/cmake/Assertion.cmake b/cmake/Assertion.cmake index ed85e14..6b6fd60 100644 --- a/cmake/Assertion.cmake +++ b/cmake/Assertion.cmake @@ -259,6 +259,7 @@ endfunction() # macro to end the test section. macro(section NAME) message(CHECK_START "${NAME}") + list(APPEND CMAKE_MESSAGE_INDENT " ") endmacro() # Ends the current test section. @@ -267,5 +268,6 @@ endmacro() # # This macro ends the current test section and marks it as passed. macro(endsection) + list(POP_BACK CMAKE_MESSAGE_INDENT) message(CHECK_PASS passed) endmacro() diff --git a/test/SectionCreation.cmake b/test/SectionCreation.cmake new file mode 100644 index 0000000..eb5fa3c --- /dev/null +++ b/test/SectionCreation.cmake @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.5) + +find_package(Assertion REQUIRED PATHS ${CMAKE_CURRENT_LIST_DIR}/../cmake) + +section("first section") + assert(CMAKE_MESSAGE_INDENT STREQUAL " ") + + section("second section") + assert(CMAKE_MESSAGE_INDENT STREQUAL " ; ") + endsection() + + assert(CMAKE_MESSAGE_INDENT STREQUAL " ") +endsection()