Skip to content

Commit

Permalink
ament_add_gtest_test: add TEST_NAME parameter (#492)
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Wecht <cwecht@mailbox.org>
Co-authored-by: Christopher Wecht <christopher.wecht@itk-engineering.de>
  • Loading branch information
cwecht and cwechtAtITK authored Nov 15, 2023
1 parent 46600b9 commit 4f6f349
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions ament_cmake_gtest/cmake/ament_add_gtest_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# 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
Expand All @@ -28,6 +29,8 @@
# :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``
Expand All @@ -48,16 +51,23 @@ function(ament_add_gtest_test target)

cmake_parse_arguments(ARG
"SKIP_TEST"
"RUNNER;TIMEOUT;WORKING_DIRECTORY"
"RUNNER;TIMEOUT;WORKING_DIRECTORY;TEST_NAME"
"APPEND_ENV;APPEND_LIBRARY_DIRS;ENV"
${ARGN})
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"ament_add_gtest_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(result_file "${AMENT_TEST_RESULTS_DIR}/${PROJECT_NAME}/${TEST_NAME}.gtest.xml")
set(cmd
"${executable}"
"--gtest_output=xml:${result_file}")
Expand All @@ -84,9 +94,9 @@ function(ament_add_gtest_test target)
endif()

ament_add_test(
"${target}"
"${TEST_NAME}"
COMMAND ${cmd}
OUTPUT_FILE "${CMAKE_BINARY_DIR}/ament_cmake_gtest/${target}.txt"
OUTPUT_FILE "${CMAKE_BINARY_DIR}/ament_cmake_gtest/${TEST_NAME}.txt"
RESULT_FILE "${result_file}"
${ARG_RUNNER}
${ARG_SKIP_TEST}
Expand All @@ -97,7 +107,7 @@ function(ament_add_gtest_test target)
${ARG_WORKING_DIRECTORY}
)
set_tests_properties(
"${target}"
"${TEST_NAME}"
PROPERTIES
REQUIRED_FILES "${executable}"
LABELS "gtest"
Expand Down

0 comments on commit 4f6f349

Please sign in to comment.