|
| 1 | +# Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# In order to centralize all the labels for all the tests, these macros has been implemented |
| 16 | +# A variable ${PROJECT_NAME}_TEST_LABELS is set with all labels accepted (labels could be repeated) |
| 17 | +# A variable ${PROJECT_NAME}_LABEL_TEST_${N} is set for each N and contains the name of the file |
| 18 | +# where to read the tests that must have such label set in previous variable. |
| 19 | +# The value N in ${PROJECT_NAME}_TEST_LABELS is the label to set in tests listed in file |
| 20 | +# ${PROJECT_NAME}_LABEL_TEST_${N} |
| 21 | + |
| 22 | +macro(set_test_label_file FILE_NAME LABEL) |
| 23 | + |
| 24 | + message(STATUS "Set ${LABEL} label to tests in ${FILE_NAME} <${${PROJECT_NAME}_TEST_LABELS}>") |
| 25 | + |
| 26 | + # First check if file exists |
| 27 | + if(NOT EXISTS ${FILE_NAME}) |
| 28 | + message(WARNING "File ${FILE_NAME} does not exist, impossible to set label ${LABEL}") |
| 29 | + return() |
| 30 | + else() |
| 31 | + # Read file |
| 32 | + file(STRINGS ${FILE_NAME} TEST_LIST) |
| 33 | + endif() |
| 34 | + |
| 35 | + list(LENGTH INTERNAL_TEST_LABELS LABELS_SIZE) |
| 36 | + |
| 37 | + message(STATUS "set_test_label_file <${INTERNAL_TEST_LABELS}> <${LABELS_SIZE}>") |
| 38 | + |
| 39 | + # Append the new label to the list |
| 40 | + list(APPEND INTERNAL_TEST_LABELS "${LABEL}") |
| 41 | + set(${PROJECT_NAME}_TEST_LABELS "${INTERNAL_TEST_LABELS}") |
| 42 | + set(${PROJECT_NAME}_TEST_LABELS "${INTERNAL_TEST_LABELS}" PARENT_SCOPE) |
| 43 | + |
| 44 | + # Store the file content in a variable with the label index in its name |
| 45 | + # NOTE: for some reason this must be set twice, once with parent scope and one without |
| 46 | + set(${PROJECT_NAME}_LABEL_TEST_${LABELS_SIZE} "${TEST_LIST}") |
| 47 | + set(${PROJECT_NAME}_LABEL_TEST_${LABELS_SIZE} "${TEST_LIST}" PARENT_SCOPE) |
| 48 | + |
| 49 | +endmacro() |
| 50 | + |
| 51 | +macro(check_and_add_tests_label TEST_NAME TEST_LABEL_LIST LABEL) |
| 52 | + |
| 53 | + if(${TEST_NAME} IN_LIST "${TEST_LABEL_LIST}") |
| 54 | + message(STATUS "Setting label ${LABEL} to test ${TEST_NAME}") |
| 55 | + set_property(TEST ${TEST_NAME} PROPERTY LABELS ${LABEL}) |
| 56 | + endif() |
| 57 | + |
| 58 | +endmacro() |
| 59 | + |
| 60 | +macro(set_test_labels TEST_NAME) |
| 61 | + |
| 62 | + set (CURRENT_INDEX 0) |
| 63 | + foreach(TEST_LABEL ${${PROJECT_NAME}_TEST_LABELS}) |
| 64 | + |
| 65 | + check_and_add_tests_label( |
| 66 | + "${TEST_NAME}" |
| 67 | + ${PROJECT_NAME}_LABEL_TEST_${CURRENT_INDEX} |
| 68 | + "${TEST_LABEL}" |
| 69 | + ) |
| 70 | + |
| 71 | + MATH(EXPR CURRENT_INDEX "${CURRENT_INDEX} + 1") |
| 72 | + |
| 73 | + endforeach() |
| 74 | + |
| 75 | +endmacro() |
0 commit comments