Skip to content

Commit 89561a5

Browse files
Merge branch 'main' into MoteusStuff
2 parents 18ab254 + f4f1129 commit 89561a5

File tree

38 files changed

+1268
-27
lines changed

38 files changed

+1268
-27
lines changed

.github/workflows/unit_tests.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Run unit tests
2+
on: push
3+
jobs:
4+
unit_tests:
5+
runs-on: ubuntu-22.04
6+
steps:
7+
- uses: actions/checkout@v4
8+
with: # added this, might fix a bug that's taken over 3 hours to find
9+
submodules: recursive
10+
- name: build
11+
run: |
12+
make test
13+
- name: Notify Discord (success)
14+
if: ${{ success() }}
15+
uses: appleboy/discord-action@v1.0.0
16+
with:
17+
webhook_id: ${{ secrets.DISCORD_BOT_WEBHOOK_ID }} # it also accepts full URL
18+
webhook_token: ${{ secrets.DISCORD_BOT_WEBHOOK_TOKEN }} # it also accepts full URL
19+
message: |
20+
*Unit tests has passed for ${{ github.actor }}.* || ${{ github.repository }} on `${{ github.ref_name }}`
21+
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
22+
- name: Notify Discord (failure)
23+
if: ${{ failure() }}
24+
uses: appleboy/discord-action@v1.0.0
25+
with:
26+
webhook_id: ${{ secrets.DISCORD_BOT_WEBHOOK_ID }} # it also accepts full URL
27+
webhook_token: ${{ secrets.DISCORD_BOT_WEBHOOK_TOKEN }} # it also accepts full URL
28+
message: |
29+
_Unit tests have failed ${{ github.actor }}_
30+
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
31+

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "src/external_pkgs/moteus_ros2"]
55
path = src/external_pkgs/moteus_ros2
66
url = https://github.com/mjbots/moteus_ros2
7+
[submodule "src/external_pkgs/Catch2"]
8+
path = src/external_pkgs/Catch2
9+
url = https://github.com/catchorg/Catch2.git

CMakeLists.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# CMake file for roverflake unit tests
2+
cmake_minimum_required(VERSION 3.20)
3+
4+
set(CMAKE_CXX_STANDARD 17) # cpp 2017 standard
5+
set(CMAKE_CXX_STANDARD_REQUIRED True)
6+
7+
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/src/external_pkgs/Catch2 ${CMAKE_CURRENT_BINARY_DIR}/external_pkgs/Catch2) # Include Catch2 for unit tests
8+
9+
set(BUILD_DIR ${CMAKE_CURRENT_LIST_DIR}/build)
10+
set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
11+
set(SAMPLE_PKG_DIR ${SRC_DIR}/rover_samples/rv_sample_package/)
12+
set(ROVER_UTILS_DIR ${SRC_DIR}/rover_utils/)
13+
14+
# Code under test sources + directories
15+
include_directories(
16+
${SAMPLE_PKG_DIR}/include
17+
${ROVER_UTILS_DIR}/include
18+
19+
# add more directories with needed .h headers
20+
)
21+
22+
set(ROVERFLAKE_SOURCES
23+
${SAMPLE_PKG_DIR}/src/unit_test_example_class.cpp # just an example
24+
# Add roverflake files here (code under test)
25+
26+
# Autogenerated files:
27+
# ${BUILD_DIR}/autogen/*.cpp
28+
# ${BUILD_DIR}/autogen/*.c
29+
)
30+
31+
set(TEST_SOURCES
32+
${SRC_DIR}/rover_samples/rv_sample_package/test/unit_test_example.cpp
33+
# add more unit test files
34+
)
35+
36+
add_executable(unit_tests
37+
${TEST_SOURCES}
38+
${ROVERFLAKE_SOURCES}
39+
)
40+
41+
target_link_libraries(unit_tests PRIVATE
42+
Catch2::Catch2WithMain)
43+
44+
target_compile_options(unit_tests PRIVATE
45+
-Wall
46+
-Wextra
47+
# -Werror # Uncomment to be verry strict
48+
)
49+
50+
include(CTest)
51+
include(Catch)
52+
catch_discover_tests(unit_tests)

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Makefile for common libraries
2+
3+
BUILD_DIR:=build
4+
5+
all: clean configure build test
6+
7+
configure:
8+
@mkdir -p $(BUILD_DIR)
9+
@cd $(BUILD_DIR) && cmake ..
10+
11+
build: configure
12+
@$(MAKE) -C $(BUILD_DIR)
13+
14+
clean:
15+
@rm -rf $(BUILD_DIR)
16+
17+
test: configure build
18+
@${BUILD_DIR}/unit_tests
19+
20+
21+
.PHONY: all configure build clean test

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ From the root of RoverFlake2:
3939

4040
If you get an error... panic, scream, and hurl insults at your computer. Then look at common issues and ask for help in the discord.
4141

42+
### Unit Tests
43+
We use Catch2 for CPP unit tests. To keep it simple, we don't integrate with colcon tests, we have a seperate CMakeLists.txt and Makefile at the root, to handle all unit tests.
44+
To build and run tests: (the -j16 is just to compile faster by specifying how many cores to use)
45+
> `make -j16 test`
46+
To add tests, open up the CMakeLists.txt and manually add paths to test files. Follow the comments within the file.
47+
Catch2 is powerful, lightweight, and easy to use. It has a lot of built in macros to help with testing but even just the basics is enough to get by.
48+
4249
### COMMON ISSUES & TROUBLESHOOTING
4350
arm_hardware_interface fails to build:
4451

bestHammer.pt

5.96 MB
Binary file not shown.

setup_scripts/setup_everything_common.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ apt_packages_to_install=(
4848
"libsfml-dev"
4949
)
5050

51-
52-
5351
# Loop through the package list and install missing packages
5452
for package in "${apt_packages_to_install[@]}"; do
5553
if is_package_installed "$package"; then

src/aruco_detector/package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<!-- Rosdep fails with the following: -->
1818
<!-- <depend>cv2_aruco</depend> -->
1919
<!-- <depend>OpenCV</depend> -->
20+
<!-- ROWTAG MERGE WARNING -->
21+
<depend>OpenCV</depend>
22+
<depend>cv2_aruco</depend>
2023

2124
<test_depend>ament_lint_auto</test_depend>
2225
<test_depend>ament_lint_common</test_depend>

src/aruco_detector/src/DetectMarker.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,4 @@ int main(int argc, char** argv) {
8686
rclcpp::spin(node);
8787
rclcpp::shutdown();
8888
return 0;
89-
9089
}

0 commit comments

Comments
 (0)