From e8f46834dc68b4e51677e0de22ae3c378e392eec Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Wed, 13 Apr 2022 09:30:50 +0200 Subject: [PATCH] common code -> macr --- Tests/Examples/CMakeLists.txt | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Tests/Examples/CMakeLists.txt b/Tests/Examples/CMakeLists.txt index f765127b757..a1848a421f3 100644 --- a/Tests/Examples/CMakeLists.txt +++ b/Tests/Examples/CMakeLists.txt @@ -9,18 +9,21 @@ file(MAKE_DIRECTORY ${TEST_OUTPUT_DIR_PY_PERSIST}) # Test scripts #################################################################################################### +macro(parse_example example) + cmake_path(SET EXAMPLE_SCRIPT NORMALIZE ${EXAMPLES_DIR}/${example}.py) + get_filename_component(EXAMPLE_NAME ${EXAMPLE_SCRIPT} NAME_WE) + get_filename_component(EXAMPLE_SUBDIR ${example} DIRECTORY) +endmacro() + # Run one Python example. # Check whether the example executes, don't check results. # If there are matplotlib commands, skip plt.show(). function(run_example example label) - set(script_path ${EXAMPLES_DIR}/${example}.py) - get_filename_component(EXAMPLE_NAME ${script_path} NAME_WE) - + parse_example(${example}) set(test_name Example.run.${EXAMPLE_NAME}) add_test(NAME ${test_name} COMMAND ${CMAKE_COMMAND} -E env BA_EXAMPLE_DATA_DIR=${EXAMPLES_DIR}/data - NOSHOW=TRUE ${Python3_EXECUTABLE} ${TOOL_DIR}/code/batch-plot.py -s ${script_path} ${TEST_OUTPUT_DIR_PY_EXAMPLES}) if(NOT label STREQUAL "") @@ -30,9 +33,7 @@ endfunction() # Run examples that don't plot. function(run_noplot example) - cmake_path(SET EXAMPLE_SCRIPT NORMALIZE ${EXAMPLES_DIR}/${example}.py) - get_filename_component(EXAMPLE_NAME ${EXAMPLE_SCRIPT} NAME_WE) - + parse_example(${example}) set(test_name Example.exec.${EXAMPLE_NAME}) add_test(NAME ${test_name} COMMAND ${Python3_EXECUTABLE} -B ${EXAMPLE_SCRIPT} @@ -41,10 +42,7 @@ endfunction() # Python equality test: run modified example, and compare with reference data of another example function(test_equality example reference tolerance) - cmake_path(SET EXAMPLE_SCRIPT NORMALIZE ${EXAMPLES_DIR}/${example}.py) - get_filename_component(EXAMPLE_NAME ${EXAMPLE_SCRIPT} NAME_WE) - get_filename_component(EXAMPLE_SUBDIR ${example} DIRECTORY) - + parse_example(${example}) set(test_name Example.persist.${EXAMPLE_NAME}) add_test(NAME ${test_name} COMMAND ${CMAKE_COMMAND} -- GitLab