diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 66e0b0636866c7e1632448f2155b385b68db2f54..aebecb1a86f23b44349550329c716ba5626c8c80 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -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 @@ -472,4 +471,4 @@ if $0 == __FILE__ ARGV[1] = ARGV[0].gsub('.c', '_Runner.c') unless ARGV[1] UnityTestRunnerGenerator.new(options).run(ARGV[0], ARGV[1]) -end \ No newline at end of file +end diff --git a/docs/UnityAssertionsReference.md b/docs/UnityAssertionsReference.md index 0f1aaa2c39358991ba5dbb972c250727a58f6194..efb03ffc068ef1d4a873659e60f2beb895860199 100644 --- a/docs/UnityAssertionsReference.md +++ b/docs/UnityAssertionsReference.md @@ -105,12 +105,12 @@ becomes messageified like thus... TEST_ASSERT_X_MESSAGE( {modifiers}, {expected}, actual, {size/count}, message ) Notes: -- The `_MESSAGE` variants intentionally do not support `printf` style formatting +- The `_MESSAGE` variants intentionally do not support `printf` style formatting since many embedded projects don't support or avoid `printf` for various reasons. It is possible to use `sprintf` before the assertion to assemble a complex fail message, if necessary. -- If you want to output a counter value within an assertion fail message (e.g. from - a loop) , building up an array of results and then using one of the `_ARRAY` +- If you want to output a counter value within an assertion fail message (e.g. from + a loop) , building up an array of results and then using one of the `_ARRAY` assertions (see below) might be a handy alternative to `sprintf`. @@ -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)` diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index 1275ca7693fad740c7fe6dbc9851993c27d45757..1aeb6c45b1cadb50ebe7fc03bea76692a4f6ae15 100644 --- a/docs/UnityConfigurationGuide.md +++ b/docs/UnityConfigurationGuide.md @@ -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 diff --git a/release/version.info b/release/version.info index cf12b30d2e236d2cd55e1e6656d789252747a533..b2031148232d4a6b0562fda4f83db5b3b3b08481 100644 --- a/release/version.info +++ b/release/version.info @@ -1,2 +1,2 @@ -2.4.3 +2.4.4 diff --git a/src/unity.c b/src/unity.c index 1fd508f8240d7756ee02d4a40eb21a12c66ff9f6..d7d3c640de42debcd8e11f6b433df1c80be6d474 100644 --- a/src/unity.c +++ b/src/unity.c @@ -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"; diff --git a/src/unity.h b/src/unity.h index 0f64653a67992cd7c1600b1581791f39673fed13..af2b549b80075156240f5eaadacd22a92beef286 100644 --- a/src/unity.h +++ b/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 } diff --git a/src/unity_internals.h b/src/unity_internals.h index 050fbdbf02fd20b9ace1fd8b71c9f3fa38631af8..c2c5fa6b569ae61a419843abb263ea8f6b09eb4a 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -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 *-----------------------------------------------*/