CuraTests.cmake 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. add_custom_target(test-verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
  7. function(cura_add_test)
  8. set(_single_args NAME DIRECTORY PYTHONPATH)
  9. cmake_parse_arguments("" "" "${_single_args}" "" ${ARGN})
  10. if(NOT _NAME)
  11. message(FATAL_ERROR "cura_add_test requires a test name argument")
  12. endif()
  13. if(NOT _DIRECTORY)
  14. message(FATAL_ERROR "cura_add_test requires a directory to test")
  15. endif()
  16. if(NOT _PYTHONPATH)
  17. set(_PYTHONPATH ${_DIRECTORY})
  18. endif()
  19. if(WIN32)
  20. string(REPLACE "|" "\\;" _PYTHONPATH ${_PYTHONPATH})
  21. set(_PYTHONPATH "${_PYTHONPATH}\\;$ENV{PYTHONPATH}")
  22. else()
  23. string(REPLACE "|" ":" _PYTHONPATH ${_PYTHONPATH})
  24. set(_PYTHONPATH "${_PYTHONPATH}:$ENV{PYTHONPATH}")
  25. endif()
  26. 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).
  27. if (NOT ${test_exists})
  28. add_test(
  29. NAME ${_NAME}
  30. COMMAND ${PYTHON_EXECUTABLE} -m pytest --verbose --full-trace --capture=no --no-print-log --junitxml=${CMAKE_BINARY_DIR}/junit-${_NAME}.xml ${_DIRECTORY}
  31. )
  32. set_tests_properties(${_NAME} PROPERTIES ENVIRONMENT LANG=C)
  33. set_tests_properties(${_NAME} PROPERTIES ENVIRONMENT "PYTHONPATH=${_PYTHONPATH}")
  34. else()
  35. message(WARNING "Duplicate test ${_NAME}!")
  36. endif()
  37. endfunction()
  38. cura_add_test(NAME pytest-main DIRECTORY ${CMAKE_SOURCE_DIR}/tests PYTHONPATH "${CMAKE_SOURCE_DIR}|${URANIUM_DIR}")
  39. file(GLOB_RECURSE _plugins plugins/*/__init__.py)
  40. foreach(_plugin ${_plugins})
  41. get_filename_component(_plugin_directory ${_plugin} DIRECTORY)
  42. if(EXISTS ${_plugin_directory}/tests)
  43. get_filename_component(_plugin_name ${_plugin_directory} NAME)
  44. cura_add_test(NAME pytest-${_plugin_name} DIRECTORY ${_plugin_directory} PYTHONPATH "${_plugin_directory}|${CMAKE_SOURCE_DIR}|${URANIUM_DIR}")
  45. endif()
  46. endforeach()
  47. #Add code style test.
  48. add_test(
  49. NAME "code-style"
  50. COMMAND ${PYTHON_EXECUTABLE} run_mypy.py
  51. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  52. )
  53. #Add test for whether the shortcut alt-keys are unique in every translation.
  54. add_test(
  55. NAME "shortcut-keys"
  56. COMMAND ${PYTHON_EXECUTABLE} scripts/check_shortcut_keys.py
  57. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  58. )