Skip to content

Commit

Permalink
Allow user-defined TEST_PROTECT & TEST_ABORT macros
Browse files Browse the repository at this point in the history
However rare, this update covers real-world use cases where:
- Unity is used to provide the assertion macros only, and an external
  test harness/runner is used for test orchestration/reporting.
- Calling longjmp on a given platform is possible, but has a
  platform-specific (or implementation-specific) set of prerequisites,
e.g. privileged access level.

Enable project-specific customisation of TEST_PROTECT and TEST_ABORT
macros.
- Use the user-defined UNITY_TEST_ABORT if available; fall back to
  default behaviour otherwise.
- Use the user-defined UNITY_TEST_PROTECT if available; fall back to
  default behaviour otherwise.
- These may be defined independently.
  • Loading branch information
fkjagodzinski committed Aug 29, 2023
1 parent cb03c3a commit 8acfb0a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/unity_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,13 +759,25 @@ extern const char UnityStrErrShorthand[];
* Test Running Macros
*-------------------------------------------------------*/

#ifdef UNITY_TEST_PROTECT
#define TEST_PROTECT() UNITY_TEST_PROTECT()
#else
#ifndef UNITY_EXCLUDE_SETJMP_H
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
#define TEST_ABORT() longjmp(Unity.AbortFrame, 1)
#else
#define TEST_PROTECT() 1
#endif
#endif

#ifdef UNITY_TEST_ABORT
#define TEST_ABORT() UNITY_TEST_ABORT()
#else
#ifndef UNITY_EXCLUDE_SETJMP_H
#define TEST_ABORT() longjmp(Unity.AbortFrame, 1)
#else
#define TEST_ABORT() return
#endif
#endif

/* Automatically enable variadic macros support, if it not enabled before */
#ifndef UNITY_SUPPORT_VARIADIC_MACROS
Expand Down

0 comments on commit 8acfb0a

Please sign in to comment.