CuraTests.cmake 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. include(CTest)
  4. include(CMakeParseArguments)
  5. # FIXME: The new FindPython3 finds the system's Python3.6 reather than the Python3.5 that we built for Cura's environment.
  6. # So we're using the old method here, with FindPythonInterp for now.
  7. find_package(PythonInterp 3 REQUIRED)
  8. set(Python3_EXECUTABLE ${PYTHON_EXECUTABLE})
  9. add_custom_target(test-verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
  10. function(cura_add_test)
  11. set(_single_args NAME DIRECTORY PYTHONPATH)
  12. cmake_parse_arguments("" "" "${_single_args}" "" ${ARGN})
  13. if(NOT _NAME)
  14. message(FATAL_ERROR "cura_add_test requires a test name argument")
  15. endif()
  16. if(NOT _DIRECTORY)
  17. message(FATAL_ERROR "cura_add_test requires a directory to test")
  18. endif()
  19. if(NOT _PYTHONPATH)
  20. set(_PYTHONPATH ${_DIRECTORY})
  21. endif()
  22. if(WIN32)
  23. string(REPLACE "|" "\\;" _PYTHONPATH ${_PYTHONPATH})
  24. set(_PYTHONPATH "${_PYTHONPATH}\\;$ENV{PYTHONPATH}")
  25. else()
  26. string(REPLACE "|" ":" _PYTHONPATH ${_PYTHONPATH})
  27. set(_PYTHONPATH "${_PYTHONPATH}:$ENV{PYTHONPATH}")
  28. endif()
  29. 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).
  30. if (NOT ${test_exists})
  31. add_test(
  32. NAME ${_NAME}
  33. COMMAND ${Python3_EXECUTABLE} -m pytest --junitxml=${CMAKE_BINARY_DIR}/junit-${_NAME}.xml ${_DIRECTORY}
  34. )
  35. set_tests_properties(${_NAME} PROPERTIES ENVIRONMENT LANG=C)
  36. set_tests_properties(${_NAME} PROPERTIES ENVIRONMENT "PYTHONPATH=${_PYTHONPATH}")
  37. else()
  38. message(WARNING "Duplicate test ${_NAME}!")
  39. endif()
  40. endfunction()
  41. #Add code style test.
  42. add_test(
  43. NAME "code-style"
  44. COMMAND ${Python3_EXECUTABLE} run_mypy.py
  45. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  46. )
  47. #Add test for import statements which are not compatible with all builds
  48. add_test(
  49. NAME "invalid-imports"
  50. COMMAND ${Python3_EXECUTABLE} scripts/check_invalid_imports.py
  51. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  52. )
  53. cura_add_test(NAME pytest-main DIRECTORY ${CMAKE_SOURCE_DIR}/tests PYTHONPATH "${CMAKE_SOURCE_DIR}|${URANIUM_DIR}")
  54. file(GLOB_RECURSE _plugins plugins/*/__init__.py)
  55. foreach(_plugin ${_plugins})
  56. get_filename_component(_plugin_directory ${_plugin} DIRECTORY)
  57. if(EXISTS ${_plugin_directory}/tests)
  58. get_filename_component(_plugin_name ${_plugin_directory} NAME)
  59. cura_add_test(NAME pytest-${_plugin_name} DIRECTORY ${_plugin_directory} PYTHONPATH "${_plugin_directory}|${CMAKE_SOURCE_DIR}|${URANIUM_DIR}")
  60. endif()
  61. endforeach()
  62. #Add test for whether the shortcut alt-keys are unique in every translation.
  63. add_test(
  64. NAME "shortcut-keys"
  65. COMMAND ${Python3_EXECUTABLE} scripts/check_shortcut_keys.py
  66. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  67. )