Skip to content

Commit

Permalink
feat: add ASSERTION_LIST_FILE variable (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal authored Jul 1, 2024
1 parent 0e4b171 commit 3c31e77
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
18 changes: 6 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,32 @@ if(ASSERT_ENABLE_TESTS)

add_test(
NAME "inclusion of other modules"
COMMAND "${CMAKE_COMMAND}"
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Assertion.cmake
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/IncludeOtherModules.cmake)

add_test(
NAME "condition assertions"
COMMAND "${CMAKE_COMMAND}"
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Assertion.cmake
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/Assert.cmake)

add_test(
NAME "fatal error assertions"
COMMAND "${CMAKE_COMMAND}"
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Assertion.cmake
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/AssertFatalError.cmake)

add_test(
NAME "execute process assertions"
COMMAND "${CMAKE_COMMAND}"
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Assertion.cmake
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/AssertExecuteProcess.cmake)

add_test(
NAME "internal assertion message formatting"
COMMAND "${CMAKE_COMMAND}"
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Assertion.cmake
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/InternalFormatMessage.cmake)

add_test(
NAME "section creation"
COMMAND "${CMAKE_COMMAND}"
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Assertion.cmake
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- ${CMAKE_CURRENT_SOURCE_DIR}/test/SectionCreation.cmake)
endif()

Expand Down
3 changes: 3 additions & 0 deletions cmake/Assertion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

cmake_minimum_required(VERSION 3.17)

# This variable contains the path to the included `Assertion.cmake` module.
set(ASSERTION_LIST_FILE "${CMAKE_CURRENT_LIST_FILE}")

# Formats an assertion message with indentation on each even line.
#
# _assert_internal_format_message(<out_var> [<lines>...])
Expand Down
9 changes: 3 additions & 6 deletions test/IncludeOtherModules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ section("it should include modules")
file(WRITE goo.cmake "message(STATUS \"goo\")\n")

assert_execute_process(
COMMAND "${CMAKE_COMMAND}"
-P ${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
-- foo.cmake goo.cmake
OUTPUT ".*foo\n.*goo")
endsection()

section("it should not include any modules if arguments are not specified")
assert_execute_process(
COMMAND "${CMAKE_COMMAND}"
-P ${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake
COMMAND "${CMAKE_COMMAND}" -P "${ASSERTION_LIST_FILE}"
OUTPUT "^$")
endsection()

section("it should not include any modules if included by another module")
file(WRITE root.cmake
"include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake)\n")
file(WRITE root.cmake "include(\"${ASSERTION_LIST_FILE}\")\n")

assert_execute_process(
COMMAND "${CMAKE_COMMAND}" -P root.cmake -- foo.cmake goo.cmake
Expand Down

0 comments on commit 3c31e77

Please sign in to comment.