-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for testing Python scripts
- Loading branch information
Showing
4 changed files
with
178 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# A function that adds a bash test for each line in a given file | ||
function(add_bash_tests) | ||
set(singleValueArgs FILE_PATH PREFIX WORKING_DIRECTORY) | ||
set(multiValueArgs EXEC_DIRECTORIES) | ||
cmake_parse_arguments( | ||
ARG | ||
"" | ||
"${singleValueArgs}" | ||
"${multiValueArgs}" | ||
${ARGN} | ||
) | ||
|
||
set(file_path ${ARG_FILE_PATH}) | ||
set(prefix ${ARG_PREFIX}) | ||
set(working_directory ${ARG_WORKING_DIRECTORY}) | ||
set(exec_directories ${ARG_EXEC_DIRECTORIES}) | ||
|
||
get_filename_component(file_name ${file_path} NAME_WE) | ||
|
||
# Add a custom target for IDEs to pickup the test script | ||
add_custom_target(test_${file_name} SOURCES ${file_path}) | ||
|
||
# Add test that cleans up temporary files | ||
add_test( | ||
NAME ${prefix}_${file_name}_cleanup | ||
COMMAND ${BASH} -c "rm -rf ${DATA_DIR}/tmp* ${DATA_DIR}/*-tmp-*" | ||
WORKING_DIRECTORY ${DATA_DIR} | ||
) | ||
set_tests_properties(${prefix}_${file_name}_cleanup PROPERTIES FIXTURES_SETUP ${file_name}_cleanup) | ||
|
||
file(STRINGS ${file_path} FILE_CONTENTS) | ||
list(LENGTH FILE_CONTENTS FILE_CONTENTS_LENGTH) | ||
math(EXPR MAX_LINE_NUM "${FILE_CONTENTS_LENGTH} - 1") | ||
|
||
|
||
set(EXEC_DIR_PATHS "${exec_directories}") | ||
string(REPLACE ";" ":" EXEC_DIR_PATHS "${EXEC_DIR_PATHS}") | ||
|
||
foreach(line_num RANGE ${MAX_LINE_NUM}) | ||
list(GET FILE_CONTENTS ${line_num} line) | ||
|
||
set(test_name ${file_name}) | ||
if(${FILE_CONTENTS_LENGTH} GREATER 1) | ||
math(EXPR suffix "${line_num} + 1") | ||
set(test_name "${file_name}_${suffix}") | ||
endif() | ||
|
||
add_test( | ||
NAME ${prefix}_${test_name} | ||
COMMAND ${BASH} -c "export PATH=${EXEC_DIR_PATHS}:$PATH;${line}" | ||
WORKING_DIRECTORY ${working_directory} | ||
) | ||
set_tests_properties(${prefix}_${test_name} | ||
PROPERTIES FIXTURES_REQUIRED ${file_name}_cleanup | ||
) | ||
message(VERBOSE "Add bash tests commands for ${file_name}: ${line}") | ||
endforeach() | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_subdirectory(binaries) | ||
add_subdirectory(lib) | ||
add_subdirectory(scripts) | ||
add_subdirectory(tools) | ||
add_subdirectory(unit_tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
find_program(BASH bash) | ||
|
||
set(DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data) | ||
|
||
include(BashTests) | ||
function(add_bash_script_tests file_path) | ||
set(EXEC_DIRS ${CMAKE_CURRENT_BINARY_DIR}) | ||
list(APPEND EXEC_DIRS ${PROJECT_BINARY_DIR}/bin) | ||
list(APPEND EXEC_DIRS ${PROJECT_BINARY_DIR}/testing/tools) | ||
|
||
add_bash_tests( | ||
FILE_PATH "${file_path}" | ||
PREFIX "script" | ||
WORKING_DIRECTORY ${DATA_DIR} | ||
EXEC_DIRECTORIES "${EXEC_DIRS}" | ||
) | ||
endfunction() | ||
|
||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/5ttgen) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/dwi2mask) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/dwi2response) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/dwibiascorrect) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/dwicat) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/dwifslpreproc) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/dwigradcheck) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/dwinormalise) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/dwishellmath) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/for_each) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/labelsgmfix) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/population_template) | ||
add_bash_script_tests(${CMAKE_CURRENT_SOURCE_DIR}/tests/responsemean) |