Salome HOME
Adaptation of compilation procedure in SALOME environment
[modules/shaper.git] / CMakeCommon / UnitTest.cmake
1 ## Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 #
4 # NewGeom unit test system
5 # How to use:
6 # INCLUDE(UnitTest)
7 # ...
8 # ADD_UNIT_TESTS(TestUndoRedo.py
9 #                TestResultBody.py)
10 # or
11 # SET(PROJECT_UNIT_TESTS
12 #     TestUndoRedo.py
13 #     TestWhatever.py  
14 #    )
15 # ADD_UNIT_TESTS(${PROJECT_UNIT_TESTS})
16 #
17 # Where "TestUndoRedo.py" and "TestResultBody.py" are names 
18 # of python test scripts in the "./Test" directory.
19 # This macro will add "Subproject_" as prefix and 
20 # remove ".py" for the test name automaticaly. 
21
22 # Start building of the "RUN_TESTS" project in the Visual studio
23 # or run "make test" on linux stations to start the testing procedure.
24 #
25
26 ENABLE_TESTING()
27
28 MACRO(ADD_UNIT_TESTS)
29   foreach(eachFileName ${ARGN})
30     # Strip the ".py" suffix 
31     GET_FILENAME_COMPONENT(aTestName ${eachFileName} NAME_WE)
32
33     # Add "SubprojectName_" prefix
34     GET_FILENAME_COMPONENT(aSubprojectName ${CMAKE_CURRENT_SOURCE_DIR} NAME)
35     SET(aTestName "${aSubprojectName}_${aTestName}")
36
37     # Full path to the python test file beeing executed 
38     SET(aTestFileName "${CMAKE_CURRENT_SOURCE_DIR}/Test/${eachFileName}")
39     IF(EXISTS ${aTestFileName})
40       ADD_TEST(NAME ${aTestName}
41                COMMAND ${PYTHON_EXECUTABLE} ${aTestFileName})
42       # Debug output...
43       #MESSAGE(STATUS "Test added: ${aTestName} file: ${aTestFileName}")
44     ELSE(EXISTS ${aTestFileName})
45       MESSAGE(WARNING "Can not find the test file: ${aTestFileName}")
46     ENDIF(EXISTS ${aTestFileName})
47   endforeach(eachFileName ${ARGN})
48 ENDMACRO(ADD_UNIT_TESTS)
49