Skip to content

Commit

Permalink
feat: allow stacking sections (#117)
Browse files Browse the repository at this point in the history
* feat: indent messages inside section

* test: test section message indentation
  • Loading branch information
threeal authored Jun 30, 2024
1 parent 511d735 commit 45a5936
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmake/Assertion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
13 changes: 13 additions & 0 deletions test/SectionCreation.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 45a5936

Please sign in to comment.