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:
Uli Schlachter 2016-06-04 15:01:30 +02:00
parent 77f867ff57
commit a7d6699d5d
1 changed files with 20 additions and 37 deletions

View File

@ -220,29 +220,19 @@ 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})
# Get the directory content if ((NOT "${file}" MATCHES ".*/shims/.*")
file(GLOB ex_files RELATIVE "${path}" AND (NOT "${file}" MATCHES ".*/template.lua"))
"${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")
# Get the file name without the extension # 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 the test name
set(TEST_NAME DOC${namespace}_${TEST_FILE_NAME}_EXAMPLE) 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}") set(ENV{EXAMPLE_LIST} "$ENV{EXAMPLE_LIST};${TEST_NAME}")
endif() endif()
endforeach() 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.