You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: docs/UnityConfigurationGuide.md
+62Lines changed: 62 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -399,6 +399,68 @@ _Example:_
399
399
#define UNITY_EXCLUDE_SETJMP
400
400
```
401
401
402
+
#### `UNITY_TEST_PROTECT`
403
+
404
+
#### `UNITY_TEST_ABORT`
405
+
406
+
Unity handles test failures via `setjmp`/`longjmp` pair by default. As mentioned above, you can disable this with `UNITY_EXCLUDE_SETJMP`. You can also customise what happens on every `TEST_PROTECT` and `TEST_ABORT` call. This can be accomplished by providing user-defined `UNITY_TEST_PROTECT` and `UNITY_TEST_ABORT` macros (and these may be defined independently).
407
+
408
+
`UNITY_TEST_PROTECT` is used as an `if` statement expression, and has to evaluate to `true` on the first call (when saving stack environment with `setjmp`), and to `false` when it returns as a result of a `TEST_ABORT` (when restoring the stack environment with `longjmp`).
409
+
410
+
Whenever an assert macro fails, `TEST_ABORT` is used to restore the stack environment previously set by `TEST_PROTECT`. This part may be overriden with `UNITY_TEST_ABORT`, e.g. if custom failure handling is needed.
411
+
412
+
_Example 1:_
413
+
414
+
Calling `longjmp` on your target is possible, but has a platform-specific (or implementation-specific) set of prerequisites, e.g. privileged access level. You can extend the default behaviour of `TEST_PROTECT` and `TEST_ABORT` as:
Unity is used to provide the assertion macros only, and an external test harness/runner is used for test orchestration/reporting. In this case you can easily plug your code by overriding `TEST_ABORT` as:
442
+
443
+
`unity_config.h`:
444
+
445
+
```C
446
+
#include "my_custom_test_handlers.h"
447
+
448
+
#define UNITY_TEST_PROTECT() 1
449
+
#define UNITY_TEST_ABORT() custom_test_abort()
450
+
```
451
+
452
+
`my_custom_test_handlers.c`:
453
+
454
+
```C
455
+
void custom_test_abort(void) {
456
+
if (Unity.CurrentTestFailed == 1) {
457
+
custom_failed_test_handler();
458
+
} else if (Unity.CurrentTestIgnored == 1) {
459
+
custom_ignored_test_handler();
460
+
}
461
+
}
462
+
```
463
+
402
464
#### `UNITY_OUTPUT_COLOR`
403
465
404
466
If you want to add color using ANSI escape codes you can use this define.
0 commit comments