diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d45167d..c7a47eb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,11 +25,24 @@ jobs: key: ${{ runner.os }}-platformio-native-${{ hashFiles('platformio.ini') }} - name: Install PlatformIO - run: pip install --upgrade platformio + run: pip install --upgrade platformio gcovr - name: Run native unit tests run: pio test -e native + - name: Coverage report + run: | + output=$(gcovr --root . --filter 'src/' --exclude 'src/main\.cpp' --print-summary --fail-under-line 90) + status=$? + { + echo '### Coverage (src/, excluding main.cpp)' + echo '```' + echo "$output" + echo '```' + } >> "$GITHUB_STEP_SUMMARY" + echo "$output" + exit $status + kb2040-build: runs-on: ubuntu-latest steps: diff --git a/CLAUDE.md b/CLAUDE.md index abc7d07..30a786b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,6 +6,7 @@ - All new logic should have unit tests in `test/` to prevent regressions. - Tests run on the native PlatformIO environment (no hardware required) — keep them that way. Do not introduce test dependencies that require Arduino or physical hardware. - When fixing a bug, add a test that would have caught it. +- CI enforces a minimum line-coverage threshold (via `gcovr`, currently 90%) on `src/`, excluding `main.cpp` (Arduino-only, can't run on native). Keep new logic covered well enough to not drop below that bar — don't lower the threshold in `.github/workflows/ci.yml` just to unblock a PR; that's a deliberate call for a human to make. **Bug fixes and regression test** - Any time you fix a bug, that bugfix should be covered by a new regression test. diff --git a/platformio.ini b/platformio.ini index df15e20..9cc2b93 100644 --- a/platformio.ini +++ b/platformio.ini @@ -29,3 +29,5 @@ platform = native test_build_src = yes build_src_filter = +<*> - test_framework = unity +build_flags = --coverage +extra_scripts = pre:scripts/native_coverage_linkflags.py diff --git a/scripts/native_coverage_linkflags.py b/scripts/native_coverage_linkflags.py new file mode 100644 index 0000000..13f4326 --- /dev/null +++ b/scripts/native_coverage_linkflags.py @@ -0,0 +1,5 @@ +Import("env") + +# PlatformIO's `build_flags` only reach the compile step for --coverage; the +# link step needs it too so the gcov/profiling runtime gets linked in. +env.Append(LINKFLAGS=["--coverage"])