From 5fc2b092d3346eef4bfc6215639d6890f094f49a Mon Sep 17 00:00:00 2001 From: jsalling Date: Mon, 23 Nov 2015 14:21:43 -0600 Subject: [PATCH 1/3] Move UNITY_PRINT_EOL to internals to allow access to it. Unity fixture needs access to this macro to be consistent. Add #ifndef wrapper for easier redefinition on systems that use "\r\n". --- src/unity.c | 1 - src/unity_internals.h | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/unity.c b/src/unity.c index 341fa0e..5e4018a 100644 --- a/src/unity.c +++ b/src/unity.c @@ -11,7 +11,6 @@ #define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; longjmp(Unity.AbortFrame, 1); } /// return prematurely if we are already in failure or ignore state #define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} } -#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); } struct _Unity Unity; diff --git a/src/unity_internals.h b/src/unity_internals.h index ad815f3..95e1a74 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -291,6 +291,10 @@ typedef UNITY_DOUBLE_TYPE _UD; extern int UNITY_OUTPUT_CHAR(int); #endif +#ifndef UNITY_PRINT_EOL +#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); } +#endif + #ifndef UNITY_OUTPUT_START #define UNITY_OUTPUT_START() #endif From d4353166d217270d1fde099cc25914650ab3ce21 Mon Sep 17 00:00:00 2001 From: jsalling Date: Mon, 23 Nov 2015 17:09:30 -0600 Subject: [PATCH 2/3] Replace all hard-coded '\n' with UNITY_PRINT_EOL macro in fixture Delete the { ;} braces and semicolon from UNITY_PRINT_EOL to give it expected behavior: 1) requires a semicolon 2) works in one-liner if-else statements If you need "\r\n" for EOL, define as the following to get the same behavior: do{UNITY_OUTPUT_CHAR('\r'); UNITY_OUTPUT_CHAR('\n');}while(0) --- extras/fixture/src/unity_fixture.c | 10 +++++----- src/unity_internals.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index 7cafaa3..b6f8a65 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -28,7 +28,7 @@ static void announceTestRun(unsigned int runNumber) UnityPrintNumber(runNumber+1); UnityPrint(" of "); UnityPrintNumber(UnityFixture.RepeatCount); - UNITY_OUTPUT_CHAR('\n'); + UNITY_PRINT_EOL; } int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)) @@ -43,7 +43,7 @@ int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)) UnityBegin(argv[0]); announceTestRun(r); runAllTests(); - UNITY_OUTPUT_CHAR('\n'); + UNITY_PRINT_EOL; UnityEnd(); } @@ -396,7 +396,7 @@ void UnityConcludeFixtureTest(void) { //if (UnityFixture.Verbose) //{ - UNITY_OUTPUT_CHAR('\n'); + UNITY_PRINT_EOL; //} Unity.TestIgnores++; } @@ -405,13 +405,13 @@ void UnityConcludeFixtureTest(void) if (UnityFixture.Verbose) { UnityPrint(" PASS"); - UNITY_OUTPUT_CHAR('\n'); + UNITY_PRINT_EOL; } } else if (Unity.CurrentTestFailed) { Unity.TestFailures++; - UNITY_OUTPUT_CHAR('\n'); + UNITY_PRINT_EOL; } Unity.CurrentTestFailed = 0; diff --git a/src/unity_internals.h b/src/unity_internals.h index 95e1a74..231799a 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -292,7 +292,7 @@ extern int UNITY_OUTPUT_CHAR(int); #endif #ifndef UNITY_PRINT_EOL -#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); } +#define UNITY_PRINT_EOL UNITY_OUTPUT_CHAR('\n') #endif #ifndef UNITY_OUTPUT_START From de7cf8335ece0e6c54ceb1979970f47a032e1d22 Mon Sep 17 00:00:00 2001 From: jsalling Date: Mon, 23 Nov 2015 21:03:46 -0600 Subject: [PATCH 3/3] Transform plain macro into a function macro, UNITY_PRINT_EOL() This helps clarity and is more obvious, it looks like a print function --- extras/fixture/src/unity_fixture.c | 10 +++++----- src/unity.c | 10 +++++----- src/unity_internals.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/extras/fixture/src/unity_fixture.c b/extras/fixture/src/unity_fixture.c index b6f8a65..45a2c02 100644 --- a/extras/fixture/src/unity_fixture.c +++ b/extras/fixture/src/unity_fixture.c @@ -28,7 +28,7 @@ static void announceTestRun(unsigned int runNumber) UnityPrintNumber(runNumber+1); UnityPrint(" of "); UnityPrintNumber(UnityFixture.RepeatCount); - UNITY_PRINT_EOL; + UNITY_PRINT_EOL(); } int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)) @@ -43,7 +43,7 @@ int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)) UnityBegin(argv[0]); announceTestRun(r); runAllTests(); - UNITY_PRINT_EOL; + UNITY_PRINT_EOL(); UnityEnd(); } @@ -396,7 +396,7 @@ void UnityConcludeFixtureTest(void) { //if (UnityFixture.Verbose) //{ - UNITY_PRINT_EOL; + UNITY_PRINT_EOL(); //} Unity.TestIgnores++; } @@ -405,13 +405,13 @@ void UnityConcludeFixtureTest(void) if (UnityFixture.Verbose) { UnityPrint(" PASS"); - UNITY_PRINT_EOL; + UNITY_PRINT_EOL(); } } else if (Unity.CurrentTestFailed) { Unity.TestFailures++; - UNITY_PRINT_EOL; + UNITY_PRINT_EOL(); } Unity.CurrentTestFailed = 0; diff --git a/src/unity.c b/src/unity.c index 5e4018a..f49b191 100644 --- a/src/unity.c +++ b/src/unity.c @@ -355,7 +355,7 @@ void UnityConcludeTest(void) Unity.CurrentTestFailed = 0; Unity.CurrentTestIgnored = 0; - UNITY_PRINT_EOL; + UNITY_PRINT_EOL(); } //----------------------------------------------- @@ -1272,16 +1272,16 @@ void UnityBegin(const char* filename) //----------------------------------------------- int UnityEnd(void) { - UNITY_PRINT_EOL; + UNITY_PRINT_EOL(); UnityPrint(UnityStrBreaker); - UNITY_PRINT_EOL; + UNITY_PRINT_EOL(); UnityPrintNumber((_U_SINT)(Unity.NumberOfTests)); UnityPrint(UnityStrResultsTests); UnityPrintNumber((_U_SINT)(Unity.TestFailures)); UnityPrint(UnityStrResultsFailures); UnityPrintNumber((_U_SINT)(Unity.TestIgnores)); UnityPrint(UnityStrResultsIgnored); - UNITY_PRINT_EOL; + UNITY_PRINT_EOL(); if (Unity.TestFailures == 0U) { UnityPrintOk(); @@ -1290,7 +1290,7 @@ int UnityEnd(void) { UnityPrintFail(); } - UNITY_PRINT_EOL; + UNITY_PRINT_EOL(); UNITY_OUTPUT_COMPLETE(); return (int)(Unity.TestFailures); } diff --git a/src/unity_internals.h b/src/unity_internals.h index 231799a..26d18e3 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -292,7 +292,7 @@ extern int UNITY_OUTPUT_CHAR(int); #endif #ifndef UNITY_PRINT_EOL -#define UNITY_PRINT_EOL UNITY_OUTPUT_CHAR('\n') +#define UNITY_PRINT_EOL() UNITY_OUTPUT_CHAR('\n') #endif #ifndef UNITY_OUTPUT_START