Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a612328

Browse filesBrowse files
authored
Merge pull request #1848 from malsyned/def-source-line
add DEF_SOURCE_LINE to ctests
2 parents 694d00d + 7395fe0 commit a612328
Copy full SHA for a612328

File tree

Expand file treeCollapse file tree

1 file changed

+60
-20
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+60
-20
lines changed

‎cmake/Modules/_CppUTestDiscovery.cmake

Copy file name to clipboardExpand all lines: cmake/Modules/_CppUTestDiscovery.cmake
+60-20Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,27 @@ if(NOT EXISTS "${EXECUTABLE}")
2121
)
2222
endif()
2323

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()
3142

3243
execute_process(
33-
COMMAND ${EMULATOR} "${EXECUTABLE}" ${discovery_arg}
44+
COMMAND ${EMULATOR} "${EXECUTABLE}" -ll
3445
OUTPUT_VARIABLE discovered_tests
3546
RESULT_VARIABLE result
3647
ERROR_VARIABLE error
@@ -41,17 +52,46 @@ if(NOT ${result} EQUAL 0)
4152
"${error}"
4253
)
4354
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()
5696

5797
file(WRITE "${CTEST_FILE}" "${script}")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.