CuraTests.cmake 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright (c) 2022 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. include(CTest)
  4. include(CMakeParseArguments)
  5. add_custom_target(test-verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
  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 --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. #Add code style test.
  38. add_test(
  39. NAME "code-style"
  40. COMMAND ${Python_EXECUTABLE} run_mypy.py
  41. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  42. )
  43. #Add test for import statements which are not compatible with all builds
  44. add_test(
  45. NAME "invalid-imports"
  46. COMMAND ${Python_EXECUTABLE} scripts/check_invalid_imports.py
  47. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  48. )
  49. cura_add_test(NAME pytest-main DIRECTORY ${CMAKE_SOURCE_DIR}/tests PYTHONPATH "${CMAKE_SOURCE_DIR}|${URANIUM_DIR}")
  50. file(GLOB_RECURSE _plugins plugins/*/__init__.py)
  51. foreach(_plugin ${_plugins})
  52. get_filename_component(_plugin_directory ${_plugin} DIRECTORY)
  53. if(EXISTS ${_plugin_directory}/tests)
  54. get_filename_component(_plugin_name ${_plugin_directory} NAME)
  55. cura_add_test(NAME pytest-${_plugin_name} DIRECTORY ${_plugin_directory} PYTHONPATH "${_plugin_directory}|${CMAKE_SOURCE_DIR}|${URANIUM_DIR}")
  56. endif()
  57. endforeach()
  58. #Add test for whether the shortcut alt-keys are unique in every translation.
  59. add_test(
  60. NAME "shortcut-keys"
  61. COMMAND ${Python_EXECUTABLE} scripts/check_shortcut_keys.py
  62. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  63. )