-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split ament_add_gmock into _executable and _test. (#497)
This way we can use one part without the other when we need to. Signed-off-by: Chris Lalancette <[email protected]>
- Loading branch information
1 parent
4f6f349
commit be887a4
Showing
6 changed files
with
201 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2014-2015 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# | ||
# Add an executable using gmock. | ||
# | ||
# Call add_executable(target ARGN) and link it against the gmock library. | ||
# It does not register the executable as a test. | ||
# | ||
# If gmock is not available the specified target will not be created and | ||
# therefore the target existence should be checked before being used. | ||
# | ||
# :param target: the target name which will also be used as the test name | ||
# :type target: string | ||
# :param ARGN: the list of source files | ||
# :type ARGN: list of strings | ||
# :param SKIP_LINKING_MAIN_LIBRARIES: if set skip linking against the gmock | ||
# main libraries | ||
# :type SKIP_LINKING_MAIN_LIBRARIES: option | ||
# | ||
# @public | ||
# | ||
macro(ament_add_gmock_executable target) | ||
_ament_cmake_gmock_find_gmock() | ||
if(GMOCK_FOUND) | ||
_ament_add_gmock_executable("${target}" ${ARGN}) | ||
endif() | ||
endmacro() | ||
|
||
function(_ament_add_gmock_executable target) | ||
cmake_parse_arguments(ARG "SKIP_LINKING_MAIN_LIBRARIES" "" "" ${ARGN}) | ||
if(NOT ARG_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR | ||
"ament_add_gmock_executable() must be invoked with at least one source file") | ||
endif() | ||
|
||
# should be EXCLUDE_FROM_ALL if it would be possible | ||
# to add this target as a dependency to the "test" target | ||
add_executable("${target}" ${ARG_UNPARSED_ARGUMENTS}) | ||
target_include_directories("${target}" SYSTEM PRIVATE "${GMOCK_INCLUDE_DIRS}") | ||
if(NOT ARG_SKIP_LINKING_MAIN_LIBRARIES) | ||
target_link_libraries("${target}" ${GMOCK_MAIN_LIBRARIES}) | ||
endif() | ||
target_link_libraries("${target}" ${GMOCK_LIBRARIES}) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# Copyright 2014-2015 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# | ||
# Add an existing executable using gmock as a test. | ||
# | ||
# Register an executable created with ament_add_gmock_executable() as a test. | ||
# If the specified target does not exist the registration is skipped. | ||
# | ||
# :param target: the target name which will also be used as the test name | ||
# if TEST_NAME is not set | ||
# :type target: string | ||
# :param RUNNER: the path to the test runner script (default: see ament_add_test). | ||
# :type RUNNER: string | ||
# :param TIMEOUT: the test timeout in seconds, | ||
# default defined by ``ament_add_test()`` | ||
# :type TIMEOUT: integer | ||
# :param WORKING_DIRECTORY: the working directory for invoking the | ||
# executable in, default defined by ``ament_add_test()`` | ||
# :type WORKING_DIRECTORY: string | ||
# :param TEST_NAME: the name of the test | ||
# :type TEST_NAME: string | ||
# :param SKIP_TEST: if set mark the test as being skipped | ||
# :type SKIP_TEST: option | ||
# :param ENV: list of env vars to set; listed as ``VAR=value`` | ||
# :type ENV: list of strings | ||
# :param APPEND_ENV: list of env vars to append if already set, otherwise set; | ||
# listed as ``VAR=value`` | ||
# :type APPEND_ENV: list of strings | ||
# :param APPEND_LIBRARY_DIRS: list of library dirs to append to the appropriate | ||
# OS specific env var, a la LD_LIBRARY_PATH | ||
# :type APPEND_LIBRARY_DIRS: list of strings | ||
# | ||
# @public | ||
# | ||
function(ament_add_gmock_test target) | ||
if(NOT TARGET ${target}) | ||
return() | ||
endif() | ||
|
||
cmake_parse_arguments(ARG | ||
"SKIP_TEST" | ||
"RUNNER;TIMEOUT;WORKING_DIRECTORY;TEST_NAME" | ||
"APPEND_ENV;APPEND_LIBRARY_DIRS;ENV" | ||
${ARGN}) | ||
if(ARG_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR | ||
"ament_add_gmock_test() called with unused arguments: ${ARGN}") | ||
endif() | ||
|
||
if(ARG_TEST_NAME) | ||
set(TEST_NAME "${ARG_TEST_NAME}") | ||
else() | ||
set(TEST_NAME "${target}") | ||
endif() | ||
|
||
set(executable "$<TARGET_FILE:${target}>") | ||
set(result_file "${AMENT_TEST_RESULTS_DIR}/${PROJECT_NAME}/${target}.gtest.xml") | ||
set(cmd | ||
"${executable}" | ||
"--gtest_output=xml:${result_file}") | ||
if(ARG_ENV) | ||
set(ARG_ENV "ENV" ${ARG_ENV}) | ||
endif() | ||
if(ARG_APPEND_ENV) | ||
set(ARG_APPEND_ENV "APPEND_ENV" ${ARG_APPEND_ENV}) | ||
endif() | ||
if(ARG_APPEND_LIBRARY_DIRS) | ||
set(ARG_APPEND_LIBRARY_DIRS "APPEND_LIBRARY_DIRS" ${ARG_APPEND_LIBRARY_DIRS}) | ||
endif() | ||
if(ARG_RUNNER) | ||
set(ARG_RUNNER "RUNNER" ${ARG_RUNNER}) | ||
endif() | ||
if(ARG_TIMEOUT) | ||
set(ARG_TIMEOUT "TIMEOUT" ${ARG_TIMEOUT}) | ||
endif() | ||
if(ARG_WORKING_DIRECTORY) | ||
set(ARG_WORKING_DIRECTORY "WORKING_DIRECTORY" "${ARG_WORKING_DIRECTORY}") | ||
endif() | ||
# Options come out TRUE or FALSE but need to be passed as value or empty | ||
if(ARG_SKIP_TEST) | ||
set(ARG_SKIP_TEST "SKIP_TEST") | ||
else() | ||
set(ARG_SKIP_TEST "") | ||
endif() | ||
|
||
ament_add_test( | ||
"${TEST_NAME}" | ||
COMMAND ${cmd} | ||
OUTPUT_FILE "${CMAKE_BINARY_DIR}/ament_cmake_gmock/${TEST_NAME}.txt" | ||
RESULT_FILE "${result_file}" | ||
${ARG_RUNNER} | ||
${ARG_SKIP_TEST} | ||
${ARG_ENV} | ||
${ARG_APPEND_ENV} | ||
${ARG_APPEND_LIBRARY_DIRS} | ||
${ARG_TIMEOUT} | ||
${ARG_WORKING_DIRECTORY} | ||
) | ||
set_tests_properties( | ||
"${TEST_NAME}" | ||
PROPERTIES | ||
REQUIRED_FILES "${executable}" | ||
LABELS "gmock" | ||
) | ||
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 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