mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-05-21 01:16:39 +08:00
- Added options for how to handle TEST_ASSERT_EQUAL shorthand
- Tweak a couple style problems with Ruby scripts.
This commit is contained in:
@ -103,8 +103,7 @@ class UnityTestRunnerGenerator
|
||||
source_scrubbed = source.clone
|
||||
source_scrubbed = source_scrubbed.gsub(/\\"/, '@quote@') # hide escaped quotes to allow capture of the full string/char
|
||||
source_scrubbed = source_scrubbed.gsub(/\\'/, '@apos@') # hide escaped apostrophes to allow capture of the full string/char
|
||||
source_scrubbed = source_scrubbed.gsub(/("[^"\n]*")|('[^'\n]*')/) { |s| s.gsub(substring_re, substring_subs) } # temporarily hide problematic
|
||||
# characters within strings
|
||||
source_scrubbed = source_scrubbed.gsub(/("[^"\n]*")|('[^'\n]*')/) { |s| s.gsub(substring_re, substring_subs) } # temporarily hide problematic characters within strings
|
||||
source_scrubbed = source_scrubbed.gsub(/\/\/.*$/, '') # remove line comments
|
||||
source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments
|
||||
lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
|
||||
|
@ -237,10 +237,6 @@ sizes.
|
||||
|
||||
##### `TEST_ASSERT_EQUAL_INT64 (expected, actual)`
|
||||
|
||||
##### `TEST_ASSERT_EQUAL (expected, actual)`
|
||||
|
||||
##### `TEST_ASSERT_NOT_EQUAL (expected, actual)`
|
||||
|
||||
##### `TEST_ASSERT_EQUAL_UINT (expected, actual)`
|
||||
|
||||
##### `TEST_ASSERT_EQUAL_UINT8 (expected, actual)`
|
||||
|
@ -420,12 +420,34 @@ _Example:_
|
||||
##### `UNITY_OUTPUT_COLOR`
|
||||
|
||||
If you want to add color using ANSI escape codes you can use this define.
|
||||
t
|
||||
|
||||
_Example:_
|
||||
```C
|
||||
#define UNITY_OUTPUT_COLOR
|
||||
```
|
||||
|
||||
##### `UNITY_SHORTHAND_AS_INT`
|
||||
##### `UNITY_SHORTHAND_AS_MEM`
|
||||
##### `UNITY_SHORTHAND_AS_RAW`
|
||||
##### `UNITY_SHORTHAND_AS_NONE`
|
||||
|
||||
These options give you control of the `TEST_ASSERT_EQUAL` and the
|
||||
`TEST_ASSERT_NOT_EQUAL` shorthand assertions. Historically, Unity treated the
|
||||
former as an alias for an integer comparison. It treated the latter as a direct
|
||||
comparison using `!=`. This assymetry was confusing, but there was much
|
||||
disagreement as to how best to treat this pair of assertions. These four options
|
||||
will allow you to specify how Unity will treat these assertions.
|
||||
|
||||
- AS INT - the values will be cast to integers and directly compared. Arguments
|
||||
that don't cast easily to integers will cause compiler errors.
|
||||
- AS MEM - the address of both values will be taken and the entire object's
|
||||
memory footprint will be compared byte by byte. Directly placing
|
||||
constant numbers like `456` as expected values will cause errors.
|
||||
- AS_RAW - Unity assumes that you can compare the two values using `==` and `!=`
|
||||
and will do so. No details are given about mismatches, because it
|
||||
doesn't really know what type it's dealing with.
|
||||
- AS_NONE - Unity will disallow the use of these shorthand macros altogether,
|
||||
insisting that developers choose a more descriptive option.
|
||||
|
||||
## Getting Into The Guts
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
2.4.3
|
||||
2.4.4
|
||||
|
||||
|
@ -53,6 +53,7 @@ static const char UnityStrNaN[] = "NaN";
|
||||
static const char UnityStrDet[] = "Determinate";
|
||||
static const char UnityStrInvalidFloatTrait[] = "Invalid Float Trait";
|
||||
#endif
|
||||
const char UnityStrErrShorthand[] = "Unity Shorthand Support Disabled";
|
||||
const char UnityStrErrFloat[] = "Unity Floating Point Disabled";
|
||||
const char UnityStrErrDouble[] = "Unity Double Precision Disabled";
|
||||
const char UnityStrErr64[] = "Unity 64-bit Support Disabled";
|
||||
|
50
src/unity.h
50
src/unity.h
@ -130,8 +130,6 @@ int suiteTearDown(int num_failures);
|
||||
#define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal")
|
||||
#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL)
|
||||
@ -322,6 +320,29 @@ int suiteTearDown(int num_failures);
|
||||
#define TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN((actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE((actual), __LINE__, NULL)
|
||||
|
||||
/* Shorthand */
|
||||
#ifdef UNITY_SHORTHAND_AS_OLD
|
||||
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal")
|
||||
#endif
|
||||
#ifdef UNITY_SHORTHAND_AS_INT
|
||||
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand)
|
||||
#endif
|
||||
#ifdef UNITY_SHORTHAND_AS_MEM
|
||||
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_MEMORY((&expected), (&actual), sizeof(expected), __LINE__, NULL)
|
||||
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand)
|
||||
#endif
|
||||
#ifdef UNITY_SHORTHAND_AS_RAW
|
||||
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) == (actual)), __LINE__, " Expected Equal")
|
||||
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal")
|
||||
#endif
|
||||
#ifdef UNITY_SHORTHAND_AS_NONE
|
||||
const char UnityStrErrShorthand[];
|
||||
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand)
|
||||
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand)
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------
|
||||
* Test Asserts (with additional messages)
|
||||
*-------------------------------------------------------*/
|
||||
@ -340,8 +361,6 @@ int suiteTearDown(int num_failures);
|
||||
#define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, (message))
|
||||
#define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, (message))
|
||||
#define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, (message))
|
||||
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, (message))
|
||||
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, (message))
|
||||
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, (message))
|
||||
#define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, (message))
|
||||
#define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, (message))
|
||||
@ -532,6 +551,29 @@ int suiteTearDown(int num_failures);
|
||||
#define TEST_ASSERT_DOUBLE_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN((actual), __LINE__, (message))
|
||||
#define TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE((actual), __LINE__, (message))
|
||||
|
||||
/* Shorthand */
|
||||
#ifdef UNITY_SHORTHAND_AS_OLD
|
||||
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, (message))
|
||||
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, (message))
|
||||
#endif
|
||||
#ifdef UNITY_SHORTHAND_AS_INT
|
||||
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand)
|
||||
#endif
|
||||
#ifdef UNITY_SHORTHAND_AS_MEM
|
||||
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_MEMORY((&expected), (&actual), sizeof(expected), __LINE__, message)
|
||||
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand)
|
||||
#endif
|
||||
#ifdef UNITY_SHORTHAND_AS_RAW
|
||||
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) == (actual)), __LINE__, message)
|
||||
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message)
|
||||
#endif
|
||||
#ifdef UNITY_SHORTHAND_AS_NONE
|
||||
const char UnityStrErrShorthand[];
|
||||
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand)
|
||||
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand)
|
||||
#endif
|
||||
|
||||
/* end of UNITY_FRAMEWORK_H */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -729,6 +729,16 @@ extern const char UnityStrErr64[];
|
||||
#define UNITY_END() UnityEnd()
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_SHORTHAND_AS_INT
|
||||
#ifndef UNITY_SHORTHAND_AS_MEM
|
||||
#ifndef UNITY_SHORTHAND_AS_NONE
|
||||
#ifndef UNITY_SHORTHAND_AS_RAW
|
||||
#define UNITY_SHORTHAND_AS_OLD
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------
|
||||
* Command Line Argument Support
|
||||
*-----------------------------------------------*/
|
||||
|
Reference in New Issue
Block a user