Skip to content

Commit

Permalink
build: prepend CMake module path with assertion module directory (#300)
Browse files Browse the repository at this point in the history
* build: prepend `CMAKE_MODULE_PATH` with Assertion list dir

Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>

* test: include Assertion module using name instead of full path

Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>

---------

Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
  • Loading branch information
threeal authored Oct 22, 2024
1 parent 97da512 commit 938cb36
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 12 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ project(
option(ASSERTION_ENABLE_TESTS "Enable test targets.")
option(ASSERTION_ENABLE_INSTALL "Enable install targets." "${PROJECT_IS_TOP_LEVEL}")

include(cmake/Assertion.cmake)
list(PREPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(Assertion)

if(ASSERTION_ENABLE_TESTS)
enable_testing()

list(APPEND CMAKE_SCRIPT_TEST_DEFINITIONS CMAKE_MODULE_PATH)

add_cmake_script_test(test/test_add_test.cmake)
add_cmake_script_test(test/test_assert_call.cmake)
add_cmake_script_test(test/test_assert_number.cmake)
Expand All @@ -27,7 +30,8 @@ endif()

if(ASSERTION_ENABLE_INSTALL)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cmake/AssertionConfig.cmake
"include(\${CMAKE_CURRENT_LIST_DIR}/Assertion.cmake)\n")
"list(PREPEND CMAKE_MODULE_PATH \${CMAKE_CURRENT_LIST_DIR})\n"
"include(Assertion)\n")

include(CMakePackageConfigHelpers)
write_basic_package_version_file(cmake/AssertionConfigVersion.cmake
Expand Down
3 changes: 1 addition & 2 deletions test/test_add_test.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.24)

include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake
RESULT_VARIABLE ASSERTION_LIST_FILE)
include(Assertion RESULT_VARIABLE ASSERTION_LIST_FILE)

set(CMAKELISTS_HEADER
"cmake_minimum_required(VERSION 3.24)\n"
Expand Down
3 changes: 1 addition & 2 deletions test/test_assert.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cmake_minimum_required(VERSION 3.24)

include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake
RESULT_VARIABLE ASSERTION_LIST_FILE)
include(Assertion RESULT_VARIABLE ASSERTION_LIST_FILE)

file(MAKE_DIRECTORY sample-project)

Expand Down
2 changes: 1 addition & 1 deletion test/test_assert_call.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.24)

include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake)
include(Assertion)

function(throw_errors)
message(SEND_ERROR "a send error message")
Expand Down
2 changes: 1 addition & 1 deletion test/test_assert_number.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.24)

include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake)
include(Assertion)

set(SEVEN_VAR 7)
set(THIRTEEN_VAR 13)
Expand Down
2 changes: 1 addition & 1 deletion test/test_assert_process.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.24)

include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake)
include(Assertion)

section("assert process executions")
section("it should assert process executions")
Expand Down
2 changes: 1 addition & 1 deletion test/test_assert_string.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.24)

include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake)
include(Assertion)

set(STRING_VAR "a string")
set(OTHER_STRING_VAR "another string")
Expand Down
2 changes: 1 addition & 1 deletion test/test_assert_version.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.24)

include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake)
include(Assertion)

set(VERSION_VAR 1.2.3)
set(VERSIONN_VAR 1.02.3)
Expand Down
2 changes: 1 addition & 1 deletion test/test_fail.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.24)

include(${CMAKE_CURRENT_LIST_DIR}/../cmake/Assertion.cmake)
include(Assertion)

section("it should fail with formatted fatal error messages given strings")
assert_call(fail "single line string"
Expand Down

0 comments on commit 938cb36

Please sign in to comment.