From cc909efed33165be83732e2f6a502459663914c1 Mon Sep 17 00:00:00 2001 From: balaksh Date: Mon, 10 Apr 2017 15:08:01 +1200 Subject: [PATCH 01/44] Implement optional printing of execution time for each test --- examples/unity_config.h | 8 +++++ extras/fixture/src/unity_fixture.c | 4 +++ src/unity.c | 4 ++- src/unity_internals.h | 52 ++++++++++++++++++++++++++++++ test/tests/testunity.c | 8 +++++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/examples/unity_config.h b/examples/unity_config.h index da3c2af..d586448 100644 --- a/examples/unity_config.h +++ b/examples/unity_config.h @@ -236,4 +236,12 @@ /* #define UNITY_PTR_ATTRIBUTE __attribute__((far)) */ /* #define UNITY_PTR_ATTRIBUTE near */ +/* Print execution time of each test when executed in verbose mode + * + * Example: + * + * TEST - PASS (10 ms) + */ +/* #define UNITY_INCLUDE_EXEC_TIME */ + #endif /* UNITY_CONFIG_H */ diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 3872bd8..36c1fb1 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -93,6 +93,8 @@ void UnityTestRunner(unityfunction* setup, UnityMalloc_StartTest(); UnityPointer_Init(); + UNITY_EXEC_TIME_START(); + if (TEST_PROTECT()) { setup(); @@ -418,6 +420,8 @@ void UnityConcludeFixtureTest(void) if (UnityFixture.Verbose) { UnityPrint(" PASS"); + UNITY_EXEC_TIME_STOP(); + UNITY_PRINT_EXEC_TIME(); UNITY_PRINT_EOL(); } } diff --git a/src/unity.c b/src/unity.c index a493b76..cae7bbd 100644 --- a/src/unity.c +++ b/src/unity.c @@ -370,6 +370,7 @@ void UnityConcludeTest(void) Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; + UNITY_EXEC_TIME_RESET(); UNITY_PRINT_EOL(); UNITY_FLUSH_CALL(); } @@ -958,7 +959,7 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta, if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { if (actual > expected) - Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); + Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); else Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta); } @@ -1351,6 +1352,7 @@ void UnityBegin(const char* filename) Unity.TestIgnores = 0; Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; + UNITY_EXEC_TIME_RESET(); UNITY_CLR_DETAILS(); UNITY_OUTPUT_START(); diff --git a/src/unity_internals.h b/src/unity_internals.h index 1b57cd0..e161627 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -32,6 +32,10 @@ #include #endif +#ifndef UNITY_EXCLUDE_TIME_H +#include +#endif + /*------------------------------------------------------- * Guess Widths If Not Specified *-------------------------------------------------------*/ @@ -285,6 +289,44 @@ extern void UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION; #define UNITY_OUTPUT_COMPLETE() #endif +#ifndef UNITY_EXEC_TIME_RESET +#ifdef UNITY_INCLUDE_EXEC_TIME +#define UNITY_EXEC_TIME_RESET()\ + Unity.CurrentTestStartTime = 0;\ + Unity.CurrentTestStopTime = 0; +#else +#define UNITY_EXEC_TIME_RESET() +#endif +#endif + +#ifndef UNITY_EXEC_TIME_START +#ifdef UNITY_INCLUDE_EXEC_TIME +#define UNITY_EXEC_TIME_START() Unity.CurrentTestStartTime = UNITY_CLOCK_MS(); +#else +#define UNITY_EXEC_TIME_START() +#endif +#endif + +#ifndef UNITY_EXEC_TIME_START +#ifdef UNITY_INCLUDE_EXEC_TIME +#define UNITY_EXEC_TIME_STOP() Unity.CurrentTestStopTime = UNITY_CLOCK_MS(); +#else +#define UNITY_EXEC_TIME_STOP() +#endif +#endif + +#ifndef UNITY_PRINT_EXEC_TIME +#ifdef UNITY_INCLUDE_EXEC_TIME +#define UNITY_PRINT_EXEC_TIME() \ + UnityPrint(" (");\ + UNITY_COUNTER_TYPE execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); + UnityPrintNumberUnsigned(execTimeMs);\ + UnityPrint(" ms)"); +#else +#define UNITY_PRINT_EXEC_TIME() +#endif +#endif + /*------------------------------------------------------- * Footprint *-------------------------------------------------------*/ @@ -387,6 +429,10 @@ struct UNITY_STORAGE_T UNITY_COUNTER_TYPE TestIgnores; UNITY_COUNTER_TYPE CurrentTestFailed; UNITY_COUNTER_TYPE CurrentTestIgnored; +#ifdef UNITY_INCLUDE_EXEC_TIME + UNITY_COUNTER_TYPE CurrentTestStartTime; + UNITY_COUNTER_TYPE CurrentTestStopTime; +#endif #ifndef UNITY_EXCLUDE_SETJMP_H jmp_buf AbortFrame; #endif @@ -590,6 +636,12 @@ extern const char UnityStrErr64[]; #define TEST_ABORT() return #endif +#ifndef UNITY_EXCLUDE_TIME_H +#define UNITY_CLOCK_MS() (UNITY_COUNTER_TYPE)((clock() * 1000) / CLOCKS_PER_SEC) +#else +#define UNITY_CLOCK_MS() +#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 __STDC_VERSION__ diff --git a/test/tests/testunity.c b/test/tests/testunity.c index af06647..88fb284 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -99,6 +99,10 @@ void testUnitySizeInitializationReminder(void) UNITY_COUNTER_TYPE TestIgnores; UNITY_COUNTER_TYPE CurrentTestFailed; UNITY_COUNTER_TYPE CurrentTestIgnored; +#ifdef UNITY_INCLUDE_EXEC_TIME + UNITY_COUNTER_TYPE CurrentTestStartTime; + UNITY_COUNTER_TYPE CurrentTestStopTime; +#endif #ifndef UNITY_EXCLUDE_SETJMP_H jmp_buf AbortFrame; #endif @@ -115,6 +119,10 @@ void testUnitySizeInitializationReminder(void) UNITY_COUNTER_TYPE TestIgnores; UNITY_COUNTER_TYPE CurrentTestFailed; UNITY_COUNTER_TYPE CurrentTestIgnored; +#ifdef UNITY_INCLUDE_EXEC_TIME + UNITY_COUNTER_TYPE CurrentTestStartTime; + UNITY_COUNTER_TYPE CurrentTestStopTime; +#endif #ifndef UNITY_EXCLUDE_SETJMP_H jmp_buf AbortFrame; #endif From 287e076962ec711cd2bdf08364a8df9ce51e106b Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Tue, 14 Nov 2017 16:26:16 -0500 Subject: [PATCH 02/44] Post release --- release/build.info | 2 +- release/version.info | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/release/build.info b/release/build.info index 50fb6ea..56d5912 100644 --- a/release/build.info +++ b/release/build.info @@ -1,2 +1,2 @@ -121 +122 diff --git a/release/version.info b/release/version.info index b674b92..cf12b30 100644 --- a/release/version.info +++ b/release/version.info @@ -1,2 +1,2 @@ -2.4.2 +2.4.3 From 53f0f95ef8af7f903ef0080d0492df33e517ed9c Mon Sep 17 00:00:00 2001 From: Krzysztof Kwiatkowski Date: Mon, 20 Nov 2017 09:46:30 +0000 Subject: [PATCH 03/44] Test runner generation: Wrap setjmp.h inclusion in ifdefs Auto generated test runner should generate a code which includes setjmp.h only if UNITY_EXCLUDE_SETJMP_H is not defined --- auto/generate_test_runner.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 344a2d0..427c513 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -162,7 +162,9 @@ class UnityTestRunnerGenerator output.puts('#endif') output.puts("#include \"#{@options[:framework]}.h\"") output.puts('#include "cmock.h"') unless mocks.empty? + output.puts('#ifndef UNITY_EXCLUDE_SETJMP_H') output.puts('#include ') + output.puts("#endif") output.puts('#include ') if @options[:defines] && !@options[:defines].empty? @options[:defines].each { |d| output.puts("#define #{d}") } From 4325773e7627eb6b6ba4779de264e42512fce538 Mon Sep 17 00:00:00 2001 From: Shreyas Balakrishna Date: Thu, 23 Nov 2017 14:58:45 +1300 Subject: [PATCH 04/44] Fix unsigned integer underflow in UnityAssertEqualIntArray --- src/unity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 177af0f..209efe7 100644 --- a/src/unity.c +++ b/src/unity.c @@ -556,7 +556,7 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) UNITY_FAIL_AND_BAIL; - while (elements--) + while ((elements > 0) && elements--) { UNITY_INT expect_val; UNITY_INT actual_val; From b4aca70fd9e0ddf0afbdafb1b826f5edcfc1049b Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Wed, 6 Dec 2017 10:08:56 -0500 Subject: [PATCH 05/44] Update UnityGettingStartedGuide.md Added more detail on test naming. --- docs/UnityGettingStartedGuide.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/UnityGettingStartedGuide.md b/docs/UnityGettingStartedGuide.md index 50fc91c..81d0398 100644 --- a/docs/UnityGettingStartedGuide.md +++ b/docs/UnityGettingStartedGuide.md @@ -100,10 +100,11 @@ find setUp or tearDown when it links, you'll know you need to at least include an empty function for these. The majority of the file will be a series of test functions. Test functions -follow the convention of starting with the word "test" or "spec". You don't HAVE +follow the convention of starting with the word "test_" or "spec_". You don't HAVE to name them this way, but it makes it clear what functions are tests for other -developers. Test functions take no arguments and return nothing. All test -accounting is handled internally in Unity. +developers. Also, the automated scripts that come with Unity or Ceedling will default +to looking for test functions to be prefixed this way. Test functions take no arguments +and return nothing. All test accounting is handled internally in Unity. Finally, at the bottom of your test file, you will write a `main()` function. This function will call `UNITY_BEGIN()`, then `RUN_TEST` for each test, and From 07602308294c5f30b4d732cd87bd98d0c5e6a693 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Mon, 29 Jan 2018 21:00:46 +0100 Subject: [PATCH 06/44] Some minor changes - String split now works correctly for windows and unix (cross platform) - Removed unnecessary whitespaces in the xml output (beautifies the output) - Added support for TEST_IGNORE() (without message) --- auto/parse_output.rb | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index f16cdb0..f3e076f 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -47,7 +47,12 @@ class ParseOutput @test_flag = true # Split the path name - test_name = test_suite_name.split('/') + test_name = if @class_name == 1 + test_suite_name.split('\\') # Windows + else + test_suite_name.split('/') # Unix based + end + # Remove the extension base_name = test_name[test_name.size - 1].split('.') @test_suite = 'test.' + base_name[0] @@ -78,11 +83,11 @@ class ParseOutput @array_list.push ' ' end - # Test was flagged as being ingored so format the output + # Test was flagged as being ignored so format the output def test_ignored(array) last_item = array.length - 1 test_name = array[last_item - 2] - reason = array[last_item].chomp + reason = array[last_item].chomp.lstrip test_suite_verify(array[@class_name]) printf "%-40s IGNORED\n", test_name @@ -96,7 +101,7 @@ class ParseOutput return unless @xml_out @array_list.push ' ' - @array_list.push ' ' + reason + ' ' + @array_list.push ' ' + reason + '' @array_list.push ' ' end @@ -104,7 +109,7 @@ class ParseOutput def test_failed(array) last_item = array.length - 1 test_name = array[last_item - 2] - reason = array[last_item].chomp + ' at line: ' + array[last_item - 3] + reason = array[last_item].chomp.lstrip + ' at line: ' + array[last_item - 3] test_suite_verify(array[@class_name]) printf "%-40s FAILED\n", test_name @@ -118,11 +123,11 @@ class ParseOutput return unless @xml_out @array_list.push ' ' - @array_list.push ' ' + reason + ' ' + @array_list.push ' ' + reason + '' @array_list.push ' ' end - # Figure out what OS we are running on. For now we are assuming if it's not Windows it must + # Figure out what OS we are running on. For now we are assuming if it's not Windows it must # be Unix based. def detect_os os = RUBY_PLATFORM.split('-') @@ -168,12 +173,16 @@ class ParseOutput if line.include? ':PASS' test_passed(line_array) test_pass += 1 - elsif line.include? ':FAIL:' + elsif line.include? ':FAIL' test_failed(line_array) test_fail += 1 elsif line.include? ':IGNORE:' test_ignored(line_array) test_ignore += 1 + elsif line.include? ':IGNORE' + line_array.push('No reason given') + test_ignored(line_array) + test_ignore += 1 elsif line.start_with? 'TEST(' if line.include? ' PASS' line_array = line.split(' ') @@ -199,7 +208,7 @@ class ParseOutput return unless @xml_out - heading = '' + heading = '' @array_list.insert(0, heading) write_xml_output end From 91a23535266b4c8a0cdc38e116bc9572d6912093 Mon Sep 17 00:00:00 2001 From: Jeremy Hannon Date: Sat, 10 Feb 2018 13:15:34 -0600 Subject: [PATCH 07/44] MISRA 16.4: param names match func decl & defn parameter names should match between declaration and definition. (MISRA 2004 rule 16.4) --- extras/fixture/src/unity_fixture.h | 2 +- extras/fixture/src/unity_fixture_internals.h | 4 ++-- src/unity_internals.h | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/extras/fixture/src/unity_fixture.h b/extras/fixture/src/unity_fixture.h index 6f8d623..2dcf473 100644 --- a/extras/fixture/src/unity_fixture.h +++ b/extras/fixture/src/unity_fixture.h @@ -78,6 +78,6 @@ int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)); #endif /* You must compile with malloc replacement, as defined in unity_fixture_malloc_overrides.h */ -void UnityMalloc_MakeMallocFailAfterCount(int count); +void UnityMalloc_MakeMallocFailAfterCount(int countdown); #endif /* UNITY_FIXTURE_H_ */ diff --git a/extras/fixture/src/unity_fixture_internals.h b/extras/fixture/src/unity_fixture_internals.h index aa0d9e7..00cee88 100644 --- a/extras/fixture/src/unity_fixture_internals.h +++ b/extras/fixture/src/unity_fixture_internals.h @@ -24,7 +24,7 @@ extern struct UNITY_FIXTURE_T UnityFixture; typedef void unityfunction(void); void UnityTestRunner(unityfunction* setup, - unityfunction* body, + unityfunction* testBody, unityfunction* teardown, const char* printableName, const char* group, @@ -37,7 +37,7 @@ void UnityMalloc_EndTest(void); int UnityGetCommandLineOptions(int argc, const char* argv[]); void UnityConcludeFixtureTest(void); -void UnityPointer_Set(void** ptr, void* newValue, UNITY_LINE_TYPE line); +void UnityPointer_Set(void** pointer, void* newValue, UNITY_LINE_TYPE line); void UnityPointer_UndoAllSets(void); void UnityPointer_Init(void); #ifndef UNITY_MAX_POINTERS diff --git a/src/unity_internals.h b/src/unity_internals.h index 67e219b..97f86ef 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -442,9 +442,9 @@ void UnityPrint(const char* string); void UnityPrintLen(const char* string, const UNITY_UINT32 length); void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number); void UnityPrintNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style); -void UnityPrintNumber(const UNITY_INT number); +void UnityPrintNumber(const UNITY_INT number_to_print); void UnityPrintNumberUnsigned(const UNITY_UINT number); -void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles); +void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print); #ifndef UNITY_EXCLUDE_FLOAT_PRINT void UnityPrintFloat(const UNITY_DOUBLE input_number); @@ -518,9 +518,9 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); -void UnityFail(const char* message, const UNITY_LINE_TYPE line); +void UnityFail(const char* msg, const UNITY_LINE_TYPE line); -void UnityIgnore(const char* message, const UNITY_LINE_TYPE line); +void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line); #ifndef UNITY_EXCLUDE_FLOAT void UnityAssertFloatsWithin(const UNITY_FLOAT delta, From 9bada282f471a5565f351bad346677f34ec36ec6 Mon Sep 17 00:00:00 2001 From: Jeremy Hannon Date: Sat, 10 Feb 2018 14:27:03 -0600 Subject: [PATCH 08/44] MISRA 19.10: parentheses around macro params MISRA 2004 rule 19.10: inside macros, surround each parameter usage with parentheses. --- src/unity.c | 14 +++++++------- src/unity_internals.h | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/unity.c b/src/unity.c index 03dcc02..136e9d7 100644 --- a/src/unity.c +++ b/src/unity.c @@ -677,13 +677,13 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, /*-----------------------------------------------*/ #ifndef UNITY_EXCLUDE_FLOAT /* Wrap this define in a function with variable types as float or double */ -#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \ - if (isinf(expected) && isinf(actual) && ((expected < 0) == (actual < 0))) return 1; \ - if (UNITY_NAN_CHECK) return 1; \ - diff = actual - expected; \ - if (diff < 0) diff = -diff; \ - if (delta < 0) delta = -delta; \ - return !(isnan(diff) || isinf(diff) || (diff > delta)) +#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \ + if (isinf(expected) && isinf(actual) && (((expected) < 0) == ((actual) < 0))) return 1; \ + if (UNITY_NAN_CHECK) return 1; \ + (diff) = (actual) - (expected); \ + if ((diff) < 0) (diff) = -(diff); \ + if ((delta) < 0) (delta) = -(delta); \ + return !(isnan(diff) || isinf(diff) || ((diff) > (delta))) /* This first part of this condition will catch any NaN or Infinite values */ #ifndef UNITY_NAN_NOT_EQUAL_NAN #define UNITY_NAN_CHECK isnan(expected) && isnan(actual) diff --git a/src/unity_internals.h b/src/unity_internals.h index 97f86ef..3ba6fae 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -422,8 +422,8 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int #define UNITY_SET_DETAILS(d1,d2) #else #define UNITY_CLR_DETAILS() { Unity.CurrentDetail1 = 0; Unity.CurrentDetail2 = 0; } -#define UNITY_SET_DETAIL(d1) { Unity.CurrentDetail1 = d1; Unity.CurrentDetail2 = 0; } -#define UNITY_SET_DETAILS(d1,d2) { Unity.CurrentDetail1 = d1; Unity.CurrentDetail2 = d2; } +#define UNITY_SET_DETAIL(d1) { Unity.CurrentDetail1 = (d1); Unity.CurrentDetail2 = 0; } +#define UNITY_SET_DETAILS(d1,d2) { Unity.CurrentDetail1 = (d1); Unity.CurrentDetail2 = (d2); } #ifndef UNITY_DETAIL1_NAME #define UNITY_DETAIL1_NAME "Function" @@ -748,18 +748,18 @@ int UnityTestMatches(void); #define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((UNITY_INTERNAL_PTR)(expected), (const char**)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(len), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EACH_EQUAL_INT(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT) expected, sizeof(int)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_INT8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT8 )expected, 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_INT16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT16 )expected, 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_INT32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT32 )expected, 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT) expected, sizeof(unsigned int)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT8 )expected, 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT16)expected, 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT32)expected, 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT8 )expected, 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT16 )expected, 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT32 )expected, 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_PTR(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_PTR_TO_INT) expected, sizeof(int*)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_POINTER, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_INT(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT) (expected), sizeof(int)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_INT8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_INT16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT16 )(expected), 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_INT32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT32 )(expected), 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT) (expected), sizeof(unsigned int)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT16)(expected), 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT32)(expected), 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT16 )(expected), 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT32 )(expected), 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_PTR(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_PTR_TO_INT) (expected), sizeof(int*)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_POINTER, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_STRING(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((UNITY_INTERNAL_PTR)(expected), (const char**)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_EACH_EQUAL_MEMORY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(len), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) From dc9c7a7b4b316cb4e0605283f1ce981d7d6dfac9 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 11 Feb 2018 13:02:26 +0100 Subject: [PATCH 09/44] Removed leading whitespace --- auto/parse_output.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index f3e076f..0f9de4d 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -123,7 +123,7 @@ class ParseOutput return unless @xml_out @array_list.push ' ' - @array_list.push ' ' + reason + '' + @array_list.push ' ' + reason + '' @array_list.push ' ' end From 4dfb512a275370a1ad2f9328d25946d9a650d4c6 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Mon, 12 Feb 2018 06:44:26 +0100 Subject: [PATCH 10/44] Added ".to_s" to the test suite name (explicit type conversion) --- auto/parse_output.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index 0f9de4d..b5132a0 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -208,7 +208,7 @@ class ParseOutput return unless @xml_out - heading = '' + heading = '' @array_list.insert(0, heading) write_xml_output end From 8efa8ffc621e0986d82a77a63362a96af7d5ca59 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 13:57:34 +0100 Subject: [PATCH 11/44] Removed UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION to simplify the behaviour --- docs/UnityConfigurationGuide.md | 8 +++----- src/unity_internals.h | 32 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index 96e5358..1b69828 100644 --- a/docs/UnityConfigurationGuide.md +++ b/docs/UnityConfigurationGuide.md @@ -248,7 +248,8 @@ _Example:_ Say you are forced to run your test suite on an embedded processor with no `stdout` option. You decide to route your test result output to a custom serial `RS232_putc()` function you wrote like thus: - + #include "RS232_header.h" + ... #define UNITY_OUTPUT_CHAR(a) RS232_putc(a) #define UNITY_OUTPUT_START() RS232_config(115200,1,8,0) #define UNITY_OUTPUT_FLUSH() RS232_flush() @@ -256,10 +257,7 @@ Say you are forced to run your test suite on an embedded processor with no _Note:_ `UNITY_OUTPUT_FLUSH()` can be set to the standard out flush function simply by -specifying `UNITY_USE_FLUSH_STDOUT`. No other defines are required. If you -specify a custom flush function instead with `UNITY_OUTPUT_FLUSH` directly, it -will declare an instance of your function by default. If you want to disable -this behavior, add `UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION`. +specifying `UNITY_USE_FLUSH_STDOUT`. No other defines are required. ##### `UNITY_WEAK_ATTRIBUTE` diff --git a/src/unity_internals.h b/src/unity_internals.h index 3ba6fae..415a29b 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -241,30 +241,30 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT; * Output Method: stdout (DEFAULT) *-------------------------------------------------------*/ #ifndef UNITY_OUTPUT_CHAR -/* Default to using putchar, which is defined in stdio.h */ -#include -#define UNITY_OUTPUT_CHAR(a) (void)putchar(a) + /* Default to using putchar, which is defined in stdio.h */ + #include + #define UNITY_OUTPUT_CHAR(a) (void)putchar(a) #else /* If defined as something else, make sure we declare it here so it's ready for use */ #ifdef UNITY_OUTPUT_CHAR_HEADER_DECLARATION -extern void UNITY_OUTPUT_CHAR_HEADER_DECLARATION; + extern void UNITY_OUTPUT_CHAR_HEADER_DECLARATION; #endif #endif #ifndef UNITY_OUTPUT_FLUSH -#ifdef UNITY_USE_FLUSH_STDOUT -/* We want to use the stdout flush utility */ -#include -#define UNITY_OUTPUT_FLUSH() (void)fflush(stdout) + #ifdef UNITY_USE_FLUSH_STDOUT + /* We want to use the stdout flush utility */ + #include + #define UNITY_OUTPUT_FLUSH() (void)fflush(stdout) + #else + /* We've specified nothing, therefore flush should just be ignored */ + #define UNITY_OUTPUT_FLUSH() + #endif #else -/* We've specified nothing, therefore flush should just be ignored */ -#define UNITY_OUTPUT_FLUSH() -#endif -#else -/* We've defined flush as something else, so make sure we declare it here so it's ready for use */ -#ifdef UNITY_OUTPUT_FLUSH_HEADER_DECLARATION -extern void UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION; -#endif + /* If defined as something else, make sure we declare it here so it's ready for use */ + #ifdef UNITY_OUTPUT_FLUSH_HEADER_DECLARATION + extern void UNITY_OUTPUT_FLUSH_HEADER_DECLARATION; + #endif #endif #ifndef UNITY_OUTPUT_FLUSH From fe950b9fa3466077b96fa93031f8f8fe1e2875bd Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 14:11:19 +0100 Subject: [PATCH 12/44] Makefile preparations --- test/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Makefile b/test/Makefile index c2710f1..f37b9ea 100644 --- a/test/Makefile +++ b/test/Makefile @@ -15,6 +15,8 @@ CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstri CFLAGS += $(DEBUG) DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\) +#DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy +#DEFINES += -D UNITY_OUTPUT_FLUSH_HEADER_DECLARATION=flushSpy\(void\) DEFINES += $(UNITY_SUPPORT_64) $(UNITY_INCLUDE_DOUBLE) UNITY_SUPPORT_64 = -D UNITY_SUPPORT_64 UNITY_INCLUDE_DOUBLE = -D UNITY_INCLUDE_DOUBLE From 456759296b407189c0b48b02dd3c479b4ddff4f3 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 14:23:26 +0100 Subject: [PATCH 13/44] Added flushSpy --- test/Makefile | 4 ++-- test/testdata/testRunnerGenerator.c | 5 ++++- test/testdata/testRunnerGeneratorSmall.c | 5 ++++- test/testdata/testRunnerGeneratorWithMocks.c | 5 ++++- test/tests/testparameterized.c | 7 +++++-- test/tests/testunity.c | 8 ++++++++ 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/test/Makefile b/test/Makefile index f37b9ea..89ece81 100644 --- a/test/Makefile +++ b/test/Makefile @@ -15,8 +15,8 @@ CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstri CFLAGS += $(DEBUG) DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\) -#DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy -#DEFINES += -D UNITY_OUTPUT_FLUSH_HEADER_DECLARATION=flushSpy\(void\) +DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy +DEFINES += -D UNITY_OUTPUT_FLUSH_HEADER_DECLARATION=flushSpy\(void\) DEFINES += $(UNITY_SUPPORT_64) $(UNITY_INCLUDE_DOUBLE) UNITY_SUPPORT_64 = -D UNITY_SUPPORT_64 UNITY_INCLUDE_DOUBLE = -D UNITY_INCLUDE_DOUBLE diff --git a/test/testdata/testRunnerGenerator.c b/test/testdata/testRunnerGenerator.c index e036dd9..7a4d63b 100644 --- a/test/testdata/testRunnerGenerator.c +++ b/test/testdata/testRunnerGenerator.c @@ -21,7 +21,10 @@ /* Support for Meta Test Rig */ #define TEST_CASE(a) -void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests + +/* Include Passthroughs for Linking Tests */ +void putcharSpy(int c) { (void)putchar(c);} +void flushSpy(int c) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/testdata/testRunnerGeneratorSmall.c b/test/testdata/testRunnerGeneratorSmall.c index c683749..a8707fb 100644 --- a/test/testdata/testRunnerGeneratorSmall.c +++ b/test/testdata/testRunnerGeneratorSmall.c @@ -13,7 +13,10 @@ TEST_FILE("some_file.c") /* Support for Meta Test Rig */ #define TEST_CASE(a) -void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests + +/* Include Passthroughs for Linking Tests */ +void putcharSpy(int c) { (void)putchar(c);} +void flushSpy(int c) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/testdata/testRunnerGeneratorWithMocks.c b/test/testdata/testRunnerGeneratorWithMocks.c index 7eb0b67..a7d622d 100644 --- a/test/testdata/testRunnerGeneratorWithMocks.c +++ b/test/testdata/testRunnerGeneratorWithMocks.c @@ -22,7 +22,10 @@ /* Support for Meta Test Rig */ #define TEST_CASE(a) -void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests + +/* Include Passthroughs for Linking Tests */ +void putcharSpy(int c) { (void)putchar(c);} +void flushSpy(int c) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/tests/testparameterized.c b/test/tests/testparameterized.c index aa6d173..7be7f2b 100644 --- a/test/tests/testparameterized.c +++ b/test/tests/testparameterized.c @@ -8,10 +8,13 @@ #include #include "unity.h" -void putcharSpy(int c) { (void)putchar(c);} // include passthrough for linking tests - +/* Support for Meta Test Rig */ #define TEST_CASE(...) +/* Include Passthroughs for Linking Tests */ +void putcharSpy(int c) { (void)putchar(c);} +void flushSpy(int c) {} + #define EXPECT_ABORT_BEGIN \ if (TEST_PROTECT()) \ { diff --git a/test/tests/testunity.c b/test/tests/testunity.c index af06647..1884cbb 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -3335,6 +3335,14 @@ void putcharSpy(int c) #endif } +#if 0 +void flushSpy(void) +{ + static unsigned int calls = 0; + calls++; // count every call +} +#endif + void testFailureCountIncrementsAndIsReturnedAtEnd(void) { UNITY_UINT savedFailures = Unity.TestFailures; From 25804f3ab4bec897019333022bbb44472f5b6534 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 14:46:42 +0100 Subject: [PATCH 14/44] Added flushSpy and the respective helper functions --- test/tests/testunity.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 1884cbb..3496990 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -54,6 +54,10 @@ void startPutcharSpy(void); void endPutcharSpy(void); char* getBufferPutcharSpy(void); +void startFlushSpy(void); +void endFlushSpy(void); +unsigned int getFlushSpyCalls(void); + static int SetToOneToFailInTearDown; static int SetToOneMeanWeAlreadyCheckedThisGuy; @@ -3335,13 +3339,18 @@ void putcharSpy(int c) #endif } -#if 0 +/* This is for counting the calls to the flushSpy */ +static int flushSpyEnabled; +static unsigned int flushSpyCalls = 0; + +void startFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 1; } +void endFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 0; } +unsigned int getFlushSpyCalls(void) { return flushSpyCalls; } + void flushSpy(void) { - static unsigned int calls = 0; - calls++; // count every call + if (flushSpyEnabled){ flushSpyCalls++; } } -#endif void testFailureCountIncrementsAndIsReturnedAtEnd(void) { @@ -3420,6 +3429,20 @@ void testPrintNumbersUnsigned32(void) #endif } + +/* This is for counting the calls to the flushSpy */ +static int flushSpyEnabled; +static unsigned int flushSpyCalls = 0; + +void startFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 1; } +void endFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 0; } +unsigned int getFlushSpyCalls(void) { return flushSpyCalls; } + +void flushSpy(void) +{ + if (flushSpyEnabled){ flushSpyCalls++; } +} + // ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES 64 BIT SUPPORT ================== void testPrintNumbersInt64(void) From 37271e8a131d12bb73bfdf2a1fc5612d3f142b03 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 14:53:39 +0100 Subject: [PATCH 15/44] Fixed copy and paste error --- test/tests/testunity.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 3496990..0f74bc5 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -3430,19 +3430,6 @@ void testPrintNumbersUnsigned32(void) } -/* This is for counting the calls to the flushSpy */ -static int flushSpyEnabled; -static unsigned int flushSpyCalls = 0; - -void startFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 1; } -void endFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 0; } -unsigned int getFlushSpyCalls(void) { return flushSpyCalls; } - -void flushSpy(void) -{ - if (flushSpyEnabled){ flushSpyCalls++; } -} - // ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES 64 BIT SUPPORT ================== void testPrintNumbersInt64(void) From 5f67ac6ab2b3adf37f9cf62bda1eb3efe1383f88 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 16:32:04 +0100 Subject: [PATCH 16/44] Fixed copy and paste error, changed the signature from: void flushSpy(int c) {} to: void flushSpy(void) {} --- test/testdata/testRunnerGenerator.c | 2 +- test/testdata/testRunnerGeneratorSmall.c | 2 +- test/testdata/testRunnerGeneratorWithMocks.c | 2 +- test/tests/testparameterized.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/testdata/testRunnerGenerator.c b/test/testdata/testRunnerGenerator.c index 7a4d63b..62989a0 100644 --- a/test/testdata/testRunnerGenerator.c +++ b/test/testdata/testRunnerGenerator.c @@ -24,7 +24,7 @@ /* Include Passthroughs for Linking Tests */ void putcharSpy(int c) { (void)putchar(c);} -void flushSpy(int c) {} +void flushSpy(void) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/testdata/testRunnerGeneratorSmall.c b/test/testdata/testRunnerGeneratorSmall.c index a8707fb..c8aaf74 100644 --- a/test/testdata/testRunnerGeneratorSmall.c +++ b/test/testdata/testRunnerGeneratorSmall.c @@ -16,7 +16,7 @@ TEST_FILE("some_file.c") /* Include Passthroughs for Linking Tests */ void putcharSpy(int c) { (void)putchar(c);} -void flushSpy(int c) {} +void flushSpy(void) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/testdata/testRunnerGeneratorWithMocks.c b/test/testdata/testRunnerGeneratorWithMocks.c index a7d622d..4aacbf9 100644 --- a/test/testdata/testRunnerGeneratorWithMocks.c +++ b/test/testdata/testRunnerGeneratorWithMocks.c @@ -25,7 +25,7 @@ /* Include Passthroughs for Linking Tests */ void putcharSpy(int c) { (void)putchar(c);} -void flushSpy(int c) {} +void flushSpy(void) {} /* Global Variables Used During These Tests */ int CounterSetup = 0; diff --git a/test/tests/testparameterized.c b/test/tests/testparameterized.c index 7be7f2b..136cd2f 100644 --- a/test/tests/testparameterized.c +++ b/test/tests/testparameterized.c @@ -13,7 +13,7 @@ /* Include Passthroughs for Linking Tests */ void putcharSpy(int c) { (void)putchar(c);} -void flushSpy(int c) {} +void flushSpy(void) {} #define EXPECT_ABORT_BEGIN \ if (TEST_PROTECT()) \ From 2480a6124e6ace123041bbdaa14b0f42bcefafe1 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 17:08:49 +0100 Subject: [PATCH 17/44] Added unit test for the call to flush --- test/tests/testunity.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 0f74bc5..5258b6e 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -56,7 +56,7 @@ char* getBufferPutcharSpy(void); void startFlushSpy(void); void endFlushSpy(void); -unsigned int getFlushSpyCalls(void); +int getFlushSpyCalls(void); static int SetToOneToFailInTearDown; static int SetToOneMeanWeAlreadyCheckedThisGuy; @@ -3341,11 +3341,11 @@ void putcharSpy(int c) /* This is for counting the calls to the flushSpy */ static int flushSpyEnabled; -static unsigned int flushSpyCalls = 0; +static int flushSpyCalls = 0; void startFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 1; } void endFlushSpy(void) { flushSpyCalls = 0; flushSpyEnabled = 0; } -unsigned int getFlushSpyCalls(void) { return flushSpyCalls; } +int getFlushSpyCalls(void) { return flushSpyCalls; } void flushSpy(void) { @@ -3357,9 +3357,13 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void) UNITY_UINT savedFailures = Unity.TestFailures; Unity.CurrentTestFailed = 1; startPutcharSpy(); // Suppress output + startFlushSpy(); + TEST_ASSERT_EQUAL(0, getFlushSpyCalls()); UnityConcludeTest(); endPutcharSpy(); TEST_ASSERT_EQUAL(savedFailures + 1, Unity.TestFailures); + TEST_ASSERT_EQUAL(1, getFlushSpyCalls()); + endFlushSpy(); startPutcharSpy(); // Suppress output int failures = UnityEnd(); From 436a46d8efea78c23b6fe163214a30ff2bb10f51 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 17:43:08 +0100 Subject: [PATCH 18/44] Got the tests running --- test/Makefile | 1 + test/tests/testunity.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/test/Makefile b/test/Makefile index 89ece81..f3981bd 100644 --- a/test/Makefile +++ b/test/Makefile @@ -17,6 +17,7 @@ DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\) DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy DEFINES += -D UNITY_OUTPUT_FLUSH_HEADER_DECLARATION=flushSpy\(void\) +DEFINES += -D USING_FLUSH_SPY DEFINES += $(UNITY_SUPPORT_64) $(UNITY_INCLUDE_DOUBLE) UNITY_SUPPORT_64 = -D UNITY_SUPPORT_64 UNITY_INCLUDE_DOUBLE = -D UNITY_INCLUDE_DOUBLE diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 5258b6e..e05b2ba 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -3357,13 +3357,17 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void) UNITY_UINT savedFailures = Unity.TestFailures; Unity.CurrentTestFailed = 1; startPutcharSpy(); // Suppress output +#ifdef USING_FLUSH_SPY startFlushSpy(); TEST_ASSERT_EQUAL(0, getFlushSpyCalls()); +#endif UnityConcludeTest(); endPutcharSpy(); TEST_ASSERT_EQUAL(savedFailures + 1, Unity.TestFailures); +#ifdef USING_FLUSH_SPY TEST_ASSERT_EQUAL(1, getFlushSpyCalls()); endFlushSpy(); +#endif startPutcharSpy(); // Suppress output int failures = UnityEnd(); From e038ae2ade1e9436322a92a043d3a5abf3866a6e Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 18 Feb 2018 18:44:58 +0100 Subject: [PATCH 19/44] Refactored the test evaluation of the flushSpy --- test/Makefile | 1 - test/tests/testunity.c | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test/Makefile b/test/Makefile index f3981bd..89ece81 100644 --- a/test/Makefile +++ b/test/Makefile @@ -17,7 +17,6 @@ DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\) DEFINES += -D UNITY_OUTPUT_FLUSH=flushSpy DEFINES += -D UNITY_OUTPUT_FLUSH_HEADER_DECLARATION=flushSpy\(void\) -DEFINES += -D USING_FLUSH_SPY DEFINES += $(UNITY_SUPPORT_64) $(UNITY_INCLUDE_DOUBLE) UNITY_SUPPORT_64 = -D UNITY_SUPPORT_64 UNITY_INCLUDE_DOUBLE = -D UNITY_INCLUDE_DOUBLE diff --git a/test/tests/testunity.c b/test/tests/testunity.c index e05b2ba..95c8280 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -3357,17 +3357,17 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void) UNITY_UINT savedFailures = Unity.TestFailures; Unity.CurrentTestFailed = 1; startPutcharSpy(); // Suppress output -#ifdef USING_FLUSH_SPY startFlushSpy(); TEST_ASSERT_EQUAL(0, getFlushSpyCalls()); -#endif UnityConcludeTest(); endPutcharSpy(); TEST_ASSERT_EQUAL(savedFailures + 1, Unity.TestFailures); -#ifdef USING_FLUSH_SPY +#if defined(UNITY_OUTPUT_FLUSH) && defined(UNITY_OUTPUT_FLUSH_HEADER_DECLARATION) TEST_ASSERT_EQUAL(1, getFlushSpyCalls()); - endFlushSpy(); +#else + TEST_ASSERT_EQUAL(0, getFlushSpyCalls()); #endif + endFlushSpy(); startPutcharSpy(); // Suppress output int failures = UnityEnd(); From 0937bf728caed9503e2b5aae306036f9bb68e088 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Thu, 22 Feb 2018 19:55:40 +0100 Subject: [PATCH 20/44] - Removed member variable @test_flag - Fixed stdout output if fixture is active - Refactored the state manipulation of @test_suite and moved it completely into test_suite_verify() --- auto/parse_output.rb | 61 ++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index b5132a0..33d1f71 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -18,11 +18,11 @@ class ParseOutput def initialize - @test_flag = false @xml_out = false @array_list = false + @class_name = 0 + @test_suite = nil @total_tests = false - @class_index = false end # Set the flag to indicate if there will be an XML output file or not @@ -30,7 +30,7 @@ class ParseOutput @xml_out = true end - # if write our output to XML + # If write our output to XML def write_xml_output output = File.open('report.xml', 'w') output << "\n" @@ -40,12 +40,10 @@ class ParseOutput output << "\n" end - # This function will try and determine when the suite is changed. This is + # This function will try and determine when the suite is changed. This is # is the name that gets added to the classname parameter. def test_suite_verify(test_suite_name) - return if @test_flag - @test_flag = true # Split the path name test_name = if @class_name == 1 test_suite_name.split('\\') # Windows @@ -53,10 +51,15 @@ class ParseOutput test_suite_name.split('/') # Unix based end - # Remove the extension - base_name = test_name[test_name.size - 1].split('.') - @test_suite = 'test.' + base_name[0] - printf "New Test: %s\n", @test_suite + # Remove the extension and extract the base_name + base_name = test_name[test_name.size - 1].split('.')[0] + + # Is this a new test suite? + if base_name.to_s != @test_suite.to_s + @test_suite = base_name + printf "New Test: %s\n", @test_suite + end + end # Test was flagged as having passed so format the output @@ -77,7 +80,8 @@ class ParseOutput test_suite = array[0].sub('TEST(', '') test_suite = test_suite.sub(',', '') test_name = array[1].sub(')', '') - + test_suite_verify(array[@class_name]) + printf "%-40s PASS\n", test_name return unless @xml_out @array_list.push ' ' @@ -88,16 +92,21 @@ class ParseOutput last_item = array.length - 1 test_name = array[last_item - 2] reason = array[last_item].chomp.lstrip - test_suite_verify(array[@class_name]) - printf "%-40s IGNORED\n", test_name + class_name = array[@class_name] if test_name.start_with? 'TEST(' array2 = test_name.split(' ') - @test_suite = array2[0].sub('TEST(', '') - @test_suite = @test_suite.sub(',', '') + + test_suite = array2[0].sub('TEST(', '') + test_suite = test_suite.sub(',', '') + class_name = test_suite + test_name = array2[1].sub(')', '') end + test_suite_verify(class_name) + printf "%-40s IGNORED\n", test_name + return unless @xml_out @array_list.push ' ' @@ -110,16 +119,21 @@ class ParseOutput last_item = array.length - 1 test_name = array[last_item - 2] reason = array[last_item].chomp.lstrip + ' at line: ' + array[last_item - 3] - test_suite_verify(array[@class_name]) - printf "%-40s FAILED\n", test_name + class_name = array[@class_name] if test_name.start_with? 'TEST(' array2 = test_name.split(' ') - @test_suite = array2[0].sub('TEST(', '') - @test_suite = @test_suite.sub(',', '') + + test_suite = array2[0].sub('TEST(', '') + test_suite = test_suite.sub(',', '') + class_name = test_suite + test_name = array2[1].sub(')', '') end + test_suite_verify(class_name) + printf "%-40s FAILED\n", test_name + return unless @xml_out @array_list.push ' ' @@ -144,7 +158,6 @@ class ParseOutput # Main function used to parse the file that was captured. def process(name) - @test_flag = false @array_list = [] detect_os @@ -189,13 +202,7 @@ class ParseOutput test_passed_unity_fixture(line_array) test_pass += 1 end - # If none of the keywords are found there are no more tests for this suite so clear - # the test flag - else - @test_flag = false end - else - @test_flag = false end end puts '' @@ -208,7 +215,7 @@ class ParseOutput return unless @xml_out - heading = '' + heading = '' @array_list.insert(0, heading) write_xml_output end From ea51e2b35cb10fad3cbdc101142543daf96ea80f Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Thu, 22 Feb 2018 21:21:32 +0100 Subject: [PATCH 21/44] Refactored the os specific settings, it is now possible to convert both styles on every system (and even mixed) --- auto/parse_output.rb | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index 33d1f71..02adbdc 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -23,6 +23,7 @@ class ParseOutput @class_name = 0 @test_suite = nil @total_tests = false + @path_delim = nil end # Set the flag to indicate if there will be an XML output file or not @@ -45,11 +46,7 @@ class ParseOutput def test_suite_verify(test_suite_name) # Split the path name - test_name = if @class_name == 1 - test_suite_name.split('\\') # Windows - else - test_suite_name.split('/') # Unix based - end + test_name = test_suite_name.split(@path_delim) # Remove the extension and extract the base_name base_name = test_name[test_name.size - 1].split('.')[0] @@ -59,7 +56,6 @@ class ParseOutput @test_suite = base_name printf "New Test: %s\n", @test_suite end - end # Test was flagged as having passed so format the output @@ -141,27 +137,24 @@ class ParseOutput @array_list.push ' ' end - # Figure out what OS we are running on. For now we are assuming if it's not Windows it must - # be Unix based. - def detect_os - os = RUBY_PLATFORM.split('-') - @class_name = if os.size == 2 - if os[1] == 'mingw32' - 1 - else - 0 - end - else - 0 - end + # Adjusts the os specific members according to the current path style + # (Windows or Unix based) + def set_os_specifics(line) + if line.include? '\\' + # Windows X:\Y\Z + @class_name = 1 + @path_delim = '\\' + else + # Unix Based /X/Y/Z + @class_name = 0 + @path_delim = '/' + end end # Main function used to parse the file that was captured. def process(name) @array_list = [] - detect_os - puts 'Parsing file: ' + name test_pass = 0 @@ -177,6 +170,7 @@ class ParseOutput # /.c:115:test_tc5100_initCanVoidPtrs:PASS # # where path is different on Unix vs Windows devices (Windows leads with a drive letter) + set_os_specifics(line) line_array = line.split(':') # If we were able to split the line then we can look to see if any of our target words From 7a437665864a99320e88606bb6e901a64bc763da Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Thu, 22 Feb 2018 21:33:11 +0100 Subject: [PATCH 22/44] - Fixed whitespaces and formatting - Added more expressiveness to the code - Fixed some of the rubocop hints --- auto/parse_output.rb | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index 02adbdc..edb69fb 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -1,21 +1,22 @@ #============================================================ # Author: John Theofanopoulos -# A simple parser. Takes the output files generated during the build process and -# extracts information relating to the tests. +# A simple parser. Takes the output files generated during the +# build process and extracts information relating to the tests. # # Notes: # To capture an output file under VS builds use the following: # devenv [build instructions] > Output.txt & type Output.txt # -# To capture an output file under GCC/Linux builds use the following: +# To capture an output file under Linux builds use the following: # make | tee Output.txt # # To use this parser use the following command # ruby parseOutput.rb [options] [file] # options: -xml : produce a JUnit compatible XML file -# file : file to scan for results +# file: file to scan for results #============================================================ +# Parser class for handling the input file class ParseOutput def initialize @xml_out = false @@ -26,12 +27,12 @@ class ParseOutput @path_delim = nil end - # Set the flag to indicate if there will be an XML output file or not + # Set the flag to indicate if there will be an XML output file or not def set_xml_output @xml_out = true end - # If write our output to XML + # If write our output to XML def write_xml_output output = File.open('report.xml', 'w') output << "\n" @@ -44,18 +45,17 @@ class ParseOutput # This function will try and determine when the suite is changed. This is # is the name that gets added to the classname parameter. def test_suite_verify(test_suite_name) - # Split the path name test_name = test_suite_name.split(@path_delim) # Remove the extension and extract the base_name base_name = test_name[test_name.size - 1].split('.')[0] - # Is this a new test suite? - if base_name.to_s != @test_suite.to_s - @test_suite = base_name - printf "New Test: %s\n", @test_suite - end + # Return if the test suite hasn't changed + return unless base_name.to_s != @test_suite.to_s + + @test_suite = base_name + printf "New Test: %s\n", @test_suite end # Test was flagged as having passed so format the output @@ -78,6 +78,7 @@ class ParseOutput test_name = array[1].sub(')', '') test_suite_verify(array[@class_name]) printf "%-40s PASS\n", test_name + return unless @xml_out @array_list.push ' ' @@ -152,10 +153,10 @@ class ParseOutput end # Main function used to parse the file that was captured. - def process(name) + def process(file_name) @array_list = [] - puts 'Parsing file: ' + name + puts 'Parsing file: ' + file_name test_pass = 0 test_fail = 0 @@ -163,7 +164,7 @@ class ParseOutput puts '' puts '=================== RESULTS =====================' puts '' - File.open(name).each do |line| + File.open(file_name).each do |line| # Typical test lines look like this: # /.c:36:test_tc1000_opsys:FAIL: Expected 1 Was 0 # /.c:112:test_tc5004_initCanChannel:IGNORE: Not Yet Implemented @@ -219,11 +220,11 @@ end parse_my_file = ParseOutput.new if ARGV.size >= 1 - ARGV.each do |a| - if a == '-xml' + ARGV.each do |arg| + if arg == '-xml' parse_my_file.set_xml_output else - parse_my_file.process(a) + parse_my_file.process(arg) break end end From 1994bf9d68d792ece33f2750d62bb7c361f12ed8 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Mon, 26 Feb 2018 22:13:29 +0100 Subject: [PATCH 23/44] Fixed unity fixture output and added methods for each of the different outputs. Added documentation. Fixed some whitespaces. Refactored class_name to class_name_idx (expressiveness). Refactored the xml output to methods (extensibility). --- auto/parse_output.rb | 238 ++++++++++++++++++++++++++++--------------- 1 file changed, 156 insertions(+), 82 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index edb69fb..cbafd7c 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -1,30 +1,38 @@ #============================================================ -# Author: John Theofanopoulos -# A simple parser. Takes the output files generated during the +# Author: John Theofanopoulos +# A simple parser. Takes the output files generated during the # build process and extracts information relating to the tests. # # Notes: # To capture an output file under VS builds use the following: -# devenv [build instructions] > Output.txt & type Output.txt +# devenv [build instructions] > Output.txt & type Output.txt # # To capture an output file under Linux builds use the following: # make | tee Output.txt # # To use this parser use the following command # ruby parseOutput.rb [options] [file] -# options: -xml : produce a JUnit compatible XML file -# file: file to scan for results +# options: -xml : produce a JUnit compatible XML file +# file: file to scan for results #============================================================ # Parser class for handling the input file class ParseOutput def initialize + # internal data + @class_name_idx = 0 + @path_delim = nil + + # xml output related @xml_out = false @array_list = false - @class_name = 0 + + # current suite name and statistics @test_suite = nil - @total_tests = false - @path_delim = nil + @total_tests = 0 + @test_passed = 0 + @test_failed = 0 + @test_ignored = 0 end # Set the flag to indicate if there will be an XML output file or not @@ -39,7 +47,34 @@ class ParseOutput @array_list.each do |item| output << item << "\n" end - output << "\n" + end + + # Pushes the suite info as xml to the array list, which will be written later + def push_xml_output_suite_info + # Insert opening tag at front + heading = '' + @array_list.insert(0, heading) + # Push back the closing tag + @array_list.push '' + end + + # Pushes xml output data to the array list, which will be written later + def push_xml_output_passed(test_name) + @array_list.push ' ' + end + + # Pushes xml output data to the array list, which will be written later + def push_xml_output_failed(test_name, reason) + @array_list.push ' ' + @array_list.push ' ' + reason + '' + @array_list.push ' ' + end + + # Pushes xml output data to the array list, which will be written later + def push_xml_output_ignored(test_name, reason) + @array_list.push ' ' + @array_list.push ' ' + reason + '' + @array_list.push ' ' end # This function will try and determine when the suite is changed. This is @@ -58,65 +93,76 @@ class ParseOutput printf "New Test: %s\n", @test_suite end - # Test was flagged as having passed so format the output - def test_passed(array) - last_item = array.length - 1 - test_name = array[last_item - 1] - test_suite_verify(array[@class_name]) - printf "%-40s PASS\n", test_name - - return unless @xml_out - - @array_list.push ' ' + # Prepares the line for verbose fixture output ("-v") + def prepare_fixture_line(line) + line = line.sub('IGNORE_TEST(', '') + line = line.sub('TEST(', '') + line = line.sub(')', ',') + line = line.chomp + array = line.split(',') + array.map { |x| x.to_s.lstrip.chomp } end # Test was flagged as having passed so format the output. # This is using the Unity fixture output and not the original Unity output. def test_passed_unity_fixture(array) - test_suite = array[0].sub('TEST(', '') - test_suite = test_suite.sub(',', '') - test_name = array[1].sub(')', '') - test_suite_verify(array[@class_name]) + class_name = array[0] + test_name = array[1] + test_suite_verify(class_name) + printf "%-40s PASS\n", test_name + + push_xml_output_passed(test_name) if @xml_out + end + + # Test was flagged as having failed so format the output. + # This is using the Unity fixture output and not the original Unity output. + def test_failed_unity_fixture(array) + class_name = array[0] + test_name = array[1] + test_suite_verify(class_name) + reason_array = array[2].split(':') + reason = reason_array[-1].lstrip.chomp + ' at line: ' + reason_array[-4] + + printf "%-40s FAILED\n", test_name + + push_xml_output_failed(test_name, reason) if @xml_out + end + + # Test was flagged as being ignored so format the output. + # This is using the Unity fixture output and not the original Unity output. + def test_ignored_unity_fixture(array) + class_name = array[0] + test_name = array[1] + reason = 'No reason given' + if array.size > 2 + reason_array = array[2].split(':') + tmp_reason = reason_array[-1].lstrip.chomp + reason = tmp_reason == 'IGNORE' ? 'No reason given' : tmp_reason + end + test_suite_verify(class_name) + printf "%-40s IGNORED\n", test_name + + push_xml_output_ignored(test_name, reason) if @xml_out + end + + # Test was flagged as having passed so format the output + def test_passed(array) + last_item = array.length - 1 + test_name = array[last_item - 1] + test_suite_verify(array[@class_name_idx]) printf "%-40s PASS\n", test_name return unless @xml_out - @array_list.push ' ' + push_xml_output_passed(test_name) if @xml_out end - # Test was flagged as being ignored so format the output - def test_ignored(array) - last_item = array.length - 1 - test_name = array[last_item - 2] - reason = array[last_item].chomp.lstrip - class_name = array[@class_name] - - if test_name.start_with? 'TEST(' - array2 = test_name.split(' ') - - test_suite = array2[0].sub('TEST(', '') - test_suite = test_suite.sub(',', '') - class_name = test_suite - - test_name = array2[1].sub(')', '') - end - - test_suite_verify(class_name) - printf "%-40s IGNORED\n", test_name - - return unless @xml_out - - @array_list.push ' ' - @array_list.push ' ' + reason + '' - @array_list.push ' ' - end - - # Test was flagged as having failed so format the line + # Test was flagged as having failed so format the line def test_failed(array) last_item = array.length - 1 test_name = array[last_item - 2] reason = array[last_item].chomp.lstrip + ' at line: ' + array[last_item - 3] - class_name = array[@class_name] + class_name = array[@class_name_idx] if test_name.start_with? 'TEST(' array2 = test_name.split(' ') @@ -131,11 +177,30 @@ class ParseOutput test_suite_verify(class_name) printf "%-40s FAILED\n", test_name - return unless @xml_out + push_xml_output_failed(test_name, reason) if @xml_out + end - @array_list.push ' ' - @array_list.push ' ' + reason + '' - @array_list.push ' ' + # Test was flagged as being ignored so format the output + def test_ignored(array) + last_item = array.length - 1 + test_name = array[last_item - 2] + reason = array[last_item].chomp.lstrip + class_name = array[@class_name_idx] + + if test_name.start_with? 'TEST(' + array2 = test_name.split(' ') + + test_suite = array2[0].sub('TEST(', '') + test_suite = test_suite.sub(',', '') + class_name = test_suite + + test_name = array2[1].sub(')', '') + end + + test_suite_verify(class_name) + printf "%-40s IGNORED\n", test_name + + push_xml_output_ignored(test_name, reason) if @xml_out end # Adjusts the os specific members according to the current path style @@ -143,11 +208,11 @@ class ParseOutput def set_os_specifics(line) if line.include? '\\' # Windows X:\Y\Z - @class_name = 1 + @class_name_idx = 1 @path_delim = '\\' else # Unix Based /X/Y/Z - @class_name = 0 + @class_name_idx = 0 @path_delim = '/' end end @@ -158,9 +223,9 @@ class ParseOutput puts 'Parsing file: ' + file_name - test_pass = 0 - test_fail = 0 - test_ignore = 0 + @test_passed = 0 + @test_failed = 0 + @test_ignored = 0 puts '' puts '=================== RESULTS =====================' puts '' @@ -175,43 +240,52 @@ class ParseOutput line_array = line.split(':') # If we were able to split the line then we can look to see if any of our target words - # were found. Case is important. - if (line_array.size >= 4) || (line.start_with? 'TEST(') - # Determine if this test passed - if line.include? ':PASS' + # were found. Case is important. + if (line_array.size >= 4) || (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') + + # check if the output is fixture output (with verbose flag "-v") + if (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') + line_array = prepare_fixture_line(line) + if line.include? ' PASS' + test_passed_unity_fixture(line_array) + @test_passed += 1 + elsif line.include? 'FAIL' + test_failed_unity_fixture(line_array) + @test_failed += 1 + elsif line.include? 'IGNORE' + test_ignored_unity_fixture(line_array) + @test_ignored += 1 + end + # normal output / fixture output (without verbose "-v") + elsif line.include? ':PASS' test_passed(line_array) - test_pass += 1 + @test_passed += 1 elsif line.include? ':FAIL' test_failed(line_array) - test_fail += 1 + @test_failed += 1 elsif line.include? ':IGNORE:' test_ignored(line_array) - test_ignore += 1 + @test_ignored += 1 elsif line.include? ':IGNORE' line_array.push('No reason given') test_ignored(line_array) - test_ignore += 1 - elsif line.start_with? 'TEST(' - if line.include? ' PASS' - line_array = line.split(' ') - test_passed_unity_fixture(line_array) - test_pass += 1 - end + @test_ignored += 1 end + @total_tests = @test_passed + @test_failed + @test_ignored end end puts '' puts '=================== SUMMARY =====================' puts '' - puts 'Tests Passed : ' + test_pass.to_s - puts 'Tests Failed : ' + test_fail.to_s - puts 'Tests Ignored : ' + test_ignore.to_s - @total_tests = test_pass + test_fail + test_ignore + puts 'Tests Passed : ' + @test_passed.to_s + puts 'Tests Failed : ' + @test_failed.to_s + puts 'Tests Ignored : ' + @test_ignored.to_s return unless @xml_out - heading = '' - @array_list.insert(0, heading) + # push information about the suite + push_xml_output_suite_info + # write xml output file write_xml_output end end From 38e1ee872ccf2989ff873415ce98fd20ba9c2f1a Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Tue, 27 Feb 2018 07:23:18 +0100 Subject: [PATCH 24/44] Added some useful documentation which states the output formats that are parseable by this script. --- auto/parse_output.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index cbafd7c..f04508f 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -10,6 +10,11 @@ # To capture an output file under Linux builds use the following: # make | tee Output.txt # +# This script can handle the following output formats: +# - normal output (raw unity) +# - fixture output (unity_fixture.h/.c) +# - fixture output with verbose flag set ("-v") +# # To use this parser use the following command # ruby parseOutput.rb [options] [file] # options: -xml : produce a JUnit compatible XML file @@ -230,12 +235,25 @@ class ParseOutput puts '=================== RESULTS =====================' puts '' File.open(file_name).each do |line| - # Typical test lines look like this: + # Typical test lines look like these: + # ---------------------------------------------------- + # 1. normal output: # /.c:36:test_tc1000_opsys:FAIL: Expected 1 Was 0 # /.c:112:test_tc5004_initCanChannel:IGNORE: Not Yet Implemented # /.c:115:test_tc5100_initCanVoidPtrs:PASS # - # where path is different on Unix vs Windows devices (Windows leads with a drive letter) + # 2. fixture output + # /.c:63:TEST(, ):FAIL: Expected 0x00001234 Was 0x00005A5A + # /.c:36:TEST(, ):IGNORE + # Note: "PASS" information won't be generated in this mode + # + # 3. fixture output with verbose information ("-v") + # TEST()/:168::FAIL: Expected 0x8D Was 0x8C + # TEST(, )/:22::IGNORE: This Test Was Ignored On Purpose + # IGNORE_TEST() + # TEST() PASS + # + # Note: Where path is different on Unix vs Windows devices (Windows leads with a drive letter)! set_os_specifics(line) line_array = line.split(':') From ceecf1fae8129662381559686fd9adfe7b12a1cf Mon Sep 17 00:00:00 2001 From: Trond Einar Snekvik Date: Thu, 7 Jun 2018 10:06:39 +0200 Subject: [PATCH 25/44] Add support for :mock_suffix Adds support for :mock_suffix when generating mock setup and teardown functions. Also documents both prefix and suffix in the helper script guide. --- auto/generate_test_runner.rb | 3 ++- docs/UnityHelperScriptsGuide.md | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 427c513..84daa42 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -26,6 +26,7 @@ class UnityTestRunnerGenerator framework: :unity, test_prefix: 'test|spec|should', mock_prefix: 'Mock', + mock_suffix: '', setup_name: 'setUp', teardown_name: 'tearDown', main_name: 'main', # set to :auto to automatically generate each time @@ -148,7 +149,7 @@ class UnityTestRunnerGenerator mock_headers = [] includes.each do |include_path| include_file = File.basename(include_path) - mock_headers << include_path if include_file =~ /^#{@options[:mock_prefix]}/i + mock_headers << include_path if include_file =~ /^#{@options[:mock_prefix]}.*#{@options[:mock_suffix]}$/i end mock_headers end diff --git a/docs/UnityHelperScriptsGuide.md b/docs/UnityHelperScriptsGuide.md index 4242990..8b0df1b 100644 --- a/docs/UnityHelperScriptsGuide.md +++ b/docs/UnityHelperScriptsGuide.md @@ -159,6 +159,12 @@ CMock (see CMock documentation). This generates extra variables required for everything to run smoothly. If you provide the same YAML to the generator as used in CMock's configuration, you've already configured the generator properly. +##### `:mock_prefix` and `:mock_suffix` + +Unity automatically generates calls to Init, Verify and Destroy for every file +included in the main test file that starts with the given mock prefix and ends +with the given mock suffix, file extension not included. By default, Unity +assumes a `Mock` prefix and no suffix. ##### `:plugins` From 40af5e23eb8ff9402ce1d0419ff44513554e1c02 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Wed, 18 Jul 2018 11:20:29 -0400 Subject: [PATCH 26/44] Update travis to specify valid version of rubocop --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bd165b1..5a15f03 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ before_install: - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --assume-yes --quiet gcc-multilib; fi install: - gem install rspec - - gem install rubocop + - gem install rubocop -v 0.57.2 script: - cd test && rake ci - make -s From 2c5d09bf203a88bcbda5da19843437fcfe7b4525 Mon Sep 17 00:00:00 2001 From: Xenoamor Date: Wed, 18 Jul 2018 16:05:10 +0100 Subject: [PATCH 27/44] Flush unity output before a potential longjmp Flush the unity stdout buffer before calling TEST_ABORT(). This is because if TEST_PROTECT() has not previously been called this will cause a segmentation fault and the stdout buffer will fail to print Although the segmentation fault will still occur, the error that caused it will at least be displayed --- src/unity.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unity.c b/src/unity.c index 136e9d7..44a8003 100644 --- a/src/unity.c +++ b/src/unity.c @@ -14,8 +14,8 @@ void UNITY_OUTPUT_CHAR(int); #endif /* Helpful macros for us to use here in Assert functions */ -#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; TEST_ABORT(); } -#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; TEST_ABORT(); } +#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_FLUSH(); TEST_ABORT(); } +#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_FLUSH(); TEST_ABORT(); } #define RETURN_IF_FAIL_OR_IGNORE if (Unity.CurrentTestFailed || Unity.CurrentTestIgnored) return struct UNITY_STORAGE_T Unity; From ac3cde30f5257c13bffae48676a69d410dcb639f Mon Sep 17 00:00:00 2001 From: Roland Stahn Date: Sat, 21 Jul 2018 16:57:53 +0200 Subject: [PATCH 28/44] Added notes on _MESSAGE assertions (#331) Added notes, why _MESSAGE assertions do not support printf style formatting and how users can work around this limitation (see #331) --- docs/UnityAssertionsReference.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/UnityAssertionsReference.md b/docs/UnityAssertionsReference.md index 2dcf5e3..d569e76 100644 --- a/docs/UnityAssertionsReference.md +++ b/docs/UnityAssertionsReference.md @@ -104,6 +104,15 @@ 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 + 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` + assertions (see below) might be a handy alternative to `sprintf`. + #### TEST_ASSERT_X_ARRAY Variants From 6a1d2e8d44fb256ee47368bdee49ed8eb020ee4d Mon Sep 17 00:00:00 2001 From: Roland Stahn Date: Wed, 25 Jul 2018 22:57:44 +0200 Subject: [PATCH 29/44] Fix LESS_OR_EQUAL_MESSAGE asserts for HEX32/HEX64 Macros TEST_ASSERT_LESS_OR_EQUAL_HEX32_MESSAGE() and TEST_ASSERT_LESS_OR_EQUAL_HEX64_MESSAGE() need to be mapped to UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEXnn() instead of UNITY_TEST_ASSERT_SMALLER_THAN_HEXnn() --- src/unity.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unity.h b/src/unity.h index 32ff0e6..a0c301d 100644 --- a/src/unity.h +++ b/src/unity.h @@ -402,8 +402,8 @@ int suiteTearDown(int num_failures); #define TEST_ASSERT_LESS_OR_EQUAL_UINT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT64((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX8((threshold), (actual), __LINE__, (message)) #define TEST_ASSERT_LESS_OR_EQUAL_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX64((threshold), (actual), __LINE__, (message)) +#define TEST_ASSERT_LESS_OR_EQUAL_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX32((threshold), (actual), __LINE__, (message)) +#define TEST_ASSERT_LESS_OR_EQUAL_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX64((threshold), (actual), __LINE__, (message)) /* Integer Ranges (of all sizes) */ #define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN((delta), (expected), (actual), __LINE__, (message)) From fb4b13904339b90b51a57b5cca9e6efb4681402d Mon Sep 17 00:00:00 2001 From: elliot Date: Sat, 28 Jul 2018 20:14:00 +0100 Subject: [PATCH 30/44] Fixed UNITY_EXEC_TIME_STOP macro ifdef --- src/unity_internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unity_internals.h b/src/unity_internals.h index 9c0d4ee..351d9fe 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -307,7 +307,7 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT; #endif #endif -#ifndef UNITY_EXEC_TIME_START +#ifndef UNITY_EXEC_TIME_STOP #ifdef UNITY_INCLUDE_EXEC_TIME #define UNITY_EXEC_TIME_STOP() Unity.CurrentTestStopTime = UNITY_CLOCK_MS(); #else From e72dfafd440054ccdf6c8034112e36cd0156c1fb Mon Sep 17 00:00:00 2001 From: Deryew <40446717+Deryew@users.noreply.github.com> Date: Mon, 30 Jul 2018 10:53:02 +0800 Subject: [PATCH 31/44] Fixed some grammar errors on docs Fixed grammar errors and some sentences to make it easier to understand --- docs/ThrowTheSwitchCodingStandard.md | 19 +++++++++---------- docs/UnityAssertionsReference.md | 4 ++-- docs/UnityConfigurationGuide.md | 8 ++++---- docs/UnityGettingStartedGuide.md | 4 ++-- docs/UnityHelperScriptsGuide.md | 4 ++-- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/docs/ThrowTheSwitchCodingStandard.md b/docs/ThrowTheSwitchCodingStandard.md index a85adef..bf4c099 100644 --- a/docs/ThrowTheSwitchCodingStandard.md +++ b/docs/ThrowTheSwitchCodingStandard.md @@ -1,4 +1,4 @@ -# ThrowTheSwitch.org Coding Standard +# ThrowTheSwitch.org Coding Standard Hi. Welcome to the coding standard for ThrowTheSwitch.org. For the most part, we try to follow these standards to unify our contributors' code into a cohesive @@ -11,7 +11,7 @@ and we'll try to be polite when we notice yours. ## Why Have A Coding Standard? -Being consistent makes code easier to understand. We've made an attempt to keep +Being consistent makes code easier to understand. We've tried to keep our standard simple because we also believe that we can only expect someone to follow something that is understandable. Please do your best. @@ -51,11 +51,11 @@ much as they can, but give the user the power to override it when it's wrong. Let's talk about naming things. Programming is all about naming things. We name files, functions, variables, and so much more. While we're not always going to -find the best name for something, we actually put quite a bit of effort into +find the best name for something, we actually put a bit of effort into finding *What Something WANTS to be Called*™. -When naming things, we more or less follow this hierarchy, the first being the -most important to us (but we do all four whenever possible): +When naming things, we follow this hierarchy, the first being the +most important to us (but we do all four when possible): 1. Readable 2. Descriptive 3. Consistent @@ -74,7 +74,7 @@ abbreviations (sticking to ones we feel are common). We like descriptive names for things, especially functions and variables. Finding the right name for something is an important endeavor. You might notice from poking around our code that this often results in names that are a little -longer than the average. Guilty. We're okay with a tiny bit more typing if it +longer than the average. Guilty. We're okay with a bit more typing if it means our code is easier to understand. There are two exceptions to this rule that we also stick to as religiously as @@ -82,8 +82,7 @@ possible: First, while we realize hungarian notation (and similar systems for encoding type information into variable names) is providing a more descriptive name, we -feel that (for the average developer) it takes away from readability and -therefore is to be avoided. +feel that (for the average developer) it takes away from readability and is to be avoided. Second, loop counters and other local throw-away variables often have a purpose which is obvious. There's no need, therefore, to get carried away with complex @@ -128,7 +127,7 @@ the same. It will only hurt a little. We promise. #### Whitespace Our C-style is to use spaces and to use 4 of them per indent level. It's a nice -power-of-2 number that looks decent on a wide screen. We have no more reason +power-of-2 number that looks decent on a wide-screen. We have no more reason than that. We break that rule when we have lines that wrap (macros or function arguments or whatnot). When that happens, we like to indent further to line things up in nice tidy columns. @@ -200,7 +199,7 @@ that happens, we like to indent further to line things up in nice tidy columns. ## Documentation -Egad. Really? We use markdown and we like pdf files because they can be made to +Egad. Really? We use mark down and we like pdf files because they can be made to look nice while still being portable. Good enough? diff --git a/docs/UnityAssertionsReference.md b/docs/UnityAssertionsReference.md index d569e76..eb855f3 100644 --- a/docs/UnityAssertionsReference.md +++ b/docs/UnityAssertionsReference.md @@ -80,7 +80,7 @@ marked as an optional parameter because some assertions only need a single "actual" parameter (e.g. null check). "Size/count" refers to string lengths, number of array elements, etc. -Many of Unity's assertions are apparent duplications in that the same data type +Many of Unity's assertions are clear duplications in that the same data type is handled by several assertions. The differences among these are in how failure messages are presented. For instance, a `_HEX` variant of an assertion prints the expected and actual values of that assertion formatted as hexadecimal. @@ -703,7 +703,7 @@ point value. So what happens when it's zero? Zero - even more than other floating point values - can be represented many different ways. It doesn't matter if you have -0 x 20or 0 x 263.It's still zero, right? Luckily, if you +0 x 20 or 0 x 263.It's still zero, right? Luckily, if you subtract these values from each other, they will always produce a difference of zero, which will still fall between 0 plus or minus a delta of 0. So it still works! diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index 1b69828..dace20c 100644 --- a/docs/UnityConfigurationGuide.md +++ b/docs/UnityConfigurationGuide.md @@ -1,4 +1,4 @@ -# Unity Configuration Guide +# Unity Configuration Guide ## C Standards, Compilers and Microcontrollers @@ -19,7 +19,7 @@ definitions. A couple are macros with arguments. They live inside the unity_internals.h header file. We don't necessarily recommend opening that file unless you really need to. That file is proof that a cross-platform library is challenging to build. From a more positive perspective, it is also proof that a -great deal of complexity can be centralized primarily to one place in order to +great deal of complexity can be centralized primarily to one place to provide a more consistent and simple experience elsewhere. @@ -58,7 +58,7 @@ sizes. It starts off by trying to do it automatically. ##### `UNITY_EXCLUDE_STDINT_H` The first thing that Unity does to guess your types is check `stdint.h`. -This file includes defines like `UINT_MAX` that Unity can make use of to +This file includes defines like `UINT_MAX` that Unity can use to learn a lot about your system. It's possible you don't want it to do this (um. why not?) or (more likely) it's possible that your system doesn't support `stdint.h`. If that's the case, you're going to want to define this. @@ -222,7 +222,7 @@ In addition to the options listed above, there are a number of other options which will come in handy to customize Unity's behavior for your specific toolchain. It is possible that you may not need to touch any of these... but certain platforms, particularly those running in simulators, may need to jump -through extra hoops to operate properly. These macros will help in those +through extra hoops to run properly. These macros will help in those situations. diff --git a/docs/UnityGettingStartedGuide.md b/docs/UnityGettingStartedGuide.md index 81d0398..5e4427c 100644 --- a/docs/UnityGettingStartedGuide.md +++ b/docs/UnityGettingStartedGuide.md @@ -11,7 +11,7 @@ functional. The core Unity test framework is three files: a single C file and a couple header files. These team up to provide functions and macros to make testing easier. -Unity was designed to be cross platform. It works hard to stick with C standards +Unity was designed to be cross-platform. It works hard to stick with C standards while still providing support for the many embedded C compilers that bend the rules. Unity has been used with many compilers, including GCC, IAR, Clang, Green Hills, Microchip, and MS Visual Studio. It's not much work to get it to @@ -149,7 +149,7 @@ int main(void) { } ``` -It's possible that you will require more customization than this, eventually. +It's possible that you will need more customization than this, eventually. For that sort of thing, you're going to want to look at the configuration guide. This should be enough to get you going, though. diff --git a/docs/UnityHelperScriptsGuide.md b/docs/UnityHelperScriptsGuide.md index 8b0df1b..12d68d3 100644 --- a/docs/UnityHelperScriptsGuide.md +++ b/docs/UnityHelperScriptsGuide.md @@ -3,7 +3,7 @@ ## With a Little Help From Our Friends Sometimes what it takes to be a really efficient C programmer is a little non-C. -The Unity project includes a couple Ruby scripts for making your life just a tad +The Unity project includes a couple of Ruby scripts for making your life just a tad easier. They are completely optional. If you choose to use them, you'll need a copy of Ruby, of course. Just install whatever the latest version is, and it is likely to work. You can find Ruby at [ruby-lang.org](https://ruby-labg.org/). @@ -105,7 +105,7 @@ UnityTestRunnerGenerator.new.run(testfile, runner_name, options) If you have multiple files to generate in a build script (such as a Rakefile), you might want to instantiate a generator object with your options and call it -to generate each runner thereafter. Like thus: +to generate each runner afterwards. Like thus: ```Ruby gen = UnityTestRunnerGenerator.new(options) From 9987824da794ce53ff77137f237dcebec91f3dd6 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Thu, 9 Aug 2018 08:48:08 -0400 Subject: [PATCH 32/44] Added support to inject "extern C" into runners when generated. --- auto/generate_test_runner.rb | 3 +++ docs/UnityHelperScriptsGuide.md | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 84daa42..2f14966 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -197,9 +197,11 @@ class UnityTestRunnerGenerator output.puts("\n/*=======External Functions This Runner Calls=====*/") output.puts("extern void #{@options[:setup_name]}(void);") output.puts("extern void #{@options[:teardown_name]}(void);") + output.puts("\n#ifdef __cplusplus\nextern \"C\"\n{\n#endif") if @options[:externc] tests.each do |test| output.puts("extern void #{test[:test]}(#{test[:call] || 'void'});") end + output.puts("#ifdef __cplusplus\n}\n#endif") if @options[:externc] output.puts('') end @@ -439,6 +441,7 @@ if $0 == __FILE__ ' *.h - header files are added as #includes in runner', ' options:', ' -cexception - include cexception support', + ' -externc - add extern "C" for cpp support', ' --setup_name="" - redefine setUp func name to something else', ' --teardown_name="" - redefine tearDown func name to something else', ' --main_name="" - redefine main func name to something else', diff --git a/docs/UnityHelperScriptsGuide.md b/docs/UnityHelperScriptsGuide.md index 12d68d3..da56db2 100644 --- a/docs/UnityHelperScriptsGuide.md +++ b/docs/UnityHelperScriptsGuide.md @@ -159,6 +159,12 @@ CMock (see CMock documentation). This generates extra variables required for everything to run smoothly. If you provide the same YAML to the generator as used in CMock's configuration, you've already configured the generator properly. + +##### `:externc` + +This option should be defined if you are mixing C and CPP and want your test +runners to automatically include extern "C" support when they are generated. + ##### `:mock_prefix` and `:mock_suffix` Unity automatically generates calls to Init, Verify and Destroy for every file From e0d52d1a7908a4c0a78c439919c31c71bc2dc8d5 Mon Sep 17 00:00:00 2001 From: Kyle Krueger Date: Wed, 12 Sep 2018 17:46:11 +0200 Subject: [PATCH 33/44] fix uninitialzed value warning --- src/unity.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 103bde2..4bad2c2 100644 --- a/src/unity.c +++ b/src/unity.c @@ -283,7 +283,7 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) int exponent = 0; int decimals, digits; UNITY_INT32 n; - char buf[16]; + char buf[16] = {0}; /* scale up or down by powers of 10 */ while (number < 100000.0f / 1e6f) { number *= 1e6f; exponent -= 6; } From e2e549a22f55465074e9f73c4012473a9a7f56e3 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sun, 14 Oct 2018 14:08:09 +0200 Subject: [PATCH 34/44] Added include of 'stddef.h' to 'unity_internals.h' if 'UNITY_EXCLUDE_STDDEF_H' is not defined. This adds compiler independent support for the 'NULL' macro. --- docs/UnityConfigurationGuide.md | 12 ++++++++++++ src/unity_internals.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index dace20c..b88eeee 100644 --- a/docs/UnityConfigurationGuide.md +++ b/docs/UnityConfigurationGuide.md @@ -215,6 +215,18 @@ Guide. _Example:_ #define UNITY_FLOAT_PRECISION 0.001f +### Miscellaneous + +##### `UNITY_EXCLUDE_STDDEF_H` + +Unity uses the `NULL` macro, which defines the value of a null pointer constant, +defined in `stddef.h` by default. If you want to provide +your own macro for this, you should exclude the `stddef.h` header file by adding this +define to your configuration. + +_Example:_ + #define UNITY_EXCLUDE_STDDEF_H + ### Toolset Customization diff --git a/src/unity_internals.h b/src/unity_internals.h index 351d9fe..4c55ef8 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -19,6 +19,10 @@ #include #endif +#ifndef UNITY_EXCLUDE_STDDEF_H +#include +#endif + /* Unity Attempts to Auto-Detect Integer Types * Attempt 1: UINT_MAX, ULONG_MAX in , or default to 32 bits * Attempt 2: UINTPTR_MAX in , or default to same size as long From 7cc3cf478bfae76b516f245ac3e5ff12f09f3ef4 Mon Sep 17 00:00:00 2001 From: Levin Messing Date: Thu, 18 Oct 2018 23:55:38 +0200 Subject: [PATCH 35/44] fixed compile error UNITY_PRINT_EXEC_TIME() --- src/unity_internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unity_internals.h b/src/unity_internals.h index 4c55ef8..7249fc7 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -323,7 +323,7 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT; #ifdef UNITY_INCLUDE_EXEC_TIME #define UNITY_PRINT_EXEC_TIME() \ UnityPrint(" (");\ - UNITY_COUNTER_TYPE execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); + UNITY_COUNTER_TYPE execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime);\ UnityPrintNumberUnsigned(execTimeMs);\ UnityPrint(" ms)"); #else From 01cbce870a55037cc808235b71e83d29ef1417ae Mon Sep 17 00:00:00 2001 From: Filip Michalak Date: Mon, 22 Oct 2018 15:32:22 +0200 Subject: [PATCH 36/44] Changed some text issues --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ec73b4a..abddd4c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Running Tests RUN_TEST(func, linenum) -Each Test is run within the macro `RUN_TEST`. This macro performs necessary setup before the test is called and handles cleanup and result tabulation afterwards. +Each Test is run within the macro `RUN_TEST`. This macro performs necessary setup before the test is called and handles cleanup and result tabulation afterwards. Ignoring Tests -------------- @@ -75,7 +75,7 @@ Another way of calling `TEST_ASSERT_FALSE` TEST_FAIL() TEST_FAIL_MESSAGE(message) -This test is automatically marked as a failure. The message is output stating why. +This test is automatically marked as a failure. The message is output stating why. Numerical Assertions: Integers ------------------------------ @@ -87,7 +87,7 @@ Numerical Assertions: Integers TEST_ASSERT_EQUAL_INT64(expected, actual) Compare two integers for equality and display errors as signed integers. A cast will be performed -to your natural integer size so often this can just be used. When you need to specify the exact size, +to your natural integer size so often this can just be used. When you need to specify the exact size, like when comparing arrays, you can use a specific version: TEST_ASSERT_EQUAL_UINT(expected, actual) @@ -96,7 +96,7 @@ like when comparing arrays, you can use a specific version: TEST_ASSERT_EQUAL_UINT32(expected, actual) TEST_ASSERT_EQUAL_UINT64(expected, actual) -Compare two integers for equality and display errors as unsigned integers. Like INT, there are +Compare two integers for equality and display errors as unsigned integers. Like INT, there are variants for different sizes also. TEST_ASSERT_EQUAL_HEX(expected, actual) @@ -105,7 +105,7 @@ variants for different sizes also. TEST_ASSERT_EQUAL_HEX32(expected, actual) TEST_ASSERT_EQUAL_HEX64(expected, actual) -Compares two integers for equality and display errors as hexadecimal. Like the other integer comparisons, +Compares two integers for equality and display errors as hexadecimal. Like the other integer comparisons, you can specify the size... here the size will also effect how many nibbles are shown (for example, `HEX16` will show 4 nibbles). @@ -115,7 +115,7 @@ Another way of calling TEST_ASSERT_EQUAL_INT TEST_ASSERT_INT_WITHIN(delta, expected, actual) -Asserts that the actual value is within plus or minus delta of the expected value. This also comes in +Asserts that the actual value is within plus or minus delta of the expected value. This also comes in size specific variants. @@ -199,12 +199,12 @@ Compare two null-terminate strings. Fail if any character is different or if th TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message) -Compare two strings. Fail if any character is different, stop comparing after len characters. Output a custom message on failure. +Compare two strings. Fail if any character is different, stop comparing after len characters. Output a custom message on failure. Pointer Assertions ------------------ -Most pointer operations can be performed by simply using the integer comparisons above. However, a couple of special cases are added for clarity. +Most pointer operations can be performed by simply using the integer comparisons above. However, a couple of special cases are added for clarity. TEST_ASSERT_NULL(pointer) From e84cb29acc0e01e22728bc6bf093329b67710588 Mon Sep 17 00:00:00 2001 From: Fabian Zahn Date: Sat, 27 Oct 2018 11:24:29 +0200 Subject: [PATCH 37/44] Fixed an "array index out of bounds violation" in the examples (regarding issue #360). --- examples/example_1/src/ProductionCode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/example_1/src/ProductionCode.c b/examples/example_1/src/ProductionCode.c index d039c3e..db128e5 100644 --- a/examples/example_1/src/ProductionCode.c +++ b/examples/example_1/src/ProductionCode.c @@ -4,14 +4,14 @@ int Counter = 0; int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; /* some obnoxious array to search that is 1-based indexing instead of 0. */ -/* This function is supposed to search through NumbersToFind and find a particular number. - * If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since - * NumbersToFind is indexed from 1. Unfortunately it's broken +/* This function is supposed to search through NumbersToFind and find a particular number. + * If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since + * NumbersToFind is indexed from 1. Unfortunately it's broken * (and should therefore be caught by our tests) */ int FindFunction_WhichIsBroken(int NumberToFind) { int i = 0; - while (i <= 8) /* Notice I should have been in braces */ + while (i < 8) /* Notice I should have been in braces */ i++; if (NumbersToFind[i] == NumberToFind) /* Yikes! I'm getting run after the loop finishes instead of during it! */ return i; From be765649f1f4203de9ea79241f6c9f929b056502 Mon Sep 17 00:00:00 2001 From: Kochise Date: Wed, 31 Oct 2018 11:24:37 +0100 Subject: [PATCH 38/44] Some cleanup --- src/unity_internals.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/unity_internals.h b/src/unity_internals.h index 7249fc7..0d047da 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -359,7 +359,6 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT; # undef UNITY_WEAK_PRAGMA #endif - /*------------------------------------------------------- * Internal Structs Needed *-------------------------------------------------------*/ @@ -400,11 +399,13 @@ UNITY_DISPLAY_STYLE_UINT = sizeof(unsigned) + UNITY_DISPLAY_RANGE_UINT, typedef enum { + UNITY_WITHIN = 0, UNITY_EQUAL_TO = 1, UNITY_GREATER_THAN = 2, UNITY_GREATER_OR_EQUAL = 2 + UNITY_EQUAL_TO, UNITY_SMALLER_THAN = 4, - UNITY_SMALLER_OR_EQUAL = 4 + UNITY_EQUAL_TO + UNITY_SMALLER_OR_EQUAL = 4 + UNITY_EQUAL_TO, + UNITY_UNKNOWN } UNITY_COMPARISON_T; #ifndef UNITY_EXCLUDE_FLOAT @@ -425,7 +426,8 @@ typedef enum UNITY_FLOAT_TRAIT typedef enum { UNITY_ARRAY_TO_VAL = 0, - UNITY_ARRAY_TO_ARRAY + UNITY_ARRAY_TO_ARRAY, + UNITY_ARRAY_UNKNOWN } UNITY_FLAGS_T; struct UNITY_STORAGE_T @@ -568,9 +570,9 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style); -void UnityFail(const char* msg, const UNITY_LINE_TYPE line); +void UnityFail(const char* message, const UNITY_LINE_TYPE line); -void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line); +void UnityIgnore(const char* message, const UNITY_LINE_TYPE line); #ifndef UNITY_EXCLUDE_FLOAT void UnityAssertFloatsWithin(const UNITY_FLOAT delta, @@ -826,9 +828,9 @@ int UnityTestMatches(void); #define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_ARRAY) #define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EACH_EQUAL_INT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)expected, 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT64)expected, 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)expected, 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_INT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_INT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) #define UNITY_TEST_ASSERT_UINT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) #define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) @@ -910,10 +912,10 @@ int UnityTestMatches(void); #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) #else -#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((UNITY_DOUBLE)(delta), (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)line) -#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((UNITY_DOUBLE)(expected) * (UNITY_DOUBLE)UNITY_DOUBLE_PRECISION, (UNITY_DOUBLE)expected, (UNITY_DOUBLE)actual, (UNITY_LINE_TYPE)(line), message) -#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((UNITY_DOUBLE*)(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray(UnityDoubleToPtr(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_ARRAY_TO_VAL) +#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((UNITY_DOUBLE)(delta), (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line)) +#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((UNITY_DOUBLE)(expected) * (UNITY_DOUBLE)UNITY_DOUBLE_PRECISION, (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (UNITY_LINE_TYPE)(line), (message)) +#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((UNITY_DOUBLE*)(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) +#define UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray(UnityDoubleToPtr(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) #define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_INF) #define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NEG_INF) #define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NAN) From 96127581a041a2c76a3a6ae6659499dbb7dc1678 Mon Sep 17 00:00:00 2001 From: Kochise Date: Wed, 31 Oct 2018 11:30:13 +0100 Subject: [PATCH 39/44] Some cleanup --- src/unity.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 103bde2..4efc47f 100644 --- a/src/unity.c +++ b/src/unity.c @@ -67,6 +67,7 @@ static const char UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " "; * Pretty Printers & Test Result Output Handlers *-----------------------------------------------*/ +/*-----------------------------------------------*/ void UnityPrint(const char* string) { const char* pch = string; @@ -116,6 +117,7 @@ void UnityPrint(const char* string) } } +/*-----------------------------------------------*/ void UnityPrintLen(const char* string, const UNITY_UINT32 length) { const char* pch = string; @@ -479,6 +481,7 @@ static void UnityPrintExpectedAndActualStringsLen(const char* expected, * Assertion & Control Helpers *-----------------------------------------------*/ +/*-----------------------------------------------*/ static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_LINE_TYPE lineNumber, @@ -511,6 +514,7 @@ static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected, * Assertion Functions *-----------------------------------------------*/ +/*-----------------------------------------------*/ void UnityAssertBits(const UNITY_INT mask, const UNITY_INT expected, const UNITY_INT actual, @@ -704,12 +708,14 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UnityPrint(UnityStrDelta) #endif /* UNITY_EXCLUDE_FLOAT_PRINT */ +/*-----------------------------------------------*/ static int UnityFloatsWithin(UNITY_FLOAT delta, UNITY_FLOAT expected, UNITY_FLOAT actual) { UNITY_FLOAT diff; UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff); } +/*-----------------------------------------------*/ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected, UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* actual, const UNITY_UINT32 num_elements, @@ -840,6 +846,7 @@ static int UnityDoublesWithin(UNITY_DOUBLE delta, UNITY_DOUBLE expected, UNITY_D UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff); } +/*-----------------------------------------------*/ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expected, UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* actual, const UNITY_UINT32 num_elements, @@ -900,7 +907,6 @@ void UnityAssertDoublesWithin(const UNITY_DOUBLE delta, } /*-----------------------------------------------*/ - void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual, const char* msg, const UNITY_LINE_TYPE lineNumber, @@ -1259,6 +1265,7 @@ UNITY_INTERNAL_PTR UnityNumToPtr(const UNITY_INT num, const UNITY_UINT8 size) } #ifndef UNITY_EXCLUDE_FLOAT +/*-----------------------------------------------*/ UNITY_INTERNAL_PTR UnityFloatToPtr(const float num) { UnityQuickCompare.f = num; @@ -1267,6 +1274,7 @@ UNITY_INTERNAL_PTR UnityFloatToPtr(const float num) #endif #ifndef UNITY_EXCLUDE_DOUBLE +/*-----------------------------------------------*/ UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num) { UnityQuickCompare.d = num; @@ -1278,6 +1286,7 @@ UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num) * Control Functions *-----------------------------------------------*/ +/*-----------------------------------------------*/ void UnityFail(const char* msg, const UNITY_LINE_TYPE line) { RETURN_IF_FAIL_OR_IGNORE; @@ -1402,6 +1411,7 @@ char* UnityOptionIncludeNamed = NULL; char* UnityOptionExcludeNamed = NULL; int UnityVerbosity = 1; +/*-----------------------------------------------*/ int UnityParseOptions(int argc, char** argv) { UnityOptionIncludeNamed = NULL; @@ -1458,6 +1468,7 @@ int UnityParseOptions(int argc, char** argv) return 0; } +/*-----------------------------------------------*/ int IsStringInBiggerString(const char* longstring, const char* shortstring) { const char* lptr = longstring; @@ -1496,9 +1507,11 @@ int IsStringInBiggerString(const char* longstring, const char* shortstring) lptr = lnext; sptr = shortstring; } + return 0; } +/*-----------------------------------------------*/ int UnityStringArgumentMatches(const char* str) { int retval; @@ -1522,24 +1535,33 @@ int UnityStringArgumentMatches(const char* str) if ((ptr2[0] == ':') && (ptr2[1] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')) ptrf = &ptr2[1]; } while ((ptr2[0] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')); + while ((ptr2[0] != 0) && ((ptr2[0] == ':') || (ptr2[0] == '\'') || (ptr2[0] == '"') || (ptr2[0] == ','))) + { ptr2++; + } /* done if complete filename match */ retval = IsStringInBiggerString(Unity.TestFile, ptr1); if (retval == 1) + { return retval; + } /* done if testname match after filename partial match */ if ((retval == 2) && (ptrf != 0)) { if (IsStringInBiggerString(Unity.CurrentTestName, ptrf)) + { return 1; + } } /* done if complete testname match */ if (IsStringInBiggerString(Unity.CurrentTestName, ptr1) == 1) + { return 1; + } ptr1 = ptr2; } @@ -1548,6 +1570,7 @@ int UnityStringArgumentMatches(const char* str) return 0; } +/*-----------------------------------------------*/ int UnityTestMatches(void) { /* Check if this test name matches the included test pattern */ From 50ce8a880af6d27dabab5d3655bbd26a3a16d295 Mon Sep 17 00:00:00 2001 From: Kochise Date: Wed, 31 Oct 2018 11:41:44 +0100 Subject: [PATCH 40/44] Some cleanup --- src/unity.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/src/unity.c b/src/unity.c index 4efc47f..732db55 100644 --- a/src/unity.c +++ b/src/unity.c @@ -214,7 +214,9 @@ void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print) int nibble; char nibbles = nibbles_to_print; if ((unsigned)nibbles > (2 * sizeof(number))) + { nibbles = 2 * sizeof(number); + } while (nibbles > 0) { @@ -277,9 +279,18 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number) } /* handle zero, NaN, and +/- infinity */ - if (number == 0.0f) UnityPrint("0"); - else if (isnan(number)) UnityPrint("nan"); - else if (isinf(number)) UnityPrint("inf"); + if (number == 0.0f) + { + UnityPrint("0"); + } + else if (isnan(number)) + { + UnityPrint("nan"); + } + else if (isinf(number)) + { + UnityPrint("inf"); + } else { int exponent = 0; @@ -621,9 +632,15 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UnityPrintPointlessAndBail(); } - if (expected == actual) return; /* Both are NULL or same pointer */ + if (expected == actual) + { + return; /* Both are NULL or same pointer */ + } + if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) + { UNITY_FAIL_AND_BAIL; + } while ((elements > 0) && elements--) { @@ -734,9 +751,15 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected, UnityPrintPointlessAndBail(); } - if (expected == actual) return; /* Both are NULL or same pointer */ + if (expected == actual) + { + return; /* Both are NULL or same pointer */ + } + if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) + { UNITY_FAIL_AND_BAIL; + } while (elements--) { @@ -821,14 +844,18 @@ void UnityAssertFloatSpecial(const UNITY_FLOAT actual, UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); if (!should_be_trait) + { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); UnityPrint(UnityStrWas); #ifndef UNITY_EXCLUDE_FLOAT_PRINT UnityPrintFloat((UNITY_DOUBLE)actual); #else if (should_be_trait) + { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); #endif UnityAddMsgIfSpecified(msg); @@ -865,9 +892,15 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expecte UnityPrintPointlessAndBail(); } - if (expected == actual) return; /* Both are NULL or same pointer */ + if (expected == actual) + { + return; /* Both are NULL or same pointer */ + } + if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) + { UNITY_FAIL_AND_BAIL; + } while (elements--) { @@ -951,14 +984,18 @@ void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual, UnityTestResultsFailBegin(lineNumber); UnityPrint(UnityStrExpected); if (!should_be_trait) + { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); UnityPrint(UnityStrWas); #ifndef UNITY_EXCLUDE_FLOAT_PRINT UnityPrintFloat(actual); #else if (should_be_trait) + { UnityPrint(UnityStrNot); + } UnityPrint(trait_names[trait_index]); #endif UnityAddMsgIfSpecified(msg); @@ -981,16 +1018,24 @@ void UnityAssertNumbersWithin(const UNITY_UINT delta, if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) { if (actual > expected) + { Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); + } else + { Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta); + } } else { if ((UNITY_UINT)actual > (UNITY_UINT)expected) + { Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); + } else + { Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta); + } } if (Unity.CurrentTestFailed) @@ -1186,9 +1231,15 @@ void UnityAssertEqualMemory(UNITY_INTERNAL_PTR expected, UnityPrintPointlessAndBail(); } - if (expected == actual) return; /* Both are NULL or same pointer */ + if (expected == actual) + { + return; /* Both are NULL or same pointer */ + } + if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) + { UNITY_FAIL_AND_BAIL; + } while (elements--) { @@ -1428,9 +1479,13 @@ int UnityParseOptions(int argc, char** argv) case 'n': /* include tests with name including this string */ case 'f': /* an alias for -n */ if (argv[i][2] == '=') + { UnityOptionIncludeNamed = &argv[i][3]; + } else if (++i < argc) + { UnityOptionIncludeNamed = argv[i]; + } else { UnityPrint("ERROR: No Test String to Include Matches For"); @@ -1446,9 +1501,13 @@ int UnityParseOptions(int argc, char** argv) break; case 'x': /* exclude tests with name including this string */ if (argv[i][2] == '=') + { UnityOptionExcludeNamed = &argv[i][3]; + } else if (++i < argc) + { UnityOptionExcludeNamed = argv[i]; + } else { UnityPrint("ERROR: No Test String to Exclude Matches For"); @@ -1476,7 +1535,9 @@ int IsStringInBiggerString(const char* longstring, const char* shortstring) const char* lnext = lptr; if (*sptr == '*') + { return 1; + } while (*lptr) { @@ -1524,7 +1585,9 @@ int UnityStringArgumentMatches(const char* str) while (ptr1[0] != 0) { if ((ptr1[0] == '"') || (ptr1[0] == '\'')) + { ptr1++; + } /* look for the start of the next partial */ ptr2 = ptr1; @@ -1533,7 +1596,9 @@ int UnityStringArgumentMatches(const char* str) { ptr2++; if ((ptr2[0] == ':') && (ptr2[1] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')) + { ptrf = &ptr2[1]; + } } while ((ptr2[0] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')); while ((ptr2[0] != 0) && ((ptr2[0] == ':') || (ptr2[0] == '\'') || (ptr2[0] == '"') || (ptr2[0] == ','))) @@ -1580,14 +1645,19 @@ int UnityTestMatches(void) retval = UnityStringArgumentMatches(UnityOptionIncludeNamed); } else + { retval = 1; + } /* Check if this test name matches the excluded test pattern */ if (UnityOptionExcludeNamed) { if (UnityStringArgumentMatches(UnityOptionExcludeNamed)) + { retval = 0; + } } + return retval; } From 7dd21c333e56098b2e047a6fedd1c7ddfc4a88ab Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Fri, 2 Nov 2018 07:42:47 -0400 Subject: [PATCH 41/44] Fix unintended array overrun in example (#360. Thanks @quantum-leaps) --- examples/example_1/src/ProductionCode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/example_1/src/ProductionCode.c b/examples/example_1/src/ProductionCode.c index d039c3e..db128e5 100644 --- a/examples/example_1/src/ProductionCode.c +++ b/examples/example_1/src/ProductionCode.c @@ -4,14 +4,14 @@ int Counter = 0; int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; /* some obnoxious array to search that is 1-based indexing instead of 0. */ -/* This function is supposed to search through NumbersToFind and find a particular number. - * If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since - * NumbersToFind is indexed from 1. Unfortunately it's broken +/* This function is supposed to search through NumbersToFind and find a particular number. + * If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since + * NumbersToFind is indexed from 1. Unfortunately it's broken * (and should therefore be caught by our tests) */ int FindFunction_WhichIsBroken(int NumberToFind) { int i = 0; - while (i <= 8) /* Notice I should have been in braces */ + while (i < 8) /* Notice I should have been in braces */ i++; if (NumbersToFind[i] == NumberToFind) /* Yikes! I'm getting run after the loop finishes instead of during it! */ return i; From 100c73d37feef84c63530535793c739b30b23c0f Mon Sep 17 00:00:00 2001 From: Dan Yeaw Date: Tue, 13 Nov 2018 21:07:05 -0500 Subject: [PATCH 42/44] Move license for GitHub detection --- docs/license.txt => LICENSE.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/license.txt => LICENSE.txt (100%) diff --git a/docs/license.txt b/LICENSE.txt similarity index 100% rename from docs/license.txt rename to LICENSE.txt From 6b657c6f17ca45c240dd7ad74e8096dd17ab3ad1 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 28 Nov 2018 13:27:00 -0500 Subject: [PATCH 43/44] Fix (most) Rubocop warnings. --- auto/colour_prompt.rb | 4 +- auto/colour_reporter.rb | 2 +- auto/generate_module.rb | 8 ++-- auto/generate_test_runner.rb | 8 ++-- auto/parse_output.rb | 55 +++++++++++++-------------- auto/stylize_as_junit.rb | 12 ++---- auto/test_file_filter.rb | 4 +- auto/unity_test_summary.rb | 4 -- examples/example_3/rakefile.rb | 11 ++---- examples/example_3/rakefile_helper.rb | 8 ++-- extras/fixture/rakefile.rb | 14 +++---- test/.rubocop.yml | 2 +- test/rakefile | 7 ++-- test/rakefile_helper.rb | 8 ++-- 14 files changed, 64 insertions(+), 83 deletions(-) diff --git a/auto/colour_prompt.rb b/auto/colour_prompt.rb index 0f1dc4e..bf09d02 100644 --- a/auto/colour_prompt.rb +++ b/auto/colour_prompt.rb @@ -24,7 +24,7 @@ class ColourCommandLine return unless RUBY_PLATFORM =~ /(win|w)32$/ get_std_handle = Win32API.new('kernel32', 'GetStdHandle', ['L'], 'L') @set_console_txt_attrb = - Win32API.new('kernel32', 'SetConsoleTextAttribute', %w(L N), 'I') + Win32API.new('kernel32', 'SetConsoleTextAttribute', %w[L N], 'I') @hout = get_std_handle.call(-11) end @@ -107,7 +107,7 @@ class ColourCommandLine $stdout.print("#{change_to(colour)}#{str}\033[0m") if mode == :print end end -end # ColourCommandLine +end def colour_puts(role, str) ColourCommandLine.new.out_c(:puts, role, str) diff --git a/auto/colour_reporter.rb b/auto/colour_reporter.rb index bb1fbfc..1c3bc21 100644 --- a/auto/colour_reporter.rb +++ b/auto/colour_reporter.rb @@ -4,7 +4,7 @@ # [Released under MIT License. Please refer to license.txt for details] # ========================================== -require "#{File.expand_path(File.dirname(__FILE__))}/colour_prompt" +require_relative 'colour_prompt' $colour_output = true diff --git a/auto/generate_module.rb b/auto/generate_module.rb index 13b4cc7..fb8c7ac 100644 --- a/auto/generate_module.rb +++ b/auto/generate_module.rb @@ -45,8 +45,6 @@ TEMPLATE_INC ||= '#ifndef _%3$s_H class UnityModuleGenerator ############################ def initialize(options = nil) - here = File.expand_path(File.dirname(__FILE__)) + '/' - @options = UnityModuleGenerator.default_options case options when NilClass then @options @@ -56,9 +54,9 @@ class UnityModuleGenerator end # Create default file paths if none were provided - @options[:path_src] = here + '../src/' if @options[:path_src].nil? - @options[:path_inc] = @options[:path_src] if @options[:path_inc].nil? - @options[:path_tst] = here + '../test/' if @options[:path_tst].nil? + @options[:path_src] = "#{__dir__}/../src/" if @options[:path_src].nil? + @options[:path_inc] = @options[:path_src] if @options[:path_inc].nil? + @options[:path_tst] = "#{__dir__}/../test/" if @options[:path_tst].nil? @options[:path_src] += '/' unless @options[:path_src][-1] == 47 @options[:path_inc] += '/' unless @options[:path_inc][-1] == 47 @options[:path_tst] += '/' unless @options[:path_tst][-1] == 47 diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index 2f14966..377db6f 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -4,8 +4,6 @@ # [Released under MIT License. Please refer to license.txt for details] # ========================================== -File.expand_path(File.join(File.dirname(__FILE__), 'colour_prompt')) - class UnityTestRunnerGenerator def initialize(options = nil) @options = UnityTestRunnerGenerator.default_options @@ -15,7 +13,7 @@ class UnityTestRunnerGenerator when Hash then @options.merge!(options) else raise 'If you specify arguments, it should be a filename or a hash of options' end - require "#{File.expand_path(File.dirname(__FILE__))}/type_sanitizer" + require_relative 'type_sanitizer' end def self.default_options @@ -165,7 +163,7 @@ class UnityTestRunnerGenerator output.puts('#include "cmock.h"') unless mocks.empty? output.puts('#ifndef UNITY_EXCLUDE_SETJMP_H') output.puts('#include ') - output.puts("#endif") + output.puts('#endif') output.puts('#include ') if @options[:defines] && !@options[:defines].empty? @options[:defines].each { |d| output.puts("#define #{d}") } @@ -379,7 +377,7 @@ class UnityTestRunnerGenerator end output.puts output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty? - output.puts(" return suite_teardown(UnityEnd());") + output.puts(' return suite_teardown(UnityEnd());') output.puts('}') end diff --git a/auto/parse_output.rb b/auto/parse_output.rb index f04508f..fa07b7d 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -210,7 +210,7 @@ class ParseOutput # Adjusts the os specific members according to the current path style # (Windows or Unix based) - def set_os_specifics(line) + def detect_os_specifics(line) if line.include? '\\' # Windows X:\Y\Z @class_name_idx = 1 @@ -254,43 +254,42 @@ class ParseOutput # TEST() PASS # # Note: Where path is different on Unix vs Windows devices (Windows leads with a drive letter)! - set_os_specifics(line) + detect_os_specifics(line) line_array = line.split(':') # If we were able to split the line then we can look to see if any of our target words # were found. Case is important. - if (line_array.size >= 4) || (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') + next unless (line_array.size >= 4) || (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') - # check if the output is fixture output (with verbose flag "-v") - if (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') - line_array = prepare_fixture_line(line) - if line.include? ' PASS' - test_passed_unity_fixture(line_array) - @test_passed += 1 - elsif line.include? 'FAIL' - test_failed_unity_fixture(line_array) - @test_failed += 1 - elsif line.include? 'IGNORE' - test_ignored_unity_fixture(line_array) - @test_ignored += 1 - end - # normal output / fixture output (without verbose "-v") - elsif line.include? ':PASS' - test_passed(line_array) + # check if the output is fixture output (with verbose flag "-v") + if (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') + line_array = prepare_fixture_line(line) + if line.include? ' PASS' + test_passed_unity_fixture(line_array) @test_passed += 1 - elsif line.include? ':FAIL' - test_failed(line_array) + elsif line.include? 'FAIL' + test_failed_unity_fixture(line_array) @test_failed += 1 - elsif line.include? ':IGNORE:' - test_ignored(line_array) - @test_ignored += 1 - elsif line.include? ':IGNORE' - line_array.push('No reason given') - test_ignored(line_array) + elsif line.include? 'IGNORE' + test_ignored_unity_fixture(line_array) @test_ignored += 1 end - @total_tests = @test_passed + @test_failed + @test_ignored + # normal output / fixture output (without verbose "-v") + elsif line.include? ':PASS' + test_passed(line_array) + @test_passed += 1 + elsif line.include? ':FAIL' + test_failed(line_array) + @test_failed += 1 + elsif line.include? ':IGNORE:' + test_ignored(line_array) + @test_ignored += 1 + elsif line.include? ':IGNORE' + line_array.push('No reason given') + test_ignored(line_array) + @test_ignored += 1 end + @total_tests = @test_passed + @test_failed + @test_ignored end puts '' puts '=================== SUMMARY =====================' diff --git a/auto/stylize_as_junit.rb b/auto/stylize_as_junit.rb index b3d8f40..a53f85f 100755 --- a/auto/stylize_as_junit.rb +++ b/auto/stylize_as_junit.rb @@ -61,8 +61,8 @@ class ArgvParser opts.parse!(args) options - end # parse() -end # class OptparseExample + end +end class UnityToJUnit include FileUtils::Verbose @@ -155,10 +155,6 @@ class UnityToJUnit [Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i] end - def here - File.expand_path(File.dirname(__FILE__)) - end - private def results_structure @@ -221,9 +217,9 @@ class UnityToJUnit def write_suites_footer(stream) stream.puts '' end -end # UnityToJUnit +end -if __FILE__ == $0 +if $0 == __FILE__ # parse out the command options options = ArgvParser.parse(ARGV) diff --git a/auto/test_file_filter.rb b/auto/test_file_filter.rb index aad28e3..5c3a79f 100644 --- a/auto/test_file_filter.rb +++ b/auto/test_file_filter.rb @@ -11,8 +11,8 @@ module RakefileHelpers def initialize(all_files = false) @all_files = all_files - return false unless @all_files - return false unless File.exist?('test_file_filter.yml') + return unless @all_files + return unless File.exist?('test_file_filter.yml') filters = YAML.load_file('test_file_filter.yml') @all_files = filters[:all_files] diff --git a/auto/unity_test_summary.rb b/auto/unity_test_summary.rb index b37dc5f..810fdbd 100644 --- a/auto/unity_test_summary.rb +++ b/auto/unity_test_summary.rb @@ -101,10 +101,6 @@ class UnityTestSummary raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ } [Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i] end - - def here - File.expand_path(File.dirname(__FILE__)) - end end if $0 == __FILE__ diff --git a/examples/example_3/rakefile.rb b/examples/example_3/rakefile.rb index bf9f42b..d014929 100644 --- a/examples/example_3/rakefile.rb +++ b/examples/example_3/rakefile.rb @@ -1,12 +1,9 @@ -HERE = File.expand_path(File.dirname(__FILE__)) + '/' -UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/../..' - require 'rake' require 'rake/clean' -require HERE + 'rakefile_helper' +require_relative 'rakefile_helper' TEMP_DIRS = [ - File.join(HERE, 'build') + File.join(__dir__, 'build') ].freeze TEMP_DIRS.each do |dir| @@ -32,8 +29,8 @@ task :summary do end desc 'Build and test Unity' -task all: %i(clean unit summary) -task default: %i(clobber all) +task all: %i[clean unit summary] +task default: %i[clobber all] task ci: [:default] task cruise: [:default] diff --git a/examples/example_3/rakefile_helper.rb b/examples/example_3/rakefile_helper.rb index a186cf0..f1f51d4 100644 --- a/examples/example_3/rakefile_helper.rb +++ b/examples/example_3/rakefile_helper.rb @@ -1,8 +1,8 @@ require 'yaml' require 'fileutils' -require UNITY_ROOT + '/auto/unity_test_summary' -require UNITY_ROOT + '/auto/generate_test_runner' -require UNITY_ROOT + '/auto/colour_reporter' +require_relative '../../auto/unity_test_summary' +require_relative '../../auto/generate_test_runner' +require_relative '../../auto/colour_reporter' module RakefileHelpers C_EXTENSION = '.c'.freeze @@ -149,7 +149,7 @@ module RakefileHelpers def report_summary summary = UnityTestSummary.new - summary.root = HERE + summary.root = __dir__ results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob.tr!('\\', '/') results = Dir[results_glob] diff --git a/extras/fixture/rakefile.rb b/extras/fixture/rakefile.rb index 7603e57..8b5319c 100644 --- a/extras/fixture/rakefile.rb +++ b/extras/fixture/rakefile.rb @@ -4,15 +4,13 @@ # [Released under MIT License. Please refer to license.txt for details] # ========================================== -HERE = File.expand_path(File.dirname(__FILE__)) + '/' - require 'rake' require 'rake/clean' require 'rake/testtask' -require HERE + 'rakefile_helper' +require_relative 'rakefile_helper' TEMP_DIRS = [ - File.join(HERE, 'build') + File.join(__dir__, 'build') ].freeze TEMP_DIRS.each do |dir| @@ -33,10 +31,10 @@ task unit: [:prepare_for_tests] do end desc 'Build and test Unity Framework' -task all: %i(clean unit) -task default: %i(clobber all) -task ci: %i(no_color default) -task cruise: %i(no_color default) +task all: %i[clean unit] +task default: %i[clobber all] +task ci: %i[no_color default] +task cruise: %i[no_color default] desc 'Load configuration' task :config, :config_file do |_t, args| diff --git a/test/.rubocop.yml b/test/.rubocop.yml index c074ca9..3bfe31a 100644 --- a/test/.rubocop.yml +++ b/test/.rubocop.yml @@ -18,7 +18,7 @@ Style/HashSyntax: EnforcedStyle: no_mixed_keys # This is disabled because it seems to get confused over nested hashes -Style/AlignHash: +Layout/AlignHash: Enabled: false EnforcedHashRocketStyle: table EnforcedColonStyle: table diff --git a/test/rakefile b/test/rakefile index 4a2f3d2..770fead 100644 --- a/test/rakefile +++ b/test/rakefile @@ -4,17 +4,16 @@ # [Released under MIT License. Please refer to license.txt for details] # ========================================== -UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/' $verbose = false require 'rake' require 'rake/clean' -require UNITY_ROOT + 'rakefile_helper' +require_relative 'rakefile_helper' require 'rspec/core/rake_task' TEMP_DIRS = [ - File.join(UNITY_ROOT, 'build'), - File.join(UNITY_ROOT, 'sandbox') + File.join(__dir__, 'build'), + File.join(__dir__, 'sandbox') ] TEMP_DIRS.each do |dir| diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index 1fd60c5..d4335ec 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -6,9 +6,9 @@ require 'yaml' require 'fileutils' -require UNITY_ROOT + '../auto/unity_test_summary' -require UNITY_ROOT + '../auto/generate_test_runner' -require UNITY_ROOT + '../auto/colour_reporter' +require_relative '../auto/unity_test_summary' +require_relative '../auto/generate_test_runner' +require_relative '../auto/colour_reporter' module RakefileHelpers C_EXTENSION = '.c'.freeze @@ -179,7 +179,7 @@ module RakefileHelpers def report_summary summary = UnityTestSummary.new - summary.root = UNITY_ROOT + summary.root = __dir__ results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob.tr!('\\', '/') results = Dir[results_glob] From 5cd1c33b0e99bfaa1c1c1a2c950854286e6c5eb3 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 28 Nov 2018 13:36:27 -0500 Subject: [PATCH 44/44] Fix uninitialized constant --- extras/fixture/rakefile_helper.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extras/fixture/rakefile_helper.rb b/extras/fixture/rakefile_helper.rb index c45b239..71e752b 100644 --- a/extras/fixture/rakefile_helper.rb +++ b/extras/fixture/rakefile_helper.rb @@ -6,9 +6,9 @@ require 'yaml' require 'fileutils' -require HERE + '../../auto/unity_test_summary' -require HERE + '../../auto/generate_test_runner' -require HERE + '../../auto/colour_reporter' +require_relative '../../auto/unity_test_summary' +require_relative '../../auto/generate_test_runner' +require_relative '../../auto/colour_reporter' module RakefileHelpers C_EXTENSION = '.c'.freeze @@ -16,7 +16,7 @@ module RakefileHelpers def load_configuration(config_file) return if $configured - $cfg_file = HERE + "../../test/targets/#{config_file}" unless config_file =~ /[\\|\/]/ + $cfg_file = "#{__dir__}/../../test/targets/#{config_file}" unless config_file =~ /[\\|\/]/ $cfg = YAML.load(File.read($cfg_file)) $colour_output = false unless $cfg['colour'] $configured = true if config_file != DEFAULT_CONFIG_FILE @@ -128,7 +128,7 @@ module RakefileHelpers def report_summary summary = UnityTestSummary.new - summary.root = HERE + summary.root = __dir__ results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob.tr!('\\', '/') results = Dir[results_glob] @@ -145,9 +145,9 @@ module RakefileHelpers $cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil? # Get a list of all source files needed - src_files = Dir[HERE + 'src/*.c'] - src_files += Dir[HERE + 'test/*.c'] - src_files += Dir[HERE + 'test/main/*.c'] + src_files = Dir["#{__dir__}/src/*.c"] + src_files += Dir["#{__dir__}/test/*.c"] + src_files += Dir["#{__dir__}/test/main/*.c"] src_files << '../../src/unity.c' # Build object files