Skip to content

Commit

Permalink
Add some basic tests to ament_cmake_libraries (#512)
Browse files Browse the repository at this point in the history
Signed-off-by: Scott K Logan <[email protected]>
  • Loading branch information
cottsay authored Feb 28, 2024
1 parent cf8d4d3 commit 34699da
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ament_cmake_libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions ament_cmake_libraries/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_test(deduplicate "${CMAKE_COMMAND}" -P ${CMAKE_CURRENT_LIST_DIR}/test_deduplicate.cmake)
31 changes: 31 additions & 0 deletions ament_cmake_libraries/test/test_deduplicate.cmake
Original file line number Diff line number Diff line change
@@ -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}")
8 changes: 8 additions & 0 deletions ament_cmake_libraries/test/utilities.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 34699da

Please sign in to comment.