refactor: S24.18 drop do/while(0) wrapper from test CHECK_* macros#563
Conversation
Remove the `do { ... } while (0)` wrapper and the paired
NOLINTBEGIN/END(cppcoreguidelines-macro-usage,cppcoreguidelines-avoid-do-while)
brackets from every test assertion/helper macro (42 files). Multi-statement
bodies become a plain compound `{ ... }` (block scope preserved for macros that
declare a local); single-statement macros were already bare expressions.
The wrapper only protects a multi-statement macro's tail from escaping an
unbraced if/else, and .clang-format's InsertBraces:true (our MISRA 15.6
enforcement) already braces every conditional body before a macro expands, so
the wrapper was dead weight.
Re-enable cppcoreguidelines-avoid-do-while in Tests/.clang-tidy so do/while
can't creep back; macro-usage stays disabled (CppUTest needs macros for caller
__FILE__/__LINE__). Upstream-convention configASSERT / LWIP_PLATFORM_* macros in
the fake config headers keep their do/while (consumed by un-formatted upstream
code); they have no use site governed by Tests/.clang-tidy.
Update CLAUDE.md test-macro convention and DEVLOG.
Closes #552
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (45)
📝 WalkthroughWalkthroughThis PR removes the redundant ChangesTest Assertion Macro Cleanup: Remove do/while Wrappers
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
☀️ Quality Summary 🚦 build-linux-gcc: 100% successful (✔️ 1521 passed) Created by Quality Monitor v1.14.0 (#f3859fd). More details are shown in the GitHub Checks Result. |
Purpose
Closes #552.
CodeRabbit flagged
CHECK_FRAMEDon #551 for not using the housedo { … } while (0)+NOLINT(...avoid-do-while)"safe-test-macro" form. Onreview, that safety is unreachable here:
.clang-formatsetsInsertBraces: true(our MISRA 15.6 enforcement), so every conditional body is already brace-delimited
before any macro expands — the wrapper's tail can never escape an
if/else. Thedo/while(0)is dead weight, and it introduces anavoid-do-whileviolation wethen silence with
NOLINT. This removes the idiom tree-wide and turns the lintcheck back on so it can't return.
Change Description
do { … } while (0)from every test assertion/helper macro (42 files,~60 macros), plus the paired
NOLINTBEGIN/END(cppcoreguidelines-macro-usage,cppcoreguidelines-avoid-do-while)brackets (8 files had them).
{ … }(block scope kept, which mattersfor macros declaring a local — e.g.
CHECK_BLOCK_CONTAINS'scheckBuf,CHECK_IS_FALLBACK'sforvar). Single-statement macros were already bareexpressions and are untouched.
cppcoreguidelines-avoid-do-whileinTests/.clang-tidyso thewrapper can't creep back.
cppcoreguidelines-macro-usagestays disabled(CppUTest needs macros for caller
__FILE__/__LINE__), so no per-site NOLINTis required.
configASSERT(FreeRTOS) andLWIP_PLATFORM_DIAG/LWIP_PLATFORM_ASSERT(lwIP) macros in the fake configheaders as
do/while(0)— they're consumed by un-formatted upstream code whereInsertBraces gives no cover. Safe under the re-enabled check:
configASSERThaszero use sites in linted code;
LWIP_ASSERTexpands only inBdd/Targets/FreeRtosLwip/netif/EthernetIf.c(underBdd/.clang-tidy).CHECK_PRIVALpath reference.Test Evidence
Builds via docker compose (
.devcontainer/docker-compose.yml):debug: 1482 tests pass, no behaviour change (same assertions/counts).tidy(Posix/OpenSsl) withavoid-do-whilenow enforced: green, no do/whilewarnings.
cppcheckclean rebuild: green.clang-formatdry-run: clean tree-wide.freertos-hostdebug build: green (covers FreeRtos/Lwip/MbedTls/FatFs/PlusFattest trees).
Windows/Winsock and the freertos/lwip clang-tidy lanes are CI's job; the
conversions there are identical and mechanical.
Areas Affected
Tests/**(assertion/helper macros),Tests/.clang-tidyCLAUDE.md,DEVLOG.mdCore/,Platform/) touched.🤖 Generated with Claude Code
Summary by CodeRabbit