Skip to content

refactor: S24.18 drop do/while(0) wrapper from test CHECK_* macros#563

Merged
DavidCozens merged 1 commit into
mainfrom
refactor/s24.18-drop-do-while-test-macros
Jun 6, 2026
Merged

refactor: S24.18 drop do/while(0) wrapper from test CHECK_* macros#563
DavidCozens merged 1 commit into
mainfrom
refactor/s24.18-drop-do-while-test-macros

Conversation

@DavidCozens

@DavidCozens DavidCozens commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Purpose

Closes #552.

CodeRabbit flagged CHECK_FRAMED on #551 for not using the house
do { … } while (0) + NOLINT(...avoid-do-while) "safe-test-macro" form. On
review, that safety is unreachable here: .clang-format sets InsertBraces: 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. The
do/while(0) is dead weight, and it introduces an avoid-do-while violation we
then silence with NOLINT. This removes the idiom tree-wide and turns the lint
check back on so it can't return.

Change Description

  • Removed 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).
  • Multi-statement bodies → plain compound { … } (block scope kept, which matters
    for macros declaring a local — e.g. CHECK_BLOCK_CONTAINS's checkBuf,
    CHECK_IS_FALLBACK's for var). Single-statement macros were already bare
    expressions and are untouched.
  • Re-enabled cppcoreguidelines-avoid-do-while in Tests/.clang-tidy so the
    wrapper can't creep back. cppcoreguidelines-macro-usage stays disabled
    (CppUTest needs macros for caller __FILE__/__LINE__), so no per-site NOLINT
    is required.
  • Left the upstream-convention configASSERT (FreeRTOS) and
    LWIP_PLATFORM_DIAG/LWIP_PLATFORM_ASSERT (lwIP) macros in the fake config
    headers as do/while(0) — they're consumed by un-formatted upstream code where
    InsertBraces gives no cover. Safe under the re-enabled check: configASSERT has
    zero use sites in linted code; LWIP_ASSERT expands only in
    Bdd/Targets/FreeRtosLwip/netif/EthernetIf.c (under Bdd/.clang-tidy).
  • Updated the CLAUDE.md "Test code" convention + DEVLOG; fixed a stale
    CHECK_PRIVAL path reference.

Test Evidence

Builds via docker compose (.devcontainer/docker-compose.yml):

  • debug: 1482 tests pass, no behaviour change (same assertions/counts).
  • tidy (Posix/OpenSsl) with avoid-do-while now enforced: green, no do/while
    warnings.
  • cppcheck clean rebuild: green.
  • clang-format dry-run: clean tree-wide.
  • freertos-host debug build: green (covers FreeRtos/Lwip/MbedTls/FatFs/PlusFat
    test 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-tidy
  • CLAUDE.md, DEVLOG.md
  • No production code (Core/, Platform/) touched.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Simplified test assertion macro structures across the test suite by removing unnecessary control-flow wrappers and replacing them with standard compound blocks.
    • Updated test code style guidelines and linter configuration to enforce the new macro patterns.

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
@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e041b318-36c8-443b-b2a2-6fe1e8a404df

📥 Commits

Reviewing files that changed from the base of the PR and between e1f324b and a374cd4.

📒 Files selected for processing (45)
  • CLAUDE.md
  • DEVLOG.md
  • Tests/.clang-tidy
  • Tests/Bdd/Targets/BddTargetErrorTextTest.cpp
  • Tests/FatFs/SolidSyslogFatFsFilePoolTest.cpp
  • Tests/FreeRtos/SolidSyslogFreeRtosMutexTest.cpp
  • Tests/FreeRtos/SolidSyslogPlusTcpAddressTest.cpp
  • Tests/FreeRtos/SolidSyslogPlusTcpDatagramTest.cpp
  • Tests/FreeRtos/SolidSyslogPlusTcpResolverTest.cpp
  • Tests/FreeRtos/SolidSyslogPlusTcpTcpStreamTest.cpp
  • Tests/Lwip/SolidSyslogLwipRawAddressTest.cpp
  • Tests/Lwip/SolidSyslogLwipRawDatagramTest.cpp
  • Tests/Lwip/SolidSyslogLwipRawDnsResolverTest.cpp
  • Tests/Lwip/SolidSyslogLwipRawResolverTest.cpp
  • Tests/Lwip/SolidSyslogLwipRawTcpStreamTest.cpp
  • Tests/MbedTls/SolidSyslogMbedTlsAesGcmPolicyTest.cpp
  • Tests/MbedTls/SolidSyslogMbedTlsHmacSha256PolicyTest.cpp
  • Tests/MbedTls/SolidSyslogMbedTlsStreamPoolTest.cpp
  • Tests/MbedTls/SolidSyslogMbedTlsStreamTest.cpp
  • Tests/PlusFat/SolidSyslogPlusFatFilePoolTest.cpp
  • Tests/SolidSyslogCircularBufferTest.cpp
  • Tests/SolidSyslogFileBlockDeviceTest.cpp
  • Tests/SolidSyslogGetAddrInfoResolverTest.cpp
  • Tests/SolidSyslogOpenSslAesGcmPolicyTest.cpp
  • Tests/SolidSyslogOpenSslHmacSha256PolicyTest.cpp
  • Tests/SolidSyslogPoolTest.cpp
  • Tests/SolidSyslogPosixAddressTest.cpp
  • Tests/SolidSyslogPosixDatagramTest.cpp
  • Tests/SolidSyslogPosixFileTest.cpp
  • Tests/SolidSyslogPosixMessageQueueBufferTest.cpp
  • Tests/SolidSyslogPosixMutexTest.cpp
  • Tests/SolidSyslogPosixTcpStreamTest.cpp
  • Tests/SolidSyslogSdElementTest.cpp
  • Tests/SolidSyslogStdAtomicCounterPoolTest.cpp
  • Tests/SolidSyslogStreamSenderTest.cpp
  • Tests/SolidSyslogTlsStreamPoolTest.cpp
  • Tests/SolidSyslogTlsStreamTest.cpp
  • Tests/SolidSyslogWindowsAtomicCounterPoolTest.cpp
  • Tests/SolidSyslogWindowsFileTest.cpp
  • Tests/SolidSyslogWindowsMutexTest.cpp
  • Tests/SolidSyslogWinsockAddressTest.cpp
  • Tests/SolidSyslogWinsockDatagramTest.cpp
  • Tests/SolidSyslogWinsockResolverTest.cpp
  • Tests/SolidSyslogWinsockTcpStreamTest.cpp
  • Tests/Support/TestUtils.h

📝 Walkthrough

Walkthrough

This PR removes the redundant do { ... } while (0) wrapper idiom and associated NOLINTBEGIN/END(cppcoreguidelines-avoid-do-while) directives from test assertion macros across the entire Tests/ directory. Multi-statement macros are converted to plain compound blocks; single-statement macros to bare expressions. The refactoring is justified by the fact that .clang-format enforces InsertBraces: true, making the do/while wrapper unnecessary for conditional safety. Linter configuration, design documentation, and ~40 test files are updated accordingly.

Changes

Test Assertion Macro Cleanup: Remove do/while Wrappers

Layer / File(s) Summary
Configuration and design documentation update
Tests/.clang-tidy, CLAUDE.md, DEVLOG.md
Tests/.clang-tidy re-enables cppcoreguidelines-avoid-do-while with explanatory comments on multi-statement macro body structure and MISRA brace enforcement. CLAUDE.md test-macro design guide removes the do { ... } while (0) + NOLINTBEGIN/END requirement and documents reliance on .clang-format brace enforcement. DEVLOG.md entry (S24.18) records the sweep rationale, re-enabling logic, upstream-macro exceptions, and verification outcomes.
Test assertion and helper macro refactoring sweep
Tests/Bdd/Targets/*, Tests/FatFs/*, Tests/FreeRtos/*, Tests/Lwip/*, Tests/MbedTls/*, Tests/PlusFat/*, Tests/SolidSyslog*, Tests/Support/*, and platform-specific test suites (Posix, Windows, Winsock)
Removes do { ... } while (0) wrappers and NOLINT directives from ~60 test assertion macro definitions across 40+ test files. Multi-statement macros (CHECK_IS_FALLBACK, CHECK_REPORTED, CHECK_REPORTED_ERROR, etc.) are converted to plain compound blocks to preserve local scope; single-statement macros to bare expressions. Macro logic (assertions, fake expectations, checks) is unchanged; only the statement-wrapper form differs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • DavidCozens/solid-syslog#458: Early pilot of the same do/while removal pattern on CHECK_IS_FALLBACK/CHECK_REPORTED in a Lwip test file, providing precedent and testing the safety of the refactoring approach.

Poem

🐰 The do/while clutter we've cleared away,
Clang-format guards our macros' play,
Plain braces now, no lint to shun,
Assertion sweep—the cleanup's done! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 69.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately summarizes the main change: removing do/while(0) wrappers from test CHECK_* macros per sweep S24.18, which is the primary objective of the changeset.
Description check ✅ Passed The PR description comprehensively covers Purpose (closes #552), Change Description (detailed macro refactoring, linter re-enabling, upstream macro handling, documentation updates), Test Evidence (docker-compose build results), and Areas Affected (Tests/**, CLAUDE.md, DEVLOG.md, no production code).
Linked Issues check ✅ Passed The PR fully addresses the coding objectives from issue #552: ~60 test macros across 42 files converted from do/while(0) to plain compound blocks or bare expressions; cppcoreguidelines-avoid-do-while re-enabled in Tests/.clang-tidy; CLAUDE.md and DEVLOG updated; all test evidence provided (1482 tests pass, tidy/cppcheck/format green).
Out of Scope Changes check ✅ Passed All changes are in-scope to issue #552: Tests/** macro refactoring, Tests/.clang-tidy linter config, CLAUDE.md/DEVLOG documentation updates. No production code (Core/, Platform/) or unrelated modifications present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/s24.18-drop-do-while-test-macros

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

☀️   Quality Summary

   🚦   build-linux-gcc: 100% successful (✔️ 1521 passed)
   🚦   build-freertos-host-tdd-plustcp: 100% successful (✔️ 1872 passed)
   🚦   build-linux-clang: 100% successful (✔️ 1453 passed)
   🚦   sanitize-linux-gcc: 100% successful (✔️ 1453 passed)
   🚦   integration-linux-openssl: 100% successful (✔️ 16 passed)
   🚦   integration-linux-mbedtls: 100% successful (✔️ 14 passed)
   🚦   integration-windows-openssl: 100% successful (✔️ 16 passed)
   🚦   bdd-linux-syslog-ng: 94% successful (✔️ 49 passed, 🙈 3 skipped)
   🚦   bdd-windows-otel: 88% successful (✔️ 46 passed, 🙈 6 skipped)
   🚦   bdd-freertos-qemu-plustcp: 87% successful (✔️ 45 passed, 🙈 7 skipped)
   🚦   bdd-freertos-qemu-lwip: 87% successful (✔️ 45 passed, 🙈 7 skipped)
   🚦   build-windows-msvc: 100% successful (✔️ 1298 passed)
   🚦   build-linux-tunable-override: 100% successful (✔️ 1453 passed)
   ⚠️   Clang-Tidy: No warnings
   ⚠️   CPPCheck: No warnings


Created by Quality Monitor v1.14.0 (#f3859fd). More details are shown in the GitHub Checks Result.

@DavidCozens DavidCozens merged commit 21dd494 into main Jun 6, 2026
27 checks passed
@DavidCozens DavidCozens deleted the refactor/s24.18-drop-do-while-test-macros branch June 6, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

S24.18: drop redundant do/while(0)+NOLINT wrapper from test CHECK_* macros

1 participant