Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert the unit tests of xbt::config to Catch2.
[simgrid.git] / tools / cmake / UnitTesting.cmake
1 # This file is in charge of the unit testing in SimGrid.
2 # See http://simgrid.gforge.inria.fr/simgrid/3.13/doc/inside_tests.html#inside_tests_add_units
3
4 # To register a file containing unit tests, simply add it to
5 # FILES_CONTAINING_UNITTESTS and have a pleasant day.
6
7 set(FILES_CONTAINING_UNITTESTS
8   src/xbt/cunit.cpp
9 )
10
11 ####  Nothing to change below this line to add a new tested file
12 ################################################################
13
14 foreach(file ${FILES_CONTAINING_UNITTESTS})
15   get_filename_component(basename ${file} NAME_WE)
16   get_filename_component(ext ${file} EXT)
17   set(EXTRACTED_TEST_SOURCE_FILES ${EXTRACTED_TEST_SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/src/${basename}_unit${ext})
18 endforeach()
19
20 set(EXTRACTED_TEST_SOURCE_FILES ${EXTRACTED_TEST_SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/src/simgrid_units_main.c)
21
22 set_source_files_properties(${EXTRACTED_TEST_SOURCE_FILES} PROPERTIES GENERATED true)
23
24 ADD_CUSTOM_COMMAND(
25   OUTPUT  ${EXTRACTED_TEST_SOURCE_FILES}
26   DEPENDS ${CMAKE_HOME_DIRECTORY}/tools/sg_unit_extractor.pl ${FILES_CONTAINING_UNITTESTS}
27   COMMENT "Generating *_units files for testall..."
28
29   WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
30   COMMAND           ${CMAKE_COMMAND} -E remove -f ${EXTRACTED_TEST_SOURCE_FILES}
31   COMMAND           chmod +x ${CMAKE_HOME_DIRECTORY}/tools/sg_unit_extractor.pl
32   COMMAND           ${CMAKE_HOME_DIRECTORY}/tools/sg_unit_extractor.pl --root=src/ --outdir=${CMAKE_CURRENT_BINARY_DIR}/src/ ${FILES_CONTAINING_UNITTESTS}
33 )
34
35 add_executable       (testall EXCLUDE_FROM_ALL ${EXTRACTED_TEST_SOURCE_FILES})
36 add_dependencies(tests testall)
37 target_link_libraries(testall simgrid)
38 set_property(
39     TARGET testall
40     APPEND PROPERTY
41            INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}"
42            )
43