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