From ef1e2ad58c61f42c070e09d4ba0e8bc7b27d9b92 Mon Sep 17 00:00:00 2001 From: jsalling Date: Sat, 14 Jan 2017 11:15:30 -0600 Subject: [PATCH] Option to exclude setjump/longjmp, setjmp.h Using this option changes the control flow of Unity, but is useful on constrained embedded systems. You can't fully simulate the power of 'longjmp' with just 'return', but Unity still works well, all tests pass. --- src/unity_internals.h | 10 +++++++++- test/tests/testunity.c | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/unity_internals.h b/src/unity_internals.h index e5cfe5e..a36eadd 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -11,7 +11,9 @@ #include "unity_config.h" #endif +#ifndef UNITY_EXCLUDE_SETJMP_H #include +#endif #ifndef UNITY_EXCLUDE_MATH_H #include @@ -371,7 +373,9 @@ struct UNITY_STORAGE_T UNITY_COUNTER_TYPE TestIgnores; UNITY_COUNTER_TYPE CurrentTestFailed; UNITY_COUNTER_TYPE CurrentTestIgnored; +#ifndef UNITY_EXCLUDE_SETJMP_H jmp_buf AbortFrame; +#endif }; extern struct UNITY_STORAGE_T Unity; @@ -534,9 +538,13 @@ extern const char UnityStrErr64[]; * Test Running Macros *-------------------------------------------------------*/ +#ifndef UNITY_EXCLUDE_SETJMP_H #define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0) - #define TEST_ABORT() longjmp(Unity.AbortFrame, 1) +#else +#define TEST_PROTECT() 1 +#define TEST_ABORT() return +#endif /* This tricky series of macros gives us an optional line argument to treat it as RUN_TEST(func, num=__LINE__) */ #ifndef RUN_TEST diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 5f52ce2..7a1548a 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -99,7 +99,9 @@ void testUnitySizeInitializationReminder(void) UNITY_COUNTER_TYPE TestIgnores; UNITY_COUNTER_TYPE CurrentTestFailed; UNITY_COUNTER_TYPE CurrentTestIgnored; +#ifndef UNITY_EXCLUDE_SETJMP_H jmp_buf AbortFrame; +#endif } _Expected_Unity; #else struct { @@ -113,7 +115,9 @@ void testUnitySizeInitializationReminder(void) UNITY_COUNTER_TYPE TestIgnores; UNITY_COUNTER_TYPE CurrentTestFailed; UNITY_COUNTER_TYPE CurrentTestIgnored; +#ifndef UNITY_EXCLUDE_SETJMP_H jmp_buf AbortFrame; +#endif } _Expected_Unity; #endif