mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-09-22 02:19:21 +08:00
Adding possibility for automatically defining
TEST_CASE & TEST_RANGE macros
This commit is contained in:
@ -438,6 +438,30 @@ This will rarely be necessary. Most often, Unity will automatically detect if th
|
||||
In the event that the compiler supports variadic macros, but is primarily C89 (ANSI), defining this option will allow you to use them.
|
||||
This option is also not necessary when using Ceedling or the test runner generator script.
|
||||
|
||||
#### `UNITY_INCLUDE_PARAM_TESTING_MACRO`
|
||||
|
||||
Unity can automatically define all supported parameterized tests macros.
|
||||
To enable that feature, use the following example:
|
||||
|
||||
```C
|
||||
#define UNITY_INCLUDE_PARAM_TESTING_MACRO
|
||||
```
|
||||
|
||||
You can manually provide required `TEST_CASE` or `TEST_RANGE` macro definitions
|
||||
before including `unity.h`, and they won't be redefined.
|
||||
If you provide one of the following macros, some of default definitions will not be
|
||||
defined:
|
||||
| User defines macro | Unity will __not__ define following macro |
|
||||
|---|---|
|
||||
| `UNITY_NOT_DEFINE_TEST_CASE` | `TEST_CASE` |
|
||||
| `UNITY_NOT_DEFINE_TEST_RANGE` | `TEST_RANGE` |
|
||||
| `TEST_CASE` | `TEST_CASE` |
|
||||
| `TEST_RANGE` | `TEST_RANGE` |
|
||||
|
||||
_Note:_
|
||||
That feature requires variadic macro support by compiler. If required feature
|
||||
is not detected, it will not be enabled, even though preprocessor macro is defined.
|
||||
|
||||
## Getting Into The Guts
|
||||
|
||||
There will be cases where the options above aren't quite going to get everything perfect.
|
||||
|
@ -765,19 +765,35 @@ extern const char UnityStrErrShorthand[];
|
||||
#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
|
||||
/* Automatically enable variadic macros support, if it not enabled before */
|
||||
#ifndef UNITY_SUPPORT_VARIADIC_MACROS
|
||||
#ifdef __STDC_VERSION__
|
||||
#if __STDC_VERSION__ >= 199901L
|
||||
#define UNITY_SUPPORT_VARIADIC_MACROS
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This tricky series of macros gives us an optional line argument to treat it as RUN_TEST(func, num=__LINE__) */
|
||||
#ifndef RUN_TEST
|
||||
#ifdef UNITY_SUPPORT_VARIADIC_MACROS
|
||||
#define RUN_TEST(...) RUN_TEST_AT_LINE(__VA_ARGS__, __LINE__, throwaway)
|
||||
#define RUN_TEST_AT_LINE(func, line, ...) UnityDefaultTestRun(func, #func, line)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Enable default macros for masking param tests test cases */
|
||||
#ifdef UNITY_INCLUDE_PARAM_TESTING_MACRO
|
||||
#ifdef UNITY_SUPPORT_VARIADIC_MACROS
|
||||
#if !defined(TEST_CASE) && !defined(UNITY_NOT_DEFINE_TEST_CASE)
|
||||
#define TEST_CASE(...)
|
||||
#endif
|
||||
#if !defined(TEST_RANGE) && !defined(UNITY_NOT_DEFINE_TEST_RANGE)
|
||||
#define TEST_RANGE(...)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* If we can't do the tricky version, we'll just have to require them to always include the line number */
|
||||
#ifndef RUN_TEST
|
||||
#ifdef CMOCK
|
||||
|
@ -4,14 +4,12 @@
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#define UNITY_INCLUDE_PARAM_TESTING_MACRO
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdio.h>
|
||||
#include "unity.h"
|
||||
|
||||
/* Support for Meta Test Rig */
|
||||
#define TEST_CASE(...)
|
||||
#define TEST_RANGE(...)
|
||||
|
||||
/* Include Passthroughs for Linking Tests */
|
||||
void putcharSpy(int c) { (void)putchar(c);}
|
||||
void flushSpy(void) {}
|
||||
|
Reference in New Issue
Block a user