]> SALOME platform Git repositories - modules/shaper.git/blob - CMakeCommon/UnitTest.cmake
Salome HOME
Additional fix for '#17858 Many ctest errors in SHAPER' issue
[modules/shaper.git] / CMakeCommon / UnitTest.cmake
1 # Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 #
21 # SHAPER unit test system
22 # How to use:
23 # INCLUDE(UnitTest)
24 # ...
25 # ADD_UNIT_TESTS(TestUndoRedo.py
26 #                TestResultBody.py)
27 # or
28 # SET(PROJECT_UNIT_TESTS
29 #     TestUndoRedo.py
30 #     TestWhatever.py
31 #    )
32 # ADD_UNIT_TESTS(${PROJECT_UNIT_TESTS})
33 #
34 # Where "TestUndoRedo.py" and "TestResultBody.py" are names
35 # of python test scripts in the "./Test" directory.
36 # This macro will add "Subproject_" as prefix and
37 # remove ".py" for the test name automaticaly.
38 #
39 # Start building of the "RUN_TESTS" project in the Visual studio
40 # or run "make test" on linux stations to start the testing procedure.
41 #
42
43 ENABLE_TESTING()
44
45 MACRO(ADD_UNIT_TESTS)
46   if (WIN32) # different separators and path to libraries variable name
47     SET(_JUSTPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_BIN};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES};${SUIT_LIB_DIR};${SALOME_KERNEL_LIBDIR};$ENV{PATH}")
48     STRING(REPLACE "\\" "/" _JUSTPATH "${_JUSTPATH}")
49     STRING(REPLACE ";" "\\;" _JUSTPATH "${_JUSTPATH}")
50     SET(_PYTHONPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_ADDONS};$ENV{PYTHONPATH}")
51     STRING(REPLACE "\\" "/" _PYTHONPATH "${_PYTHONPATH}")
52     STRING(REPLACE ";" "\\;" _PYTHONPATH "${_PYTHONPATH}")
53   else()
54     SET(_LD_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_BIN}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES}:${SUIT_LIB_DIR}:${SALOME_KERNEL_LIBDIR}:$ENV{LD_LIBRARY_PATH}")
55     SET(_PYTHONPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_ADDONS}:$ENV{PYTHONPATH}")
56   endif()
57
58   foreach(eachFileName ${ARGN})
59     # Strip the ".py" suffix
60     GET_FILENAME_COMPONENT(aTestName ${eachFileName} NAME_WE)
61
62     # Add "SubprojectName_" prefix
63     GET_FILENAME_COMPONENT(aSubprojectName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
64     SET(aTestName "${aSubprojectName}_${aTestName}")
65
66     # Full path to the python test file beeing executed
67     SET(aTestFileName "${CMAKE_CURRENT_SOURCE_DIR}/Test/${eachFileName}")
68     IF(EXISTS ${aTestFileName})
69       ADD_TEST(NAME ${aTestName}
70                COMMAND ${PYTHON_EXECUTABLE} ${aTestFileName})
71       if (WIN32) # different path to libraries variable name
72         SET_TESTS_PROPERTIES(${aTestName} PROPERTIES
73                ENVIRONMENT "PATH=${_JUSTPATH};PYTHONPATH=${_PYTHONPATH}")
74       else()
75         SET_TESTS_PROPERTIES(${aTestName} PROPERTIES
76                ENVIRONMENT "LD_LIBRARY_PATH=${_LD_LIBRARY_PATH};PYTHONPATH=${_PYTHONPATH}")
77       endif()
78       # Debug output...
79       #MESSAGE(STATUS "Test added: ${aTestName} file: ${aTestFileName}")
80     ELSE(EXISTS ${aTestFileName})
81       MESSAGE(WARNING "Can not find the test file: ${aTestFileName}")
82     ENDIF(EXISTS ${aTestFileName})
83   endforeach(eachFileName ${ARGN})
84 ENDMACRO(ADD_UNIT_TESTS)
85
86 MACRO(ADD_UNIT_TESTS_API)
87   if (WIN32) # different separators and path to libraries variable name
88     SET(_JUSTPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_BIN};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES};${SUIT_LIB_DIR};${SALOME_KERNEL_LIBDIR};$ENV{PATH}")
89     STRING(REPLACE "\\" "/" _JUSTPATH "${_JUSTPATH}")
90     STRING(REPLACE ";" "\\;" _JUSTPATH "${_JUSTPATH}")
91     SET(_PYTHONPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES};${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_ADDONS};$ENV{PYTHONPATH}")
92     STRING(REPLACE "\\" "/" _PYTHONPATH "${_PYTHONPATH}")
93     STRING(REPLACE ";" "\\;" _PYTHONPATH "${_PYTHONPATH}")
94   else()
95     SET(_LD_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_BIN}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES}:${SUIT_LIB_DIR}:${SALOME_KERNEL_LIBDIR}:$ENV{LD_LIBRARY_PATH}")
96     SET(_PYTHONPATH "${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_SWIG}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_PLUGIN_FILES}:${CMAKE_INSTALL_PREFIX}/${SHAPER_INSTALL_ADDONS}:$ENV{PYTHONPATH}")
97   endif()
98
99   foreach(eachFileName ${ARGN})
100     # Strip the ".py" suffix
101     GET_FILENAME_COMPONENT(aTestName ${eachFileName} NAME_WE)
102
103     # Add "SubprojectName_" prefix
104     GET_FILENAME_COMPONENT(aSubprojectName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
105     SET(aTestName "${aSubprojectName}_${aTestName}")
106
107     # Full path to the python test file beeing executed
108     SET(aTestFileName "${CMAKE_CURRENT_SOURCE_DIR}/${eachFileName}")
109     IF(EXISTS ${aTestFileName})
110       ADD_TEST(NAME ${aTestName}
111                COMMAND ${PYTHON_EXECUTABLE} ${aTestFileName})
112       if (WIN32) # different path to libraries variable name
113         SET_TESTS_PROPERTIES(${aTestName} PROPERTIES
114                ENVIRONMENT "PATH=${_JUSTPATH};PYTHONPATH=${_PYTHONPATH}")
115       else()
116         SET_TESTS_PROPERTIES(${aTestName} PROPERTIES
117                ENVIRONMENT "LD_LIBRARY_PATH=${_LD_LIBRARY_PATH};PYTHONPATH=${_PYTHONPATH}")
118       endif()
119       # Debug output...
120       #MESSAGE(STATUS "Test added: ${aTestName} file: ${aTestFileName}")
121     ELSE(EXISTS ${aTestFileName})
122       MESSAGE(WARNING "Can not find the test file: ${aTestFileName}")
123     ENDIF(EXISTS ${aTestFileName})
124   endforeach(eachFileName ${ARGN})
125 ENDMACRO(ADD_UNIT_TESTS_API)