diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..03ecdf5 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,27 @@ +name: ci +on: + pull_request: + push: + branches: + - main + +permissions: + contents: read + packages: read + issues: write # posting and hiding bot comments + pull-requests: write # posting and hiding bot comments + +jobs: + test: + strategy: + fail-fast: false + matrix: + ALPINE_VERSION: ["3.20"] + ROS_DISTRO: ["humble", "jazzy"] + uses: alpine-ros/alpine-ros-ci-workflows/.github/workflows/ros2.yaml@support-ros2 + with: + enable-bot-comment: true + alpine-version: ${{ matrix.ALPINE_VERSION }} + ros-distro: ${{ matrix.ROS_DISTRO }} + secrets: + bot-comment-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/sample_ros2_pkg/CMakeLists.txt b/sample_ros2_pkg/CMakeLists.txt new file mode 100644 index 0000000..33acdf4 --- /dev/null +++ b/sample_ros2_pkg/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.8) +project(sample_ros2_pkg) + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +find_package(ament_cmake REQUIRED) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + set(ament_cmake_copyright_FOUND TRUE) + set(ament_cmake_cpplint_FOUND TRUE) + ament_lint_auto_find_test_dependencies() + + find_package(ament_cmake_gtest REQUIRED) + ament_add_gtest(test_sample + test/src/test_sample.cpp + src/sample.cpp) + target_include_directories(test_sample PUBLIC + $ + $) +endif() + +install( + DIRECTORY include + DESTINATION include/${PROJECT_NAME} +) + +ament_package() diff --git a/sample_ros2_pkg/include/sample_ros2_pkg/sample.h b/sample_ros2_pkg/include/sample_ros2_pkg/sample.h new file mode 100644 index 0000000..06ae34c --- /dev/null +++ b/sample_ros2_pkg/include/sample_ros2_pkg/sample.h @@ -0,0 +1,4 @@ +#pragma once + +int sum(const int a, const int b); +int mul(const int a, const int b); diff --git a/sample_ros2_pkg/package.xml b/sample_ros2_pkg/package.xml new file mode 100644 index 0000000..65870b7 --- /dev/null +++ b/sample_ros2_pkg/package.xml @@ -0,0 +1,21 @@ + + + + sample_ros2_pkg + 0.0.0 + Sample ROS 2 package for testing + Kazuki Takahashi + N/A + + ament_cmake + + ament_lint_auto + ament_lint_common + ament_cmake_gtest + + + ament_cmake + + diff --git a/sample_ros2_pkg/src/sample.cpp b/sample_ros2_pkg/src/sample.cpp new file mode 100644 index 0000000..f3413c3 --- /dev/null +++ b/sample_ros2_pkg/src/sample.cpp @@ -0,0 +1,13 @@ +int sum(const int a, const int b) +{ + // covered + const int c = a + b; + return c; +} + +int mul(const int a, const int b) +{ + // not covered + const int c = a * b; + return c; +} diff --git a/sample_ros2_pkg/test/src/test_sample.cpp b/sample_ros2_pkg/test/src/test_sample.cpp new file mode 100644 index 0000000..81e8b05 --- /dev/null +++ b/sample_ros2_pkg/test/src/test_sample.cpp @@ -0,0 +1,15 @@ +#include + +#include + +TEST(Sum, Sum) +{ + ASSERT_EQ(sum(1, 2), 3); +} + +int main(int argc, char ** argv) +{ + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +}