chore: S24.02 adopt CALLED_* test macros + standardise *CallCount naming#322
Conversation
Pure rename ahead of the upcoming CALLED_FUNCTION test macro sweep. Aligns SenderFake_SendCount / DisconnectCount with the *CallCount naming rule that the new token-paste macros enforce. No behaviour change; 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces TestUtils.h's single expression-based CALLED_FUNCTION with three token-paste macros that enforce the <name>CallCount naming rule at compile time: CALLED_FUNCTION(name, count) for local static counters CALLED_FAKE(getter, count) for global-state fake getters CALLED_FAKE_ON(getter, instance, count) for instance-parameter getters Migrates the two pre-existing call sites: - SolidSyslogSwitchingSenderTest.cpp — was the only consumer of the old expression form; every site fits CALLED_FAKE_ON cleanly after the SenderFake *Count -> *CallCount rename. - SolidSyslogErrorTest.cpp — the bespoke CHECK_HANDLER_INVOKED_ONCE / CHECK_HANDLER_NOT_INVOKED macros are now redundant; replaced with CALLED_FUNCTION(handler, ...). CososoTesting namespace + NEVER/ONCE/TWICE/THRICE enum unchanged. 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Aligns the last non-conforming fake-library getter with the *CallCount naming rule. Pure rename; 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Renames g_sleepCallCount to NoOpSleepCallCount (matches the function that increments it), and converts every call-count assertion in the file (50 sites) to the new macros: CALLED_FAKE for global-state OpenSslFake getters, CALLED_FAKE_ON for instance-parameter StreamFake getters, CALLED_FUNCTION for the local sleep counter. 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…macros Renames the local SpyGetHost / SpyGetPort callback counters from get*CallCount to Spy*CallCount (matches the function names) and sweeps every call-count assertion in both files: CALLED_FAKE for global-state SocketFake getters, CALLED_FUNCTION for the local spy counters, with a single explicit-literal site for the reconnect-relative count expression. 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Test utilities header was reachable from files in Tests/ via the implicit-source-dir lookup, but not from Tests/Example/ or Tests/FreeRtos/ where the upcoming sweep will need it. Tests/Support is the established home for shared test infrastructure (SafeString, TestAtomicOps, fake libraries) and is already on the include path of SolidSyslogTests and ExampleTests via the PosixFakes/WinsockFakes PUBLIC include directory. Adds Tests/Support to the FreeRtos test include paths preemptively so the call-count macro sweep can reach TestUtils.h there too. 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ExampleServiceThreadTest: - Renames sleepCallCount -> SleepFakeCallCount (matches the function that increments it). - Converts the call-count assertion to CALLED_FUNCTION; the unrelated lastSleepMs assertion stays as LONGS_EQUAL (it tracks the captured argument, not a count). BlockStoreTest (the substantial site): - Converts three bool flags to int counters following the *CallCount rule: storeFullCallbackInvoked -> StoreFullCallbackCallCount, computeIntegrityCalled -> SpyComputeIntegrityCallCount, verifyIntegrityCalled -> SpyVerifyIntegrityCallCount. Now catches unexpected double-calls. - Renames storeFullCallbackCount -> CountStoreFullInvocationsCallCount and thresholdCallbackCount -> CountThresholdCrossingsCallCount (matches the existing function names). - All call-count assertions in both files migrated to CALLED_FUNCTION / CALLED_FAKE / CALLED_FAKE_ON; CHECK_TRUE/CHECK_FALSE on the converted flags become CALLED_FUNCTION(..., ONCE/NEVER). 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Final conversion pass across the test base. Mechanical sed: - LONGS_EQUAL(N, Foo_BarCallCount()) -> CALLED_FAKE(Foo_Bar, N) - LONGS_EQUAL(N, Foo_BarCallCount(inst)) -> CALLED_FAKE_ON(Foo_Bar, inst, N) - LONGS_EQUAL(N, fooCallCount) -> CALLED_FUNCTION(foo, N) where N is mapped to NEVER/ONCE/TWICE/THRICE for 0..3, otherwise passed through as a literal. Adds #include "TestUtils.h" + `using namespace CososoTesting;` to each newly-affected file. Files swept (19): DatagramFakeTest, OpenSslFakeTest, SenderFakeTest, SocketFakeTest, StoreFakeTest, StreamFakeTest, WinsockFakeTest, SolidSyslogTest, SolidSyslogNullBufferTest, SolidSyslogPosixDatagramTest, SolidSyslogPosixMessageQueueBufferTest, SolidSyslogPosixTcpStreamTest, SolidSyslogGetAddrInfoResolverTest, SolidSyslogWinsockDatagramTest, SolidSyslogWinsockResolverTest, SolidSyslogWinsockTcpStreamTest, Example/SolidSyslogExampleTest, FreeRtos/CmsdkUartTest, FreeRtos/SolidSyslogFreeRtosDatagramTest. Verified: - gcc preset: 1088 tests pass. - freertos-host build: SolidSyslogFreeRtosDatagramTest (21), CmsdkUartTest (15), SolidSyslogFreeRtosSysUpTimeTest (4), SolidSyslogFreeRtosStaticResolverTest (10) — all green. - Winsock variants converted but compile-checked via CI only. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
clang-format -i across the touched test files. Picks up: - a small alignment shift on the bool->int fields in BlockStoreTest - the long `using namespace CososoTesting;` NOLINT comment wraps onto two lines under the 160-col limit - minor indentation tweaks in TlsStreamTest macro definitions No behaviour change; 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
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 (34)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughThis PR standardizes test call-count assertions across 30+ test files by introducing three token-paste macros in a new ChangesTest Macro Standardization
🎯 3 (Moderate) | ⏱️ ~25 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 (✔️ 1109 passed, 🙈 3 skipped) Created by Quality Monitor v1.14.0 (#f3859fd). More details are shown in the GitHub Checks Result. |
Purpose
S24.02 (#321) under E24 Code Hygiene (#254). Closes #321.
The test base mixed several call-count assertion shapes —
LONGS_EQUAL(N, fooCallCount),LONGS_EQUAL(N, FakeFoo_BarCount()),CHECK_TRUE(barCalled)— with inconsistent variable naming(
SenderFake_SendCount,StoreFake_WriteCount,g_sleepCallCount,storeFullCallbackCount, etc.). Two partial implementations(bespoke
CHECK_HANDLER_INVOKED_ONCEmacros inSolidSyslogErrorTest.cppand an expression-form
CALLED_FUNCTION(f, n)already inTestUtils.h)hinted at the shape of the answer but didn't enforce naming. This PR
generalises both into a single design across every test executable.
Change Description
Tests/Support/TestUtils.hnow defines three token-paste macros backedby the existing
CososoTesting::NEVER/ONCE/TWICE/THRICEenum:Token paste enforces the
<functionName>CallCountnaming rule atcompile time, so future drift is caught by the build rather than in
review.
Other notable changes:
Tests/TestUtils.hmoved toTests/Support/TestUtils.hsonon-
Tests/-root executables (Example, FreeRtos) can reach it viathe established Support include path.
<funcName>CallCountrule:SenderFake_SendCount→SendCallCount,StoreFake_WriteCount→WriteCallCount,g_sleepCallCount→NoOpSleepCallCount,getPort/HostCallCount→SpyGetPort/HostCallCount,sleepCallCount→SleepFakeCallCount,storeFullCallbackCount→CountStoreFullInvocationsCallCount,thresholdCallbackCount→CountThresholdCrossingsCallCount.storeFullCallbackInvoked/computeIntegrityCalled/verifyIntegrityCalled. Tests now also catch unexpecteddouble-fires of these callbacks/spies.
CHECK_HANDLER_INVOKED_ONCE/CHECK_HANDLER_NOT_INVOKEDmacros in
SolidSyslogErrorTest.cppremoved in favour of thegeneric
CALLED_FUNCTION(handler, ...).CALLED_FUNCTION(expr, n)callers inSolidSyslogSwitchingSenderTest.cppmigrated toCALLED_FAKE_ON(every site there was structurally an instance-getter call).
Tests/FreeRtos/CMakeLists.txtpicks upTests/Supporton theinclude path of all four FreeRtos host test executables.
E24 itself was renamed from "Hardening" to "Code Hygiene" earlier in
the session — the body was already written for cross-cutting
non-functional sweeps; only the title was wrong. Robustness work
continues to live in E12 / E25 / E26.
Test Evidence
Pure refactor of existing test assertions; no new tests, no
production code touched. Verification:
cmake --build --preset debug --target junit— 1088 tests pass.cmake --build --preset clang-debug --target junit— 1088 tests pass.cmake --build --preset sanitize --target junit— 1088 tests pass.cmake --build --preset coverage --target coverage— 100% lines,100% functions (no change from baseline).
cmake --build --preset tidy— clean.cmake --build --preset cppcheck— clean.clang-format --dry-run --Werrorover Core/Tests/Example — clean.SolidSyslogFreeRtosDatagramTest(21 tests),CmsdkUartTest(15),SolidSyslogFreeRtosSysUpTimeTest(4),SolidSyslogFreeRtosStaticResolverTest(10) — all green.*Winsock*Test.cpp) converted via the samemechanical sweep but exercised by CI only.
Areas Affected
macros. The existing
MinSizehelper and theCososoTestingnamespace stay.
Tests/,Tests/Example/, andTests/FreeRtos/. No production code touched (Tier 1/2 boundarypreserved).
Tests/FreeRtos/CMakeLists.txt— three FreeRtos testexecutables now include
Tests/Supporton their include path.Tests/andthe test build's CMake.
Core/Interface,Core/Source,Platform/, and the public API surface are unchanged.Summary by CodeRabbit
Release Notes
Tests
Chores