From 938cb3656faea8b35d16d04bb4e79cfe65c7ae98 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 22 Oct 2024 20:39:46 +0700 Subject: [PATCH] build: prepend CMake module path with assertion module directory (#300) * build: prepend `CMAKE_MODULE_PATH` with Assertion list dir Signed-off-by: Alfi Maulana * test: include Assertion module using name instead of full path Signed-off-by: Alfi Maulana --------- Signed-off-by: Alfi Maulana --- CMakeLists.txt | 8 ++++++-- test/test_add_test.cmake | 3 +-- test/test_assert.cmake | 3 +-- test/test_assert_call.cmake | 2 +- test/test_assert_number.cmake | 2 +- test/test_assert_process.cmake | 2 +- test/test_assert_string.cmake | 2 +- test/test_assert_version.cmake | 2 +- test/test_fail.cmake | 2 +- 9 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4bcdf7..606508a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 diff --git a/test/test_add_test.cmake b/test/test_add_test.cmake index 12e4e13..6f48084 100644 --- a/test/test_add_test.cmake +++ b/test/test_add_test.cmake @@ -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" diff --git a/test/test_assert.cmake b/test/test_assert.cmake index 2c456a9..00eaac9 100644 --- a/test/test_assert.cmake +++ b/test/test_assert.cmake @@ -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) diff --git a/test/test_assert_call.cmake b/test/test_assert_call.cmake index a96cd85..c8bc8b9 100644 --- a/test/test_assert_call.cmake +++ b/test/test_assert_call.cmake @@ -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") diff --git a/test/test_assert_number.cmake b/test/test_assert_number.cmake index 34389ca..5133df6 100644 --- a/test/test_assert_number.cmake +++ b/test/test_assert_number.cmake @@ -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) diff --git a/test/test_assert_process.cmake b/test/test_assert_process.cmake index 02114de..0e9a951 100644 --- a/test/test_assert_process.cmake +++ b/test/test_assert_process.cmake @@ -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") diff --git a/test/test_assert_string.cmake b/test/test_assert_string.cmake index bae9047..9639523 100644 --- a/test/test_assert_string.cmake +++ b/test/test_assert_string.cmake @@ -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") diff --git a/test/test_assert_version.cmake b/test/test_assert_version.cmake index 6e6f12c..5db54c6 100644 --- a/test/test_assert_version.cmake +++ b/test/test_assert_version.cmake @@ -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) diff --git a/test/test_fail.cmake b/test/test_fail.cmake index 05d272a..16932ee 100644 --- a/test/test_fail.cmake +++ b/test/test_fail.cmake @@ -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"