tests/example/: Replace recursion with iteration
Instead of recursively walking the directory tree, this commit makes the code us GLOB_RECURSE to find all files and then handles them on after another. Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
77f867ff57
commit
a7d6699d5d
|
@ -220,29 +220,19 @@ function(run_test test_path namespace escaped_content)
|
|||
|
||||
endfunction()
|
||||
|
||||
# Recursive helper function to avoid adding CMakeLists.txt and add_subdirectory
|
||||
# in every sub-directories.
|
||||
function(digg path)
|
||||
|
||||
# Get the directory content
|
||||
file(GLOB ex_files RELATIVE "${path}"
|
||||
"${path}/*")
|
||||
|
||||
foreach(ex_file_name ${ex_files})
|
||||
if(IS_DIRECTORY ${path}/${ex_file_name}
|
||||
AND (NOT ${ex_file_name} STREQUAL "shims"))
|
||||
|
||||
digg("${path}/${ex_file_name}")
|
||||
|
||||
elseif(${ex_file_name} MATCHES ".lua"
|
||||
AND NOT ${ex_file_name} MATCHES "template.lua")
|
||||
# Find and run all test files
|
||||
file(GLOB_RECURSE test_files LIST_DIRECTORIES false
|
||||
"${SOURCE_DIR}/tests/examples/*.lua")
|
||||
foreach(file ${test_files})
|
||||
if ((NOT "${file}" MATCHES ".*/shims/.*")
|
||||
AND (NOT "${file}" MATCHES ".*/template.lua"))
|
||||
|
||||
# Get the file name without the extension
|
||||
string(REGEX REPLACE "\\.lua" "" TEST_FILE_NAME ${ex_file_name})
|
||||
get_filename_component(TEST_FILE_NAME ${file} NAME_WE)
|
||||
|
||||
get_namespace(namespace "${path}/${ex_file_name}")
|
||||
get_namespace(namespace "${file}")
|
||||
|
||||
run_test("${path}/${ex_file_name}" "${namespace}" ESCAPED_CODE_EXAMPLE)
|
||||
run_test("${file}" "${namespace}" ESCAPED_CODE_EXAMPLE)
|
||||
|
||||
# Set the test name
|
||||
set(TEST_NAME DOC${namespace}_${TEST_FILE_NAME}_EXAMPLE)
|
||||
|
@ -256,14 +246,7 @@ function(digg path)
|
|||
set(ENV{EXAMPLE_LIST} "$ENV{EXAMPLE_LIST};${TEST_NAME}")
|
||||
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# Start at the top level then recursively explore the sub-directories to locate
|
||||
# the test. In parallel, build a namespace for the global variables. Those
|
||||
# variables will be inserted into the lua source code itself once the examples
|
||||
# are validated.
|
||||
digg("${SOURCE_DIR}/tests/examples")
|
||||
endforeach()
|
||||
|
||||
# This is ugly, but CMake variable scope system totally ignore 50 years of
|
||||
# computer science evolution and only support function local variables.
|
||||
|
|
Loading…
Reference in New Issue