CuraTests.cmake 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. enable_testing()
  4. include(CMakeParseArguments)
  5. find_package(PythonInterp 3.5.0 REQUIRED)
  6. function(cura_add_test)
  7. set(_single_args NAME DIRECTORY PYTHONPATH)
  8. cmake_parse_arguments("" "" "${_single_args}" "" ${ARGN})
  9. if(NOT _NAME)
  10. message(FATAL_ERROR "cura_add_test requires a test name argument")
  11. endif()
  12. if(NOT _DIRECTORY)
  13. message(FATAL_ERROR "cura_add_test requires a directory to test")
  14. endif()
  15. if(NOT _PYTHONPATH)
  16. set(_PYTHONPATH ${_DIRECTORY})
  17. endif()
  18. if(WIN32)
  19. string(REPLACE "|" "\\;" _PYTHONPATH ${_PYTHONPATH})
  20. else()
  21. string(REPLACE "|" ":" _PYTHONPATH ${_PYTHONPATH})
  22. endif()
  23. add_test(
  24. NAME ${_NAME}
  25. COMMAND ${PYTHON_EXECUTABLE} -m pytest --junitxml=${CMAKE_BINARY_DIR}/junit-${_NAME}.xml ${_DIRECTORY}
  26. )
  27. set_tests_properties(${_NAME} PROPERTIES ENVIRONMENT LANG=C)
  28. set_tests_properties(${_NAME} PROPERTIES ENVIRONMENT "PYTHONPATH=${_PYTHONPATH}")
  29. endfunction()
  30. cura_add_test(NAME pytest-main DIRECTORY ${CMAKE_SOURCE_DIR}/tests PYTHONPATH "${CMAKE_SOURCE_DIR}|${URANIUM_DIR}")
  31. file(GLOB_RECURSE _plugins plugins/*/__init__.py)
  32. foreach(_plugin ${_plugins})
  33. get_filename_component(_plugin_directory ${_plugin} DIRECTORY)
  34. if(EXISTS ${_plugin_directory}/tests)
  35. get_filename_component(_plugin_name ${_plugin_directory} NAME)
  36. cura_add_test(NAME pytest-${_plugin_name} DIRECTORY ${_plugin_directory} PYTHONPATH "${_plugin_directory}|${CMAKE_SOURCE_DIR}|${URANIUM_DIR}")
  37. endif()
  38. endforeach()