| 1 |
# Distributed under the original FontForge BSD 3-clause license |
| 2 |
|
| 3 |
#[=======================================================================[.rst: |
| 4 |
TestUtils |
| 5 |
--------- |
| 6 |
|
| 7 |
``add_download_target` creates a custom target that will ensure that |
| 8 |
``font`` exists. If it is not present in the source tree, it will be |
| 9 |
downloaded via ``url``. |
| 10 |
|
| 11 |
``add_ff_test`` and ``add_py_test`` both wrap ``add_test`` to add a |
| 12 |
standard system test, which involves invoking either a native or Python |
| 13 |
script. System tests are performed by invoking ``systestdriver``, which |
| 14 |
handles determining if a test should be skipped, based on missing inputs, |
| 15 |
and also runs each test in its own test folder. |
| 16 |
|
| 17 |
#]=======================================================================] |
| 18 |
|
| 19 |
function(add_download_target font url) |
| 20 |
add_custom_command( |
| 21 |
OUTPUT |
| 22 |
"${CMAKE_CURRENT_BINARY_DIR}/fonts/${font}" |
| 23 |
COMMAND "${CMAKE_COMMAND}" |
| 24 |
-D DEST:FILEPATH="${CMAKE_CURRENT_BINARY_DIR}/fonts/${font}" |
| 25 |
-D SOURCE:FILEPATH="${CMAKE_CURRENT_SOURCE_DIR}/fonts/${font}" |
| 26 |
-D URL:STRING="${url}" |
| 27 |
-P "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/scripts/DownloadIfMissing.cmake" |
| 28 |
) |
| 29 |
endfunction() |
| 30 |
|
| 31 |
function(_add_systest test_mode binary test_script) |
| 32 |
get_filename_component(_test_name "${test_script}" NAME_WE) |
| 33 |
set(_test_name "${_test_name}_${test_mode}") |
| 34 |
|
| 35 |
list(LENGTH ARGN _arglen) |
| 36 |
if (${_arglen} LESS 1) |
| 37 |
message(FATAL_ERROR "Must pass a description as the last argument") |
| 38 |
endif() |
| 39 |
list(GET ARGN -1 _description) |
| 40 |
list(REMOVE_AT ARGN -1) |
| 41 |
|
| 42 |
# Prior to CMake 3.9, skipped tests fail the suite |
| 43 |
if(${CMAKE_VERSION} VERSION_LESS "3.9") |
| 44 |
set(_skip_arg --skip-as-pass) |
| 45 |
endif() |
| 46 |
|
| 47 |
add_test(NAME ${_test_name} |
| 48 |
COMMAND systestdriver |
| 49 |
--mode ${test_mode} |
| 50 |
--binary "${binary}" |
| 51 |
--script "${CMAKE_CURRENT_SOURCE_DIR}/${test_script}" |
| 52 |
--exedir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}" |
| 53 |
--libdir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" |
| 54 |
--argdir "${CMAKE_CURRENT_BINARY_DIR}/fonts" |
| 55 |
--argdir "${CMAKE_CURRENT_SOURCE_DIR}/fonts" |
| 56 |
--desc "${_description}" |
| 57 |
${_skip_arg} |
| 58 |
${ARGN} |
| 59 |
WORKING_DIRECTORY |
| 60 |
"${CMAKE_CURRENT_BINARY_DIR}" |
| 61 |
) |
| 62 |
set_tests_properties(${_test_name} PROPERTIES SKIP_RETURN_CODE 77) |
| 63 |
endfunction() |
| 64 |
|
| 65 |
function(add_ff_test test_script) |
| 66 |
# Native scripting tests require fontforgeexe, not available in wheel builds |
| 67 |
if(NOT BUILDING_WHEEL) |
| 68 |
_add_systest(ff "$<TARGET_FILE:fontforgeexe>" "${test_script}" ${ARGN}) |
| 69 |
endif() |
| 70 |
endfunction() |
| 71 |
|
| 72 |
function(add_py_test test_script) |
| 73 |
list(FIND ARGN PYHOOK_DISABLED _disable_pyhook_index) |
| 74 |
if(NOT _disable_pyhook_index LESS 0) |
| 75 |
list(REMOVE_AT ARGN ${_disable_pyhook_index}) |
| 76 |
set(_disable_pyhook 1) |
| 77 |
endif() |
| 78 |
|
| 79 |
# fontforgeexe-based Python tests not available in wheel builds |
| 80 |
if(NOT BUILDING_WHEEL) |
| 81 |
_add_systest(py "$<TARGET_FILE:fontforgeexe>" "${test_script}" ${ARGN}) |
| 82 |
endif() |
| 83 |
if(ENABLE_PYTHON_EXTENSION_RESULT AND NOT _disable_pyhook) |
| 84 |
_add_systest(pyhook "${Python3_EXECUTABLE}" "${test_script}" ${ARGN}) |
| 85 |
endif() |
| 86 |
endfunction() |