Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Tests to Be Declared as Functions #47

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
function(add_cmake_test FILE)
foreach(NAME ${ARGN})
string(TOLOWER ${NAME} TEST_COMMAND)
string(REPLACE " " "_" TEST_COMMAND ${TEST_COMMAND})
add_test(
NAME ${NAME}
COMMAND ${CMAKE_COMMAND}
-D CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}
-D TEST_MATCHES=^${NAME}$
-D TEST_COMMAND=${TEST_COMMAND}
-P ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
)
endforeach()
Expand Down
27 changes: 10 additions & 17 deletions test/cmake/MkdirRecursiveTest.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
# Matches everything if not defined
if(NOT TEST_MATCHES)
set(TEST_MATCHES ".*")
endif()

set(TEST_COUNT 0)

if("Create directory recursively" MATCHES ${TEST_MATCHES})
math(EXPR TEST_COUNT "${TEST_COUNT} + 1")

function(create_directory_recursively)
if(EXISTS parent)
message(STATUS "Removing test directory")
file(REMOVE_RECURSE parent)
Expand All @@ -24,15 +15,17 @@ if("Create directory recursively" MATCHES ${TEST_MATCHES})

message(STATUS "Removing test directory")
file(REMOVE_RECURSE parent)
endif()
endfunction()

# Add more test cases here.
if("Test name" MATCHES ${TEST_MATCHES})
math(EXPR TEST_COUNT "${TEST_COUNT} + 1")

function(test_name)
# Do something.
endif()
endfunction()

if(TEST_COUNT LESS_EQUAL 0)
message(FATAL_ERROR "Nothing to test with: ${TEST_MATCHES}")
if(NOT DEFINED TEST_COMMAND)
message(FATAL_ERROR "The 'TEST_COMMAND' variable should be defined")
elseif(NOT COMMAND ${TEST_COMMAND})
message(FATAL_ERROR "Unable to find a command named '${TEST_COMMAND}'")
endif()

cmake_language(CALL ${TEST_COMMAND})