Add UNITY_OUTPUT_START/COMPLETE_HEADER_DECLARATION macros (closes #799).#834
Open
adityachilka1 wants to merge 1 commit into
Open
Conversation
…owTheSwitch#799). `UNITY_OUTPUT_CHAR` and `UNITY_OUTPUT_FLUSH` already let users provide their own extern prototype via the matching `*_HEADER_DECLARATION` macro (unity_internals.h:333-335 and :349-351). `UNITY_OUTPUT_START` and `UNITY_OUTPUT_COMPLETE` did not — so users wanting to install init / deinit hooks (e.g. serial port open/close, RTT/JTAG bring-up) could override the macro but had no Unity-sanctioned way to declare the function prototype. Add the matching `_HEADER_DECLARATION` triad for both `START` and `COMPLETE`, mirroring the FLUSH pattern verbatim. Add the corresponding commented-out documentation lines to examples/unity_config.h so users discover the new option alongside the existing ones. Purely additive — the new code path only activates when the user defines both `UNITY_OUTPUT_START` (or `_COMPLETE`) AND the matching `*_HEADER_DECLARATION`. Default no-op behaviour is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #799.
The gap
UNITY_OUTPUT_CHARandUNITY_OUTPUT_FLUSHeach have a*_HEADER_DECLARATIONcompanion macro so users can override the output hook with their own function and have Unity emit the matchingexternprototype automatically (seesrc/unity_internals.h:333-335and:349-351).UNITY_OUTPUT_STARTandUNITY_OUTPUT_COMPLETEonly had the override macro — no_HEADER_DECLARATIONcompanion. A user wanting to install init / deinit hooks (e.g. serial-port open + close, RTT/JTAG bring-up, Segger RTT setup as reported by @MaxFlatline in #799) had no Unity-sanctioned way to declare the function prototype, so they had to either declare it ahead of including Unity or fork the project.The fix
Mirror the FLUSH pattern verbatim for both START and COMPLETE in
src/unity_internals.h:…and the same for
UNITY_OUTPUT_COMPLETE.Add the matching commented-out documentation lines to
examples/unity_config.hso users discover the new option in the same place they discover the CHAR/FLUSH variants.Scope
Strictly additive. The new code path is gated by
#ifdef UNITY_OUTPUT_START_HEADER_DECLARATION(or_COMPLETE_…), so:UNITY_OUTPUT_START/_COMPLETEsee zero behavioural difference (the existing#ifndef … #define … #endifpaths are unchanged).Files touched
src/unity_internals.h— 10 lines added (the two#else / #ifdef / extern / #endifblocks).examples/unity_config.h— 2 lines added (the new commented documentation entries).Why no tests
The existing CHAR/FLUSH
_HEADER_DECLARATIONmacros are exercised by the test suite via the spy infrastructure intest/tests/self_assessment_utils.h(startPutcharSpy / startFlushSpy / getFlushSpyCalls) wired throughtest/Makefile:25-28. Adding equivalent spy infrastructure for START/COMPLETE would mean new spy globals + enable/disable helpers + test cases that exerciseUnityBegin/UnityEnd— significantly larger scope than the missing-declaration gap this PR fills. Happy to follow up with a spy + test PR if you'd like that as a separate change.Why no doc-guide update
The existing
docs/UnityConfigurationGuide.mddocuments the override macros (UNITY_OUTPUT_CHAR/FLUSH/START/COMPLETE) but does not currently document the_HEADER_DECLARATIONcompanions for any of them — the declaration variants live exclusively inexamples/unity_config.handsrc/unity_internals.h. To stay symmetric with the existing pattern, this PR leaves the user guide untouched. Again, happy to add a separate docs PR if you'd prefer the guide to surface this feature.Credit
Thanks to @MaxFlatline for filing #799 and giving the exact context (Segger RTT init/deinit hooks).