Skip to content

Commit 7580a2a

Browse files
committed
fix test and coverage script
1 parent 5c0e37c commit 7580a2a

5 files changed

Lines changed: 75 additions & 4 deletions

File tree

.github/workflows/ros2-rolling.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
- uses: 'ros-industrial/industrial_ci@master'
2020
env: ${{matrix.env}}
2121
with:
22-
package-name: plotjuggler
22+
package-name: behaviortree_cpp

.github/workflows/ros2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ jobs:
2020
- uses: 'ros-industrial/industrial_ci@master'
2121
env: ${{matrix.env}}
2222
with:
23-
package-name: plotjuggler
23+
package-name: behaviortree_cpp

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ TODO.md
2929
/.worktrees/*
3030
/docs/plans/*
3131
/coverage_report/*
32+
/coverage.info

run_coverage.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Code coverage script for BehaviorTree.CPP
5+
# Based on .github/workflows/cmake_ubuntu.yml coverage job
6+
7+
BUILD_DIR="build/coverage"
8+
COVERAGE_FILE="coverage.info"
9+
COVERAGE_HTML_DIR="coverage_report"
10+
11+
echo "=== BehaviorTree.CPP Code Coverage ==="
12+
13+
# Check for lcov
14+
if ! command -v lcov &> /dev/null; then
15+
echo "Error: lcov is not installed."
16+
echo "Install with: sudo apt-get install lcov"
17+
exit 1
18+
fi
19+
20+
# Clean previous coverage data
21+
echo "Cleaning previous coverage data..."
22+
rm -rf "$BUILD_DIR" "$COVERAGE_FILE" "$COVERAGE_HTML_DIR"
23+
24+
# Configure CMake with coverage flags (plain CMake approach)
25+
echo "Configuring CMake with coverage flags..."
26+
cmake -S . -B "$BUILD_DIR" \
27+
-DCMAKE_BUILD_TYPE=Debug \
28+
-DCMAKE_C_FLAGS="--coverage -fprofile-update=atomic" \
29+
-DCMAKE_CXX_FLAGS="--coverage -fprofile-update=atomic"
30+
31+
# Build
32+
echo "Building..."
33+
cmake --build "$BUILD_DIR" --parallel
34+
35+
# Run tests
36+
echo "Running tests..."
37+
ctest --test-dir "$BUILD_DIR" --output-on-failure
38+
39+
# Collect coverage
40+
echo "Collecting coverage data..."
41+
lcov --capture --directory "$BUILD_DIR" \
42+
--output-file "$COVERAGE_FILE"
43+
44+
# Extract only project source files
45+
echo "Filtering coverage data..."
46+
lcov --extract "$COVERAGE_FILE" \
47+
"$(pwd)/include/*" \
48+
"$(pwd)/src/*" \
49+
--output-file "$COVERAGE_FILE" || true
50+
51+
# Remove contrib files
52+
lcov --remove "$COVERAGE_FILE" \
53+
'*/contrib/*' \
54+
--output-file "$COVERAGE_FILE" || true
55+
56+
# Show summary
57+
echo ""
58+
echo "=== Coverage Summary ==="
59+
lcov --list "$COVERAGE_FILE"
60+
61+
# Generate HTML report
62+
if command -v genhtml &> /dev/null; then
63+
echo ""
64+
echo "Generating HTML report..."
65+
genhtml "$COVERAGE_FILE" --output-directory "$COVERAGE_HTML_DIR"
66+
echo "HTML report generated at: $COVERAGE_HTML_DIR/index.html"
67+
fi
68+
69+
echo ""
70+
echo "Coverage data saved to: $COVERAGE_FILE"

tests/gtest_basic_types.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ TEST(BasicTypes, ConvertFromString_Double)
119119
ASSERT_DOUBLE_EQ(convertFromString<double>("-2.5"), -2.5);
120120
ASSERT_DOUBLE_EQ(convertFromString<double>("0.0"), 0.0);
121121

122-
// Invalid double throws std::invalid_argument
123-
ASSERT_THROW((void)convertFromString<double>("not_a_number"), std::invalid_argument);
122+
// Invalid double throws RuntimeError
123+
ASSERT_THROW((void)convertFromString<double>("not_a_number"), RuntimeError);
124124
}
125125

126126
TEST(BasicTypes, ConvertFromString_Bool)

0 commit comments

Comments
 (0)