Skip to content

Commit

Permalink
test: assert if there's nothing to test (#29)
Browse files Browse the repository at this point in the history
* test: add assertion if there's nothing to test

* test: fix regex for passing `TEST_MATCHES` option
  • Loading branch information
threeal authored Jan 16, 2024
1 parent 13ce8b1 commit e55fe14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function(add_cmake_test FILE)
NAME ${NAME}
COMMAND ${CMAKE_COMMAND}
-D CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}
-D TEST_MATCHES="^${NAME}$"
-D TEST_MATCHES=^${NAME}$
-P ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
)
endforeach()
Expand Down
10 changes: 10 additions & 0 deletions test/MkdirRecursiveTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ 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")

if(EXISTS parent)
message(STATUS "Removing test directory")
file(REMOVE_RECURSE parent)
Expand All @@ -24,5 +28,11 @@ endif()

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

# Do something.
endif()

if(TEST_COUNT LESS_EQUAL 0)
message(FATAL_ERROR "Nothing to test with: ${TEST_MATCHES}")
endif()

0 comments on commit e55fe14

Please sign in to comment.