CuraTests.cmake 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 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. set(_PYTHONPATH "${_PYTHONPATH}\\;$ENV{PYTHONPATH}")
  21. else()
  22. string(REPLACE "|" ":" _PYTHONPATH ${_PYTHONPATH})
  23. set(_PYTHONPATH "${_PYTHONPATH}:$ENV{PYTHONPATH}")
  24. endif()
  25. get_test_property(${_NAME} ENVIRONMENT test_exists) #Find out if the test exists by getting a property from it that always exists (such as ENVIRONMENT because we set that ourselves).
  26. if (NOT ${test_exists})
  27. add_test(
  28. NAME ${_NAME}
  29. COMMAND ${PYTHON_EXECUTABLE} -m pytest --verbose --full-trace --capture=no --no-print-log --junitxml=${CMAKE_BINARY_DIR}/junit-${_NAME}.xml ${_DIRECTORY}
  30. )
  31. set_tests_properties(${_NAME} PROPERTIES ENVIRONMENT LANG=C)
  32. set_tests_properties(${_NAME} PROPERTIES ENVIRONMENT "PYTHONPATH=${_PYTHONPATH}")
  33. else()
  34. message(WARNING "Duplicate test ${_NAME}!")
  35. endif()
  36. endfunction()
  37. cura_add_test(NAME pytest-main DIRECTORY ${CMAKE_SOURCE_DIR}/tests PYTHONPATH "${CMAKE_SOURCE_DIR}|${URANIUM_DIR}")
  38. file(GLOB_RECURSE _plugins plugins/*/__init__.py)
  39. foreach(_plugin ${_plugins})
  40. get_filename_component(_plugin_directory ${_plugin} DIRECTORY)
  41. if(EXISTS ${_plugin_directory}/tests)
  42. get_filename_component(_plugin_name ${_plugin_directory} NAME)
  43. cura_add_test(NAME pytest-${_plugin_name} DIRECTORY ${_plugin_directory} PYTHONPATH "${_plugin_directory}|${CMAKE_SOURCE_DIR}|${URANIUM_DIR}")
  44. endif()
  45. endforeach()
  46. #Add code style test.
  47. add_test(
  48. NAME "code-style"
  49. COMMAND ${PYTHON_EXECUTABLE} run_mypy.py
  50. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  51. )
  52. #Add test for whether the shortcut alt-keys are unique in every translation.
  53. add_test(
  54. NAME "shortcut-keys"
  55. COMMAND ${PYTHON_EXECUTABLE} scripts/check_shortcut_keys.py
  56. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  57. )