Skip to content

Add UNITY_OUTPUT_START/COMPLETE_HEADER_DECLARATION macros (closes #799).#834

Open
adityachilka1 wants to merge 1 commit into
ThrowTheSwitch:masterfrom
adityachilka1:fix/output-start-complete-header-declaration
Open

Add UNITY_OUTPUT_START/COMPLETE_HEADER_DECLARATION macros (closes #799).#834
adityachilka1 wants to merge 1 commit into
ThrowTheSwitch:masterfrom
adityachilka1:fix/output-start-complete-header-declaration

Conversation

@adityachilka1
Copy link
Copy Markdown

Closes #799.

The gap

UNITY_OUTPUT_CHAR and UNITY_OUTPUT_FLUSH each have a *_HEADER_DECLARATION companion macro so users can override the output hook with their own function and have Unity emit the matching extern prototype automatically (see src/unity_internals.h:333-335 and :349-351).

UNITY_OUTPUT_START and UNITY_OUTPUT_COMPLETE only had the override macro — no _HEADER_DECLARATION companion. 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:

 #ifndef UNITY_OUTPUT_START
 #define UNITY_OUTPUT_START()
+#else
+  /* If defined as something else, make sure we declare it here so it's ready for use */
+  #ifdef UNITY_OUTPUT_START_HEADER_DECLARATION
+    extern void UNITY_OUTPUT_START_HEADER_DECLARATION;
+  #endif
 #endif

…and the same for UNITY_OUTPUT_COMPLETE.

Add the matching commented-out documentation lines to examples/unity_config.h so 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:

  • Users who haven't defined the new macro see zero behavioural difference.
  • Users who haven't defined UNITY_OUTPUT_START / _COMPLETE see zero behavioural difference (the existing #ifndef … #define … #endif paths are unchanged).
  • The new prototype is only emitted when the user has explicitly opted in to both the override and the declaration, matching the existing CHAR/FLUSH contract.

Files touched

  • src/unity_internals.h — 10 lines added (the two #else / #ifdef / extern / #endif blocks).
  • examples/unity_config.h — 2 lines added (the new commented documentation entries).

Why no tests

The existing CHAR/FLUSH _HEADER_DECLARATION macros are exercised by the test suite via the spy infrastructure in test/tests/self_assessment_utils.h (startPutcharSpy / startFlushSpy / getFlushSpyCalls) wired through test/Makefile:25-28. Adding equivalent spy infrastructure for START/COMPLETE would mean new spy globals + enable/disable helpers + test cases that exercise UnityBegin / 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.md documents the override macros (UNITY_OUTPUT_CHAR/FLUSH/START/COMPLETE) but does not currently document the _HEADER_DECLARATION companions for any of them — the declaration variants live exclusively in examples/unity_config.h and src/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).

…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.
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.

UNITY_OUTPUT_START and UNITY_OUTPUT_COMPLETE macros have no _HEADER_DECLARATION

2 participants