From 285acb73559d1cfad31663e2317232492550d65b Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Fri, 21 Jun 2024 11:14:47 +0700 Subject: [PATCH] test: simplify test files organization (#75) * test: move recursive directory creation tests to `MkdirRecursive.cmake` * test: declare tests in top-level `CMakeLists.txt` --- CMakeLists.txt | 6 +++++- test/CMakeLists.txt | 17 ----------------- test/MkdirRecursive.cmake | 11 +++++++++++ test/cmake/MkdirRecursiveTest.cmake | 20 -------------------- 4 files changed, 16 insertions(+), 38 deletions(-) delete mode 100644 test/CMakeLists.txt create mode 100644 test/MkdirRecursive.cmake delete mode 100644 test/cmake/MkdirRecursiveTest.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 78cbeff..5a4ae30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,11 @@ include(cmake/MkdirRecursive.cmake) if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING) enable_testing() - add_subdirectory(test) + + add_test( + NAME "recursive directory creation" + COMMAND "${CMAKE_COMMAND}" + -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/MkdirRecursive.cmake) endif() if(MY_MKDIR_ENABLE_INSTALL) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 47c61de..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -function(add_cmake_test FILE) - math(EXPR STOP "${ARGC} - 1") - foreach(I RANGE 1 "${STOP}") - add_test( - NAME "${ARGV${I}}" - COMMAND "${CMAKE_COMMAND}" - -D "TEST_COMMAND=${ARGV${I}}" - -P ${CMAKE_CURRENT_SOURCE_DIR}/${FILE} - ) - endforeach() -endfunction() - -add_cmake_test( - cmake/MkdirRecursiveTest.cmake - "Create directory recursively" - # Add more test cases here. -) diff --git a/test/MkdirRecursive.cmake b/test/MkdirRecursive.cmake new file mode 100644 index 0000000..b54f9db --- /dev/null +++ b/test/MkdirRecursive.cmake @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.5) + +find_package(MyMkdir REQUIRED PATHS ${CMAKE_CURRENT_LIST_DIR}/../../cmake) + +file(REMOVE_RECURSE parent) + +mkdir_recursive(parent/child) + +if(NOT EXISTS parent/child) + message(FATAL_ERROR "expected path 'parent/child' to exist") +endif() diff --git a/test/cmake/MkdirRecursiveTest.cmake b/test/cmake/MkdirRecursiveTest.cmake deleted file mode 100644 index 98e5c15..0000000 --- a/test/cmake/MkdirRecursiveTest.cmake +++ /dev/null @@ -1,20 +0,0 @@ -cmake_minimum_required(VERSION 3.5) - -find_package(MyMkdir REQUIRED PATHS ${CMAKE_CURRENT_LIST_DIR}/../../cmake) - -function("Create directory recursively") - file(REMOVE_RECURSE parent) - - mkdir_recursive(parent/child) - - if(NOT EXISTS parent/child) - message(FATAL_ERROR "expected path 'parent/child' to exist") - endif() -endfunction() - -# Add more test cases here. -function("Test something") - # Do something. -endfunction() - -cmake_language(CALL "${TEST_COMMAND}")