@@ -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
+ macro (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
+ endmacro ()
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,46 @@ 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
+ string (CONCAT LL_LINE_REGEX
57
+ "^([^.]*)" # test group
58
+ "\\ ."
59
+ "([^.]*)" # test name
60
+ "\\ ."
61
+ "(.*)" # file name (only this field is allowed to contain dots)
62
+ "\\ ."
63
+ "([^.]*)" # line number
64
+ "\n "
65
+ )
66
+ string (REGEX MATCHALL "[^\n ]+\n " discovered_test_lines "${discovered_tests} " )
67
+ if (TESTS_DETAILED )
68
+ foreach (line IN LISTS discovered_test_lines )
69
+ string (REGEX MATCH "${LL_LINE_REGEX} " __unused "${line} " )
70
+ set (test_name "${CMAKE_MATCH_1} .${CMAKE_MATCH_2} " )
71
+ set (test_location "${CMAKE_MATCH_3} :${CMAKE_MATCH_4} " )
72
+ add_test_to_script ("${test_name} " "${test_location} " -st )
73
+ endforeach ()
74
+ else ()
75
+ foreach (line IN LISTS discovered_test_lines )
76
+ string (REGEX MATCH "${LL_LINE_REGEX} " __unused "${line} " )
77
+ set (test_name "${CMAKE_MATCH_1} " )
78
+ set (test_file "${CMAKE_MATCH_3} " )
79
+ set (test_line "${CMAKE_MATCH_4} " )
80
+ if (NOT _${test_name}_file )
81
+ # if the group spans two files, arbitrarily choose the first one encountered
82
+ set (_${test_name}_file "${test_file} " )
83
+ set (_${test_name}_line "${test_line} " )
84
+ elseif (test_file STREQUAL _${test_name}_file AND test_line LESS _${test_name}_line )
85
+ # line number will eventually be the first line of the first test in the group's file
86
+ set (_${test_name}_line ${test_line} )
87
+ endif ()
88
+ list (APPEND groups_seen ${test_name} )
89
+ endforeach ()
90
+ list (REMOVE_DUPLICATES groups_seen )
91
+ foreach (test_name IN LISTS groups_seen )
92
+ set (test_location "${_${test_name} _file}:${_${test_name} _line}" )
93
+ add_test_to_script ("${test_name} " "${test_location} " -sg )
94
+ endforeach ()
95
+ endif ()
56
96
57
97
file (WRITE "${CTEST_FILE} " "${script} " )
0 commit comments