-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
190 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
set(_CPPUTEST_DISCOVERY_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/_CppUTestDiscovery.cmake | ||
CACHE INTERNAL "CppUTest discovery scripts" | ||
) | ||
|
||
option(CPPUTEST_TESTS_DETAILED "Run discovered tests individually") | ||
option(CPPUTEST_JUNIT_REPORT "Output JUnit test reports") | ||
|
||
function(cpputest_discover_tests target) | ||
set(options JUNIT) | ||
set(oneValueArgs DETAILED) | ||
set(multiValueArgs EXTRA_ARGS) | ||
cmake_parse_arguments( | ||
"" | ||
"${options}" | ||
"${oneValueArgs}" | ||
"${multiValueArgs}" | ||
${ARGN} | ||
) | ||
|
||
# Validate arguments. | ||
if(NOT TARGET ${target}) | ||
message(FATAL_ERROR | ||
"Cannot discover tests for target \"${target}\" " | ||
"which is not built by this project." | ||
) | ||
endif() | ||
|
||
get_property(target_type | ||
TARGET ${target} | ||
PROPERTY TYPE | ||
) | ||
if(NOT target_type STREQUAL "EXECUTABLE") | ||
message(FATAL_ERROR | ||
"Cannot discover tests for target \"${target}\" " | ||
"which is not an executable." | ||
) | ||
endif() | ||
|
||
if(NOT DEFINED _EXTRA_ARGS) | ||
set(_EXTRA_ARGS -v) | ||
endif() | ||
|
||
if(NOT DEFINED _DETAILED) | ||
set(_DETAILED ${CPPUTEST_TESTS_DETAILED}) | ||
endif() | ||
|
||
if(_JUNIT OR CPPUTEST_JUNIT_REPORT) | ||
list(APPEND _EXTRA_ARGS -ojunit) | ||
endif() | ||
|
||
set(CTEST_INCLUDE_FILE "${CMAKE_CURRENT_BINARY_DIR}/${target}_include.cmake") | ||
if(CMAKE_CONFIGURATION_TYPES) | ||
set(CTEST_GENERATED_FILE "${CMAKE_CURRENT_BINARY_DIR}/${target}.$<CONFIG>.cmake") | ||
file(WRITE "${CTEST_INCLUDE_FILE}" | ||
"if(EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/${target}.\${CTEST_CONFIGURATION_TYPE}.cmake\")\n" | ||
" include(\"${CMAKE_CURRENT_BINARY_DIR}/${target}.\${CTEST_CONFIGURATION_TYPE}.cmake\")\n" | ||
"endif()\n" | ||
) | ||
else() | ||
set(CTEST_GENERATED_FILE "${CMAKE_CURRENT_BINARY_DIR}/${target}.cmake") | ||
file(WRITE "${CTEST_INCLUDE_FILE}" | ||
"if(EXISTS \"${CTEST_GENERATED_FILE}\")\n" | ||
" include(\"${CTEST_GENERATED_FILE}\")\n" | ||
"endif()\n" | ||
) | ||
endif() | ||
|
||
add_custom_command( | ||
TARGET ${target} POST_BUILD | ||
BYPRODUCTS "${CTEST_GENERATED_FILE}" | ||
COMMAND | ||
"${CMAKE_COMMAND}" | ||
-D "TESTS_DETAILED:BOOL=${_DETAILED}" | ||
-D "EXECUTABLE=$<TARGET_FILE:${target}>" | ||
-D "EMULATOR=$<TARGET_PROPERTY:${target},CROSSCOMPILING_EMULATOR>" | ||
-D "ARGS=${run_args}" | ||
-D "CTEST_FILE=${CTEST_GENERATED_FILE}" | ||
-P "${_CPPUTEST_DISCOVERY_SCRIPT}" | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" | ||
DEPENDS "${_CPPUTEST_DISCOVERY_SCRIPT}" | ||
VERBATIM | ||
) | ||
|
||
if(${CMAKE_VERSION} VERSION_LESS "3.10") | ||
# We can only set one. | ||
get_property(already_set | ||
DIRECTORY | ||
PROPERTY TEST_INCLUDE_FILE | ||
SET | ||
) | ||
if(${already_set}) | ||
message(FATAL_ERROR | ||
"Cannot discovery multiple tests from the same file" | ||
) | ||
endif() | ||
set_property( | ||
DIRECTORY | ||
PROPERTY TEST_INCLUDE_FILE "${CTEST_INCLUDE_FILE}" | ||
) | ||
else() | ||
set_property( | ||
DIRECTORY APPEND | ||
PROPERTY TEST_INCLUDE_FILES "${CTEST_INCLUDE_FILE}" | ||
) | ||
endif() | ||
|
||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
set(script) | ||
|
||
function(add_command NAME) | ||
set(_args "") | ||
# use ARGV* instead of ARGN, because ARGN splits arrays into multiple arguments | ||
math(EXPR _last_arg ${ARGC}-1) | ||
foreach(_n RANGE 1 ${_last_arg}) | ||
set(_arg "${ARGV${_n}}") | ||
if(_arg MATCHES "[^-./:a-zA-Z0-9_]") | ||
set(_args "${_args} [==[${_arg}]==]") # form a bracket_argument | ||
else() | ||
set(_args "${_args} ${_arg}") | ||
endif() | ||
endforeach() | ||
set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE) | ||
endfunction() | ||
|
||
if(NOT EXISTS "${EXECUTABLE}") | ||
message(FATAL_ERROR | ||
"Executable \"${EXECUTABLE}\" does not exist" | ||
) | ||
endif() | ||
|
||
if(TESTS_DETAILED) | ||
set(discovery_arg "-ln") | ||
set(select_arg "-st") | ||
else() | ||
set(discovery_arg "-lg") | ||
set(select_arg "-sg") | ||
endif() | ||
|
||
execute_process( | ||
COMMAND ${EMULATOR} "${EXECUTABLE}" ${discovery_arg} | ||
OUTPUT_VARIABLE discovered_tests | ||
RESULT_VARIABLE result | ||
ERROR_VARIABLE error | ||
) | ||
if(NOT ${result} EQUAL 0) | ||
message(FATAL_ERROR | ||
"Error executing ${EXECUTABLE}:\n" | ||
"${error}" | ||
) | ||
endif() | ||
separate_arguments(discovered_tests) | ||
foreach(test_name IN LISTS discovered_tests) | ||
add_command( | ||
add_test | ||
"${test_name}" | ||
${EMULATOR} | ||
"${EXECUTABLE}" | ||
${ARGS} | ||
${select_arg} | ||
${test_name} | ||
) | ||
endforeach() | ||
|
||
file(WRITE "${CTEST_FILE}" "${script}") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters