diff --git a/cmake/BashTests.cmake b/cmake/BashTests.cmake index bf86216463..7eda4e3c09 100644 --- a/cmake/BashTests.cmake +++ b/cmake/BashTests.cmake @@ -1,6 +1,6 @@ # 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(singleValueArgs FILE_PATH PREFIX WORKING_DIRECTORY ENVIRONMENT) set(multiValueArgs EXEC_DIRECTORIES) cmake_parse_arguments( ARG @@ -14,6 +14,7 @@ function(add_bash_tests) set(prefix ${ARG_PREFIX}) set(working_directory ${ARG_WORKING_DIRECTORY}) set(exec_directories ${ARG_EXEC_DIRECTORIES}) + set(environment ${ARG_ENVIRONMENT}) # Regenerate tests when the test script changes set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${file_path}) @@ -67,9 +68,10 @@ function(add_bash_tests) 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 + set_tests_properties(${prefix}_${test_name} PROPERTIES + ENVIRONMENT "${environment}" + FIXTURES_REQUIRED ${file_name}_cleanup ) message(VERBOSE "Add bash tests commands for ${file_name}: ${line}") endforeach() -endfunction() \ No newline at end of file +endfunction() diff --git a/testing/data/python_cli/help.txt b/testing/data/python_cli/help.txt index cb8eb76d45..d8075efa2f 100644 --- a/testing/data/python_cli/help.txt +++ b/testing/data/python_cli/help.txt @@ -1,3 +1,4 @@ + tteessttiinngg__ppyytthhoonn__ccllii: external MRtrix3 project SSYYNNOOPPSSIISS diff --git a/testing/unit_tests/CMakeLists.txt b/testing/unit_tests/CMakeLists.txt index 05040d841e..013417dfb4 100644 --- a/testing/unit_tests/CMakeLists.txt +++ b/testing/unit_tests/CMakeLists.txt @@ -22,6 +22,17 @@ set(DATA_DIR ${SOURCE_PARENT_DIR}/data) find_program(BASH bash) +set(PYTHON_ENV_PATH "${PROJECT_BINARY_DIR}/lib") +# On MSYS2 we need to convert Windows paths to Unix paths +if(MINGW AND WIN32) + EXECUTE_PROCESS( + COMMAND cygpath -u ${PYTHON_ENV_PATH} + OUTPUT_VARIABLE PYTHON_ENV_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endif() + + function(add_cpp_unit_test FILE_SRC) get_filename_component(NAME ${FILE_SRC} NAME_WE) add_executable(${NAME} ${FILE_SRC}) @@ -51,6 +62,7 @@ function (add_bash_unit_test FILE_SRC) PREFIX "unittest" WORKING_DIRECTORY ${DATA_DIR} EXEC_DIRECTORIES "${EXEC_DIRS}" + ENVIRONMENT "PYTHONPATH=${PYTHON_ENV_PATH}" ) endfunction() diff --git a/testing/unit_tests/cpp_cli b/testing/unit_tests/cpp_cli index eaf7f14a49..a346ce0e19 100644 --- a/testing/unit_tests/cpp_cli +++ b/testing/unit_tests/cpp_cli @@ -1,8 +1,8 @@ mkdir -p tmp-dirin/ && touch tmp-filein.txt && touch tmp-tracksin.tck && testing_cpp_cli -flag -text my_text -choice One -bool false -int_unbound 0 -int_nonneg 1 -int_bound 50 -float_unbound 0.0 -float_nonneg 1.0 -float_bound 0.5 -int_seq 1,2,3 -float_seq 0.1,0.2,0.3 -dir_in tmp-dirin/ -dir_out tmp-dirout/ -file_in tmp-filein.txt -file_out tmp-fileout.txt -tracks_in tmp-tracksin.tck -tracks_out tmp-tracksout.tck -various my_various && rm -rf tmp-dirin/ && rm -f tmp-filein.txt && rm -f tmp-tracksin.tck -testing_cpp_cli -help > tmp.txt && sed -i '1,2d' tmp.txt && diff tmp.txt cpp_cli/help.txt && rm -f tmp.txt -testing_cpp_cli __print_full_usage__ > tmp.txt && diff tmp.txt cpp_cli/full_usage.txt && rm -f tmp.txt -testing_cpp_cli __print_usage_markdown__ > tmp.md && diff tmp.md cpp_cli/markdown.md && rm -f tmp.md -testing_cpp_cli __print_usage_rst__ > tmp.rst && diff tmp.rst cpp_cli/restructured_text.rst && rm -f tmp.rst +testing_cpp_cli -help | tail -n +2 > tmp.txt && diff -a --strip-trailing-cr tmp.txt cpp_cli/help.txt && rm -f tmp.txt +testing_cpp_cli __print_full_usage__ > tmp.txt && diff -a --strip-trailing-cr tmp.txt cpp_cli/full_usage.txt && rm -f tmp.txt +testing_cpp_cli __print_usage_markdown__ > tmp.md && diff -a --strip-trailing-cr tmp.md cpp_cli/markdown.md && rm -f tmp.md +testing_cpp_cli __print_usage_rst__ > tmp.rst && diff -a --strip-trailing-cr tmp.rst cpp_cli/restructured_text.rst && rm -f tmp.rst testing_cpp_cli -bool false testing_cpp_cli -bool False testing_cpp_cli -bool FALSE diff --git a/testing/unit_tests/python_cli b/testing/unit_tests/python_cli index 955dc7fac1..250b5072dd 100644 --- a/testing/unit_tests/python_cli +++ b/testing/unit_tests/python_cli @@ -1,8 +1,8 @@ mkdir -p tmp-dirin/ && touch tmp-filein.txt && touch tmp-tracksin.tck && testing_python_cli -flag -string_implicit my_implicit_string -string_explicit my_explicit_string -choice One -bool false -int_builtin 0 -float_builtin 0.0 -int_unbound 0 -int_nonneg 1 -int_bound 50 -float_unbound 0.0 -float_nonneg 1.0 -float_bound 0.5 -int_seq 1,2,3 -float_seq 0.1,0.2,0.3 -dir_in tmp-dirin/ -dir_out tmp-dirout/ -file_in tmp-filein.txt -file_out tmp-fileout.txt -tracks_in tmp-tracksin.tck -tracks_out tmp-tracksout.tck -various my_various && rm -rf tmp-dirin/ && rm -f tmp-filein.txt && rm -f tmp-tracksin.tck -testing_python_cli -help > tmp.txt && sed -i '1,3d' tmp.txt && diff tmp.txt python_cli/help.txt && rm -f tmp.txt -testing_python_cli __print_full_usage__ > tmp.txt && diff tmp.txt python_cli/full_usage.txt && rm -f tmp.txt -testing_python_cli __print_usage_markdown__ > tmp.md && diff tmp.md python_cli/markdown.md && rm -f tmp.md -testing_python_cli __print_usage_rst__ > tmp.rst && diff tmp.rst python_cli/restructured_text.rst && rm -f tmp.rst +testing_python_cli -help | tail -n +3 > tmp.txt && diff -a --strip-trailing-cr tmp.txt python_cli/help.txt && rm -f tmp.txt +testing_python_cli __print_full_usage__ > tmp.txt && diff -a --strip-trailing-cr tmp.txt python_cli/full_usage.txt && rm -f tmp.txt +testing_python_cli __print_usage_markdown__ > tmp.md && diff -a --strip-trailing-cr tmp.md python_cli/markdown.md && rm -f tmp.md +testing_python_cli __print_usage_rst__ > tmp.rst && diff -a --strip-trailing-cr tmp.rst python_cli/restructured_text.rst && rm -f tmp.rst testing_python_cli -bool false testing_python_cli -bool False testing_python_cli -bool FALSE