Add some tests
This commit is contained in:
14
cmake/modules/Findcmocka.cmake
Normal file
14
cmake/modules/Findcmocka.cmake
Normal file
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
cmocka
|
||||
GIT_REPOSITORY https://gitlab.com/cmocka/cmocka.git
|
||||
GIT_TAG cmocka-2.0.1
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(cmocka)
|
||||
set(cmocka_FOUND ON)
|
||||
32
cmake/modules/dusktest.cmake
Normal file
32
cmake/modules/dusktest.cmake
Normal file
@@ -0,0 +1,32 @@
|
||||
# Copyright (c) 2026 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
find_package(cmocka REQUIRED)
|
||||
|
||||
# Function to create a test executable from a single .c file
|
||||
function(dusktest TEST_C_FILE)
|
||||
# Create target name from file name
|
||||
get_filename_component(TEST_NAME ${TEST_C_FILE} NAME_WE)
|
||||
|
||||
# Create the executable target
|
||||
add_executable(${TEST_NAME})
|
||||
|
||||
# Setup some compiler definitions.
|
||||
target_compile_definitions(${TEST_NAME} PRIVATE
|
||||
DUSK_TEST_ASSERT=1
|
||||
)
|
||||
|
||||
# Add the test file
|
||||
target_sources(${TEST_NAME} PRIVATE ${TEST_C_FILE})
|
||||
|
||||
# Add sources, both common and test-specific
|
||||
target_include_directories(${TEST_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR} ${DUSK_TEST_DIR})
|
||||
|
||||
# Link against DuskCore and cmocka
|
||||
target_link_libraries(${TEST_NAME} PUBLIC ${DUSK_LIBRARY_TARGET_NAME} cmocka)
|
||||
|
||||
# Add as a CTest
|
||||
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
|
||||
endfunction()
|
||||
Reference in New Issue
Block a user