There is more

Consider the following definition:

add_test(  NAME python_test_long  COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test.py --executable $<TARGET_FILE:sum_up>  )

The preceding definition can be re-expressed by explicitly specifying the WORKING_DIRECTORY in which the script will be run, as follows:

add_test(  NAME python_test_long  COMMAND ${PYTHON_EXECUTABLE} test.py --executable $<TARGET_FILE:sum_up>  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}  )

We will also mention that test names can contain the / character, which may be useful when organizing related tests by name; for example:

add_test(  NAME python/long  COMMAND ${PYTHON_EXECUTABLE} test.py --executable $<TARGET_FILE:sum_up> WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ...

Get CMake Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.