Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ament_add_gtest_test: add TEST_NAME parameter #492

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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