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,50 +220,33 @@ function(run_test test_path namespace escaped_content)
|
||||||
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
# Recursive helper function to avoid adding CMakeLists.txt and add_subdirectory
|
# Find and run all test files
|
||||||
# in every sub-directories.
|
file(GLOB_RECURSE test_files LIST_DIRECTORIES false
|
||||||
function(digg path)
|
"${SOURCE_DIR}/tests/examples/*.lua")
|
||||||
|
foreach(file ${test_files})
|
||||||
|
if ((NOT "${file}" MATCHES ".*/shims/.*")
|
||||||
|
AND (NOT "${file}" MATCHES ".*/template.lua"))
|
||||||
|
|
||||||
# Get the directory content
|
# Get the file name without the extension
|
||||||
file(GLOB ex_files RELATIVE "${path}"
|
get_filename_component(TEST_FILE_NAME ${file} NAME_WE)
|
||||||
"${path}/*")
|
|
||||||
|
|
||||||
foreach(ex_file_name ${ex_files})
|
get_namespace(namespace "${file}")
|
||||||
if(IS_DIRECTORY ${path}/${ex_file_name}
|
|
||||||
AND (NOT ${ex_file_name} STREQUAL "shims"))
|
|
||||||
|
|
||||||
digg("${path}/${ex_file_name}")
|
run_test("${file}" "${namespace}" ESCAPED_CODE_EXAMPLE)
|
||||||
|
|
||||||
elseif(${ex_file_name} MATCHES ".lua"
|
# Set the test name
|
||||||
AND NOT ${ex_file_name} MATCHES "template.lua")
|
set(TEST_NAME DOC${namespace}_${TEST_FILE_NAME}_EXAMPLE)
|
||||||
|
|
||||||
# Get the file name without the extension
|
# Anything called @DOC_`namespace`_EXAMPLE@
|
||||||
string(REGEX REPLACE "\\.lua" "" TEST_FILE_NAME ${ex_file_name})
|
# in the Lua or C sources will be replaced by the content if that
|
||||||
|
# variable during the pre-processing
|
||||||
|
set(ENV{${TEST_NAME}} "${ESCAPED_CODE_EXAMPLE}" CACHE INTERNAL FORCE)
|
||||||
|
|
||||||
get_namespace(namespace "${path}/${ex_file_name}")
|
# Update the test list
|
||||||
|
set(ENV{EXAMPLE_LIST} "$ENV{EXAMPLE_LIST};${TEST_NAME}")
|
||||||
|
|
||||||
run_test("${path}/${ex_file_name}" "${namespace}" ESCAPED_CODE_EXAMPLE)
|
endif()
|
||||||
|
endforeach()
|
||||||
# Set the test name
|
|
||||||
set(TEST_NAME DOC${namespace}_${TEST_FILE_NAME}_EXAMPLE)
|
|
||||||
|
|
||||||
# Anything called @DOC_`namespace`_EXAMPLE@
|
|
||||||
# in the Lua or C sources will be replaced by the content if that
|
|
||||||
# variable during the pre-processing
|
|
||||||
set(ENV{${TEST_NAME}} "${ESCAPED_CODE_EXAMPLE}" CACHE INTERNAL FORCE)
|
|
||||||
|
|
||||||
# Update the test list
|
|
||||||
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")
|
|
||||||
|
|
||||||
# This is ugly, but CMake variable scope system totally ignore 50 years of
|
# This is ugly, but CMake variable scope system totally ignore 50 years of
|
||||||
# computer science evolution and only support function local variables.
|
# computer science evolution and only support function local variables.
|
||||||
|
|
Loading…
Reference in New Issue