From 34699da101215393ab379dc447e27b9330e947dc Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Tue, 27 Feb 2024 20:04:04 -0600 Subject: [PATCH] Add some basic tests to ament_cmake_libraries (#512) Signed-off-by: Scott K Logan --- ament_cmake_libraries/CMakeLists.txt | 5 +++ ament_cmake_libraries/test/CMakeLists.txt | 1 + .../test/test_deduplicate.cmake | 31 +++++++++++++++++++ ament_cmake_libraries/test/utilities.cmake | 8 +++++ 4 files changed, 45 insertions(+) create mode 100644 ament_cmake_libraries/test/CMakeLists.txt create mode 100644 ament_cmake_libraries/test/test_deduplicate.cmake create mode 100644 ament_cmake_libraries/test/utilities.cmake diff --git a/ament_cmake_libraries/CMakeLists.txt b/ament_cmake_libraries/CMakeLists.txt index 20092c42..3d5b8675 100644 --- a/ament_cmake_libraries/CMakeLists.txt +++ b/ament_cmake_libraries/CMakeLists.txt @@ -8,6 +8,11 @@ ament_package( CONFIG_EXTRAS "ament_cmake_libraries-extras.cmake" ) +include(CTest) +if(BUILD_TESTING) + add_subdirectory(test) +endif() + install( DIRECTORY cmake DESTINATION share/${PROJECT_NAME} diff --git a/ament_cmake_libraries/test/CMakeLists.txt b/ament_cmake_libraries/test/CMakeLists.txt new file mode 100644 index 00000000..e84ab5e1 --- /dev/null +++ b/ament_cmake_libraries/test/CMakeLists.txt @@ -0,0 +1 @@ +add_test(deduplicate "${CMAKE_COMMAND}" -P ${CMAKE_CURRENT_LIST_DIR}/test_deduplicate.cmake) diff --git a/ament_cmake_libraries/test/test_deduplicate.cmake b/ament_cmake_libraries/test/test_deduplicate.cmake new file mode 100644 index 00000000..23cd4cd1 --- /dev/null +++ b/ament_cmake_libraries/test/test_deduplicate.cmake @@ -0,0 +1,31 @@ +include("${CMAKE_CURRENT_LIST_DIR}/utilities.cmake") + +# Empty +set(TEST_IN "") +ament_libraries_deduplicate(ACTUAL ${TEST_IN}) +assert_equal("" "${ACTUAL}") + +# Noop +set(TEST_IN "foo;bar;baz") +ament_libraries_deduplicate(ACTUAL ${TEST_IN}) +assert_equal("foo;bar;baz" "${ACTUAL}") + +# Simple +set(TEST_IN "foo;bar;baz;bar") +ament_libraries_deduplicate(ACTUAL ${TEST_IN}) +assert_equal("foo;baz;bar" "${ACTUAL}") + +# With matching build configs +set(TEST_IN "debug;foo;debug;bar;debug;baz;debug;bar") +ament_libraries_deduplicate(ACTUAL ${TEST_IN}) +assert_equal("debug;foo;debug;baz;debug;bar" "${ACTUAL}") + +# With missing build configs +set(TEST_IN "debug;foo;debug;bar;debug;baz;bar") +ament_libraries_deduplicate(ACTUAL ${TEST_IN}) +assert_equal("debug;foo;debug;bar;debug;baz;bar" "${ACTUAL}") + +# With mismatched build configs +set(TEST_IN "debug;foo;debug;bar;debug;baz;release;bar") +ament_libraries_deduplicate(ACTUAL ${TEST_IN}) +assert_equal("debug;foo;debug;bar;debug;baz;release;bar" "${ACTUAL}") diff --git a/ament_cmake_libraries/test/utilities.cmake b/ament_cmake_libraries/test/utilities.cmake new file mode 100644 index 00000000..8bef757f --- /dev/null +++ b/ament_cmake_libraries/test/utilities.cmake @@ -0,0 +1,8 @@ +set(ament_cmake_libraries_DIR "${CMAKE_CURRENT_LIST_DIR}/../cmake") +include("${CMAKE_CURRENT_LIST_DIR}/../ament_cmake_libraries-extras.cmake") + +macro(assert_equal EXPECTED ACTUAL) + if(NOT "${EXPECTED}" STREQUAL "${ACTUAL}") + message(SEND_ERROR "Assert failed: Expected '${EXPECTED}', got '${ACTUAL}'") + endif() +endmacro()