Salome HOME
fixed a typo
[modules/shaper.git] / CMakeCommon / UnitTest.cmake
1 # Copyright (C) 2014-2023  CEA, EDF
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 function(GENERATE_TESTS PATH testdir TESTS)
46   SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
47
48   foreach(eachFileName ${ARGN})
49     # Strip the ".py" suffix
50     GET_FILENAME_COMPONENT(aTestName ${eachFileName} NAME_WE)
51
52     # Add "SubprojectName_" prefix
53     GET_FILENAME_COMPONENT(aSubprojectName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
54     SET(aTestName "${aSubprojectName}_${aTestName}")
55
56     # Full path to the python test file beeing executed
57     SET(aTestFileName "${testdir}/${eachFileName}")
58     IF(NOT EXISTS ${aTestFileName})
59       SET(aTestFileName "${testdir}/Test/${eachFileName}")
60     ENDIF(NOT EXISTS ${aTestFileName})
61     IF(EXISTS ${aTestFileName})
62       ADD_TEST(NAME ${aTestName}
63                COMMAND ${PYTHON_EXECUTABLE} ${aTestFileName})
64       SET_TESTS_PROPERTIES(${aTestName} PROPERTIES
65                ENVIRONMENT "${tests_env};SHAPER_UNIT_TEST_IN_PROGRESS=1"
66                LABELS "${aSubprojectName}")
67       # Debug output...
68       #MESSAGE(STATUS "Test added: ${aTestName} file: ${aTestFileName}")
69     ELSE(EXISTS ${aTestFileName})
70       MESSAGE(WARNING "Can not find the test file: ${eachFileName}")
71       MESSAGE(STATUS "Search paths are: ${testdir}")
72       MESSAGE(STATUS "                  ${testdir}/Test")
73     ENDIF(EXISTS ${aTestFileName})
74   endforeach(eachFileName ${ARGN})
75 endfunction(GENERATE_TESTS)
76
77 function(ADD_UNIT_TESTS)
78   GENERATE_TESTS(PATH "${CMAKE_CURRENT_SOURCE_DIR}" TESTS ${ARGN})
79 endfunction(ADD_UNIT_TESTS)
80
81 function(ADD_UNIT_TESTS_API)
82   GENERATE_TESTS(PATH "${CMAKE_CURRENT_SOURCE_DIR}" TESTS ${ARGN})
83 endfunction(ADD_UNIT_TESTS_API)
84
85
86 function(ADD_RESTRICTED_TESTS)
87   SET(RESTRICTED_ROOT_DIR $ENV{RESTRICTED_ROOT_DIR} CACHE PATH "Path to the restricted repository")
88
89   if (EXISTS ${RESTRICTED_ROOT_DIR})
90     GENERATE_TESTS(PATH "${RESTRICTED_ROOT_DIR}/SHAPER/bugs" TESTS ${ARGN})
91   else()
92     message(WARNING "RESTRICTED_ROOT_DIR is not specified to run restricted tests")
93   endif()
94 endfunction(ADD_RESTRICTED_TESTS)