Add some tests
Some checks failed
Build Dusk / build-psp (push) Has been cancelled
Build Dusk / build-linux (push) Has been cancelled

This commit is contained in:
2026-01-05 16:13:14 -06:00
parent 8ee46fd204
commit aec937b04b
12 changed files with 711 additions and 30 deletions

View 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()