1
- set (script )
1
+ set (script "" CACHE INTERNAL "" )
2
2
3
3
function (add_command NAME )
4
4
set (_args "" )
@@ -12,7 +12,7 @@ function(add_command NAME)
12
12
set (_args "${_args} ${_arg} " )
13
13
endif ()
14
14
endforeach ()
15
- set (script "${script}${NAME} (${_args} )\n " PARENT_SCOPE )
15
+ set (script "${script}${NAME} (${_args} )\n " CACHE INTERNAL "" )
16
16
endfunction ()
17
17
18
18
if (NOT EXISTS "${EXECUTABLE} " )
@@ -21,16 +21,27 @@ if(NOT EXISTS "${EXECUTABLE}")
21
21
)
22
22
endif ()
23
23
24
- if (TESTS_DETAILED )
25
- set (discovery_arg "-ln" )
26
- set (select_arg "-st" )
27
- else ()
28
- set (discovery_arg "-lg" )
29
- set (select_arg "-sg" )
30
- endif ()
24
+ function (add_test_to_script TEST_NAME TEST_LOCATION SELECT_ARG )
25
+ add_command (
26
+ add_test
27
+ "${TEST_NAME} "
28
+ ${EMULATOR}
29
+ "${EXECUTABLE} "
30
+ ${ARGS}
31
+ ${SELECT_ARG}
32
+ ${TEST_NAME}
33
+ )
34
+ add_command (
35
+ set_tests_properties
36
+ "${TEST_NAME} "
37
+ PROPERTIES
38
+ DEF_SOURCE_LINE
39
+ "${TEST_LOCATION} "
40
+ )
41
+ endfunction ()
31
42
32
43
execute_process (
33
- COMMAND ${EMULATOR} "${EXECUTABLE} " ${discovery_arg}
44
+ COMMAND ${EMULATOR} "${EXECUTABLE} " -ll
34
45
OUTPUT_VARIABLE discovered_tests
35
46
RESULT_VARIABLE result
36
47
ERROR_VARIABLE error
@@ -41,17 +52,37 @@ if(NOT ${result} EQUAL 0)
41
52
"${error} "
42
53
)
43
54
endif ()
44
- separate_arguments (discovered_tests )
45
- foreach (test_name IN LISTS discovered_tests )
46
- add_command (
47
- add_test
48
- "${test_name} "
49
- ${EMULATOR}
50
- "${EXECUTABLE} "
51
- ${ARGS}
52
- ${select_arg}
53
- ${test_name}
54
- )
55
- endforeach ()
55
+
56
+ set (LL_LINE_REGEX "^([^.]*)\\ .([^.]*)\\ .(.*)\\ .([^.]*)\n " )
57
+ string (REGEX MATCHALL "[^\n ]+\n " discovered_test_lines "${discovered_tests} " )
58
+ if (TESTS_DETAILED )
59
+ foreach (line IN LISTS discovered_test_lines )
60
+ string (REGEX MATCH "${LL_LINE_REGEX} " __ign "${line} " )
61
+ set (test_name "${CMAKE_MATCH_1} .${CMAKE_MATCH_2} " )
62
+ set (test_location "${CMAKE_MATCH_3} :${CMAKE_MATCH_4} " )
63
+ add_test_to_script ("${test_name} " "${test_location} " -st )
64
+ endforeach ()
65
+ else ()
66
+ foreach (line IN LISTS discovered_test_lines )
67
+ string (REGEX MATCH "${LL_LINE_REGEX} " __ign "${line} " )
68
+ set (test_name "${CMAKE_MATCH_1} " )
69
+ set (test_file "${CMAKE_MATCH_3} " )
70
+ set (test_line "${CMAKE_MATCH_4} " )
71
+ if (NOT _${test_name}_file )
72
+ # if the group spans two files, arbitrarily choose the first one encountered
73
+ set (_${test_name}_file "${test_file} " )
74
+ set (_${test_name}_line "${test_line} " )
75
+ elseif (test_file STREQUAL _${test_name}_file AND test_line LESS _${test_name}_line )
76
+ # line number will eventually be the first line of the first test in the group's file
77
+ set (_${test_name}_line ${test_line} )
78
+ endif ()
79
+ list (APPEND groups_seen ${test_name} )
80
+ endforeach ()
81
+ list (REMOVE_DUPLICATES groups_seen )
82
+ foreach (test_name IN LISTS groups_seen )
83
+ set (test_location "${_${test_name} _file}:${_${test_name} _line}" )
84
+ add_test_to_script ("${test_name} " "${test_location} " -sg )
85
+ endforeach ()
86
+ endif ()
56
87
57
88
file (WRITE "${CTEST_FILE} " "${script} " )
0 commit comments