Debian Codegraph @

cmake/tribits/core/test_support/TribitsAddAdvancedTestHelpers.cmake

raw
1 # @HEADER
2 # *****************************************************************************
3 # TriBITS: Tribal Build, Integrate, and Test System
4 #
5 # Copyright 2013-2016 NTESS and the TriBITS contributors.
6 # SPDX-License-Identifier: BSD-3-Clause
7 # *****************************************************************************
8 # @HEADER
9
10
11 include("${CMAKE_CURRENT_LIST_DIR}/TribitsAddTestHelpers.cmake")
12
13
14 # Set default ax number of TEST_<idx> blocks in tribits_add_advanced_test()
15 if ("${TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_BLOCKS}" STREQUAL "")
16 set(TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_BLOCKS 20)
17 endif()
18 # NOTE: Given how includes are done in CMake, above is the only safe way to set
19 # the default.
20
21
22 # Compute TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_CMND_IDX given
23 # TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_BLOCKS
24 macro(tribits_add_advanced_test_max_num_test_cmnd_idx_compute)
25 math(EXPR TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_CMND_IDX
26 "${TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_BLOCKS}-1")
27 endmacro()
28
29
30 # Check that the numbers of TEST_<idx> blocks is not violated.
31 #
32 # This gets called on the last # TEST_<idx> block of arguments in the parser.
33 #
34 function(tribits_add_advanced_test_check_exceed_max_num_test_blocks)
35 if (NOT "${PARSE_TEST_${TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_CMND_IDX}}"
36 STREQUAL ""
37 )
38 list(FIND PARSE_TEST_${TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_CMND_IDX}
39 "TEST_${TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_BLOCKS}"
40 TEST_BLOCK_KEYWORD_FIND_IDX)
41 if (NOT TEST_BLOCK_KEYWORD_FIND_IDX EQUAL -1)
42 message_wrapper(FATAL_ERROR
43 "${TEST_NAME}: ERROR: Test block TEST_${TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_BLOCKS} exceeds the max allowed test block TEST_${TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_CMND_IDX} as allowed by TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_BLOCKS=${TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_BLOCKS}. To fix this, call set(TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_BLOCKS <larger-num>) before calling tribits_add_advanced_test()!")
44 # NOTE: The above error message is put on one line to simplify unit
45 # testing checking the string.
46 endif()
47 endif()
48 endfunction()
49
50
51 # Join arguments together to add to a set(...) statement to passed to
52 # execute_process(...)
53 #
54 function(tribits_join_exec_process_set_args OUTPUT_STRING_VAR)
55 set(OUTPUT_STRING "")
56 foreach(STRING_VAL_RAW ${ARGN})
57 # Remove quotes around arguments because CTest does not need them
58 string(REGEX REPLACE "\"" "" STRING_VAL "${STRING_VAL_RAW}")
59 if (OUTPUT_STRING STREQUAL "")
60 set(OUTPUT_STRING "\"${STRING_VAL}\"")
61 else()
62 set(OUTPUT_STRING "${OUTPUT_STRING} \"${STRING_VAL}\"")
63 endif()
64 endforeach()
65 set(${OUTPUT_STRING_VAR} "${OUTPUT_STRING}" PARENT_SCOPE)
66 endfunction()
67
68
69 # Unit test helper function for tribits_add_advanced_test(...) that resets
70 # state before calling tribits_add_advanced_test(...) in unit test mode.
71 #
72 # NOTE: The variables:
73 #
74 # TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_${TEST_CMND_IDX}
75 #
76 # may get set, even if the test does not get added. That is because the
77 # decision to add a test may not be made until much later in the script.
78 # Therefore, to determine if an advanced test is added or not, one should
79 # check the variable:
80 #
81 # TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS
82 #
83 # If that variable is empty, then the advanced test did *not* get added.
84 #
85 function(tribits_add_advanced_test_unittest_reset)
86
87 global_set(TRIBITS_ADD_ADVANCED_TEST_UNITTEST TRUE)
88
89 global_set(TRIBITS_ADD_ADVANCED_TEST_NUM_CMNDS "")
90
91 tribits_add_advanced_test_max_num_test_cmnd_idx_compute()
92 foreach( TEST_CMND_IDX RANGE
93 ${TRIBITS_ADD_ADVANCED_TEST_MAX_NUM_TEST_CMND_IDX}
94 )
95 global_set(TRIBITS_ADD_ADVANCED_TEST_CMND_ARRAY_${TEST_CMND_IDX} "")
96 endforeach()
97
98 endfunction()