11#include <avr/pgmspace.h>
18#ifdef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION
19void UNITY_OUTPUT_CHAR(
int);
23#define UNITY_FAIL_AND_BAIL \
25 Unity.CurrentTestFailed = 1; \
26 UNITY_OUTPUT_FLUSH(); \
29#define UNITY_IGNORE_AND_BAIL \
31 Unity.CurrentTestIgnored = 1; \
32 UNITY_OUTPUT_FLUSH(); \
35#define RETURN_IF_FAIL_OR_IGNORE \
36 if (Unity.CurrentTestFailed || Unity.CurrentTestIgnored) \
41#ifdef UNITY_OUTPUT_COLOR
42const char PROGMEM UnityStrOk[] =
"\033[42mOK\033[00m";
43const char PROGMEM UnityStrPass[] =
"\033[42mPASS\033[00m";
44const char PROGMEM UnityStrFail[] =
"\033[41mFAIL\033[00m";
45const char PROGMEM UnityStrIgnore[] =
"\033[43mIGNORE\033[00m";
47const char PROGMEM UnityStrOk[] =
"OK";
48const char PROGMEM UnityStrPass[] =
"PASS";
49const char PROGMEM UnityStrFail[] =
"FAIL";
50const char PROGMEM UnityStrIgnore[] =
"IGNORE";
52static const char PROGMEM UnityStrNull[] =
"NULL";
53static const char PROGMEM UnityStrSpacer[] =
". ";
54static const char PROGMEM UnityStrExpected[] =
" Expected ";
55static const char PROGMEM UnityStrWas[] =
" Was ";
56static const char PROGMEM UnityStrGt[] =
" to be greater than ";
57static const char PROGMEM UnityStrLt[] =
" to be less than ";
58static const char PROGMEM UnityStrOrEqual[] =
"or equal to ";
59static const char PROGMEM UnityStrNotEqual[] =
" to be not equal to ";
60static const char PROGMEM UnityStrElement[] =
" Element ";
61static const char PROGMEM UnityStrByte[] =
" Byte ";
62static const char PROGMEM UnityStrMemory[] =
" Memory Mismatch.";
63static const char PROGMEM UnityStrDelta[] =
" Values Not Within Delta ";
64static const char PROGMEM UnityStrPointless[] =
65 " You Asked Me To Compare Nothing, Which Was Pointless.";
66static const char PROGMEM UnityStrNullPointerForExpected[] =
67 " Expected pointer to be NULL";
68static const char PROGMEM UnityStrNullPointerForActual[] =
69 " Actual pointer was NULL";
70#ifndef UNITY_EXCLUDE_FLOAT
71static const char PROGMEM UnityStrNot[] =
"Not ";
72static const char PROGMEM UnityStrInf[] =
"Infinity";
73static const char PROGMEM UnityStrNegInf[] =
"Negative Infinity";
74static const char PROGMEM UnityStrNaN[] =
"NaN";
75static const char PROGMEM UnityStrDet[] =
"Determinate";
76static const char PROGMEM UnityStrInvalidFloatTrait[] =
"Invalid Float Trait";
78const char PROGMEM UnityStrErrShorthand[] =
"Unity Shorthand Support Disabled";
79const char PROGMEM UnityStrErrFloat[] =
"Unity Floating Point Disabled";
80const char PROGMEM UnityStrErrDouble[] =
"Unity Double Precision Disabled";
81const char PROGMEM UnityStrErr64[] =
"Unity 64-bit Support Disabled";
82static const char PROGMEM UnityStrBreaker[] =
"-----------------------";
83static const char PROGMEM UnityStrResultsTests[] =
" Tests ";
84static const char PROGMEM UnityStrResultsFailures[] =
" Failures ";
85static const char PROGMEM UnityStrResultsIgnored[] =
" Ignored ";
86static const char PROGMEM UnityStrDetail1Name[] = UNITY_DETAIL1_NAME
" ";
87static const char PROGMEM UnityStrDetail2Name[] =
" " UNITY_DETAIL2_NAME
" ";
95static void UnityPrintChar(
const char *pch) {
97 if ((*pch <= 126) && (*pch >= 32)) {
98 UNITY_OUTPUT_CHAR(*pch);
101 else if (*pch == 13) {
102 UNITY_OUTPUT_CHAR(
'\\');
103 UNITY_OUTPUT_CHAR(
'r');
106 else if (*pch == 10) {
107 UNITY_OUTPUT_CHAR(
'\\');
108 UNITY_OUTPUT_CHAR(
'n');
112 UNITY_OUTPUT_CHAR(
'\\');
113 UNITY_OUTPUT_CHAR(
'x');
114 UnityPrintNumberHex((UNITY_UINT)*pch, 2);
120#ifdef UNITY_OUTPUT_COLOR
121static UNITY_UINT UnityPrintAnsiEscapeString(
const char *
string) {
122 const char *pch = string;
123 UNITY_UINT count = 0;
125 while (*pch && (*pch !=
'm')) {
126 UNITY_OUTPUT_CHAR(*pch);
130 UNITY_OUTPUT_CHAR(
'm');
138void UnityPrint(
const char *
string) {
139 const char *pch = string;
143#ifdef UNITY_OUTPUT_COLOR
145 if ((*pch == 27) && (*(pch + 1) ==
'[')) {
146 pch += UnityPrintAnsiEscapeString(pch);
156void UnityPrintLen(
const char *
string,
const UNITY_UINT32 length) {
157 const char *pch = string;
160 while (*pch && ((UNITY_UINT32)(pch -
string) < length)) {
162 if ((*pch <= 126) && (*pch >= 32)) {
163 UNITY_OUTPUT_CHAR(*pch);
166 else if (*pch == 13) {
167 UNITY_OUTPUT_CHAR(
'\\');
168 UNITY_OUTPUT_CHAR(
'r');
171 else if (*pch == 10) {
172 UNITY_OUTPUT_CHAR(
'\\');
173 UNITY_OUTPUT_CHAR(
'n');
177 UNITY_OUTPUT_CHAR(
'\\');
178 UNITY_OUTPUT_CHAR(
'x');
179 UnityPrintNumberHex((UNITY_UINT)*pch, 2);
187void UnityPrintNumberByStyle(
const UNITY_INT number,
188 const UNITY_DISPLAY_STYLE_T style) {
189 if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) {
190 if (style == UNITY_DISPLAY_STYLE_CHAR) {
192 UNITY_OUTPUT_CHAR(
'\'');
193 if ((number <= 126) && (number >= 32)) {
194 UNITY_OUTPUT_CHAR((
int)number);
197 else if (number == 13) {
198 UNITY_OUTPUT_CHAR(
'\\');
199 UNITY_OUTPUT_CHAR(
'r');
202 else if (number == 10) {
203 UNITY_OUTPUT_CHAR(
'\\');
204 UNITY_OUTPUT_CHAR(
'n');
208 UNITY_OUTPUT_CHAR(
'\\');
209 UNITY_OUTPUT_CHAR(
'x');
210 UnityPrintNumberHex((UNITY_UINT)number, 2);
212 UNITY_OUTPUT_CHAR(
'\'');
214 UnityPrintNumber(number);
216 }
else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT) {
217 UnityPrintNumberUnsigned((UNITY_UINT)number);
219 UNITY_OUTPUT_CHAR(
'0');
220 UNITY_OUTPUT_CHAR(
'x');
221 UnityPrintNumberHex((UNITY_UINT)number, (
char)((style & 0xF) * 2));
226void UnityPrintNumber(
const UNITY_INT number_to_print) {
227 UNITY_UINT number = (UNITY_UINT)number_to_print;
229 if (number_to_print < 0) {
231 UNITY_OUTPUT_CHAR(
'-');
232 number = (~number) + 1;
234 UnityPrintNumberUnsigned(number);
239void UnityPrintNumberUnsigned(
const UNITY_UINT number) {
240 UNITY_UINT divisor = 1;
243 while (number / divisor > 9) {
249 UNITY_OUTPUT_CHAR((
char)(
'0' + (number / divisor % 10)));
251 }
while (divisor > 0);
255void UnityPrintNumberHex(
const UNITY_UINT number,
const char nibbles_to_print) {
257 char nibbles = nibbles_to_print;
259 if ((
unsigned)nibbles > UNITY_MAX_NIBBLES) {
260 nibbles = UNITY_MAX_NIBBLES;
263 while (nibbles > 0) {
265 nibble = (int)(number >> (nibbles * 4)) & 0x0F;
267 UNITY_OUTPUT_CHAR((
char)(
'0' + nibble));
269 UNITY_OUTPUT_CHAR((
char)(
'A' - 10 + nibble));
275void UnityPrintMask(
const UNITY_UINT mask,
const UNITY_UINT number) {
276 UNITY_UINT current_bit = (UNITY_UINT)1 << (UNITY_INT_WIDTH - 1);
279 for (i = 0; i < UNITY_INT_WIDTH; i++) {
280 if (current_bit & mask) {
281 if (current_bit & number) {
282 UNITY_OUTPUT_CHAR(
'1');
284 UNITY_OUTPUT_CHAR(
'0');
287 UNITY_OUTPUT_CHAR(
'X');
289 current_bit = current_bit >> 1;
294#ifndef UNITY_EXCLUDE_FLOAT_PRINT
302void UnityPrintFloat(
const UNITY_DOUBLE input_number) {
303#ifdef UNITY_INCLUDE_DOUBLE
304 static const int sig_digits = 9;
305 static const UNITY_INT32 min_scaled = 100000000;
306 static const UNITY_INT32 max_scaled = 1000000000;
308 static const int sig_digits = 7;
309 static const UNITY_INT32 min_scaled = 1000000;
310 static const UNITY_INT32 max_scaled = 10000000;
313 UNITY_DOUBLE number = input_number;
317 UNITY_OUTPUT_CHAR(
'-');
322#pragma GCC diagnostic ignored "-Wfloat-equal"
323#pragma GCC diagnostic push
324 if (number == 0.0f) {
326 }
else if (isnan(number)) {
328 }
else if (isinf(number)) {
331 UNITY_INT32 n_int = 0, n;
333 int decimals, digits;
344 UNITY_DOUBLE factor = 1.0f;
346 while (number < (UNITY_DOUBLE)max_scaled / 1e10f) {
350 while (number * factor < (UNITY_DOUBLE)min_scaled) {
356 }
else if (number > (UNITY_DOUBLE)max_scaled) {
357 UNITY_DOUBLE divisor = 1.0f;
359 while (number > (UNITY_DOUBLE)min_scaled * 1e10f) {
363 while (number / divisor > (UNITY_DOUBLE)max_scaled) {
375 UNITY_DOUBLE factor = 1.0f;
376 n_int = (UNITY_INT32)number;
377 number -= (UNITY_DOUBLE)n_int;
379 while (n_int < min_scaled) {
389 n = ((UNITY_INT32)(number + number) + 1) / 2;
391#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO
393 if ((n & 1) && (((UNITY_DOUBLE)n - number) == 0.5f))
399 if (n >= max_scaled) {
405 decimals = ((exponent <= 0) && (exponent >= -(sig_digits + 3)))
408 exponent += decimals;
411 while ((decimals > 0) && ((n % 10) == 0)) {
418 while ((n != 0) || (digits < (decimals + 1))) {
419 buf[digits++] = (char)(
'0' + n % 10);
423 if (digits == decimals) {
424 UNITY_OUTPUT_CHAR(
'.');
426 UNITY_OUTPUT_CHAR(buf[--digits]);
431 UNITY_OUTPUT_CHAR(
'e');
434 UNITY_OUTPUT_CHAR(
'-');
435 exponent = -exponent;
437 UNITY_OUTPUT_CHAR(
'+');
441 while ((exponent != 0) || (digits < 2)) {
442 buf[digits++] = (char)(
'0' + exponent % 10);
446 UNITY_OUTPUT_CHAR(buf[--digits]);
450#pragma GCC diagnostic pop
455static void UnityTestResultsBegin(
const char *file,
456 const UNITY_LINE_TYPE line) {
457#ifdef UNITY_OUTPUT_FOR_ECLIPSE
458 UNITY_OUTPUT_CHAR(
'(');
460 UNITY_OUTPUT_CHAR(
':');
461 UnityPrintNumber((UNITY_INT)line);
462 UNITY_OUTPUT_CHAR(
')');
463 UNITY_OUTPUT_CHAR(
' ');
464 UnityPrint(Unity.CurrentTestName);
465 UNITY_OUTPUT_CHAR(
':');
467#ifdef UNITY_OUTPUT_FOR_IAR_WORKBENCH
468 UnityPrint(
"<SRCREF line=");
469 UnityPrintNumber((UNITY_INT)line);
470 UnityPrint(
" file=\"");
472 UNITY_OUTPUT_CHAR(
'"');
473 UNITY_OUTPUT_CHAR(
'>');
474 UnityPrint(Unity.CurrentTestName);
475 UnityPrint(
"</SRCREF> ");
477#ifdef UNITY_OUTPUT_FOR_QT_CREATOR
478 UnityPrint(
"file://");
480 UNITY_OUTPUT_CHAR(
':');
481 UnityPrintNumber((UNITY_INT)line);
482 UNITY_OUTPUT_CHAR(
' ');
483 UnityPrint(Unity.CurrentTestName);
484 UNITY_OUTPUT_CHAR(
':');
487 UNITY_OUTPUT_CHAR(
':');
488 UnityPrintNumber((UNITY_INT)line);
489 UNITY_OUTPUT_CHAR(
':');
490 UnityPrint(Unity.CurrentTestName);
491 UNITY_OUTPUT_CHAR(
':');
498static void UnityTestResultsFailBegin(
const UNITY_LINE_TYPE line) {
499 UnityTestResultsBegin(Unity.TestFile, line);
500 UnityPrint(UnityStrFail);
501 UNITY_OUTPUT_CHAR(
':');
505void UnityConcludeTest(
void) {
506 if (Unity.CurrentTestIgnored) {
508 }
else if (!Unity.CurrentTestFailed) {
509 UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
510 UnityPrint(UnityStrPass);
512 Unity.TestFailures++;
515 Unity.CurrentTestFailed = 0;
516 Unity.CurrentTestIgnored = 0;
517 UNITY_PRINT_EXEC_TIME();
523static void UnityAddMsgIfSpecified(
const char *msg) {
525 UnityPrint(UnityStrSpacer);
527#ifdef UNITY_PRINT_TEST_CONTEXT
528 UNITY_PRINT_TEST_CONTEXT();
530#ifndef UNITY_EXCLUDE_DETAILS
531 if (Unity.CurrentDetail1) {
532 UnityPrint(UnityStrDetail1Name);
533 UnityPrint(Unity.CurrentDetail1);
534 if (Unity.CurrentDetail2) {
535 UnityPrint(UnityStrDetail2Name);
536 UnityPrint(Unity.CurrentDetail2);
538 UnityPrint(UnityStrSpacer);
546static void UnityPrintExpectedAndActualStrings(
const char *expected,
547 const char *actual) {
548 UnityPrint(UnityStrExpected);
549 if (expected != NULL) {
550 UNITY_OUTPUT_CHAR(
'\'');
551 UnityPrint(expected);
552 UNITY_OUTPUT_CHAR(
'\'');
554 UnityPrint(UnityStrNull);
556 UnityPrint(UnityStrWas);
557 if (actual != NULL) {
558 UNITY_OUTPUT_CHAR(
'\'');
560 UNITY_OUTPUT_CHAR(
'\'');
562 UnityPrint(UnityStrNull);
567static void UnityPrintExpectedAndActualStringsLen(
const char *expected,
569 const UNITY_UINT32 length) {
570 UnityPrint(UnityStrExpected);
571 if (expected != NULL) {
572 UNITY_OUTPUT_CHAR(
'\'');
573 UnityPrintLen(expected, length);
574 UNITY_OUTPUT_CHAR(
'\'');
576 UnityPrint(UnityStrNull);
578 UnityPrint(UnityStrWas);
579 if (actual != NULL) {
580 UNITY_OUTPUT_CHAR(
'\'');
581 UnityPrintLen(actual, length);
582 UNITY_OUTPUT_CHAR(
'\'');
584 UnityPrint(UnityStrNull);
593static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected,
594 UNITY_INTERNAL_PTR actual,
595 const UNITY_LINE_TYPE lineNumber,
598 if (expected == actual) {
603 if (expected == NULL) {
604 UnityTestResultsFailBegin(lineNumber);
605 UnityPrint(UnityStrNullPointerForExpected);
606 UnityAddMsgIfSpecified(msg);
611 if (actual == NULL) {
612 UnityTestResultsFailBegin(lineNumber);
613 UnityPrint(UnityStrNullPointerForActual);
614 UnityAddMsgIfSpecified(msg);
626void UnityAssertBits(
const UNITY_INT mask,
const UNITY_INT expected,
627 const UNITY_INT actual,
const char *msg,
628 const UNITY_LINE_TYPE lineNumber) {
629 RETURN_IF_FAIL_OR_IGNORE;
631 if ((mask & expected) != (mask & actual)) {
632 UnityTestResultsFailBegin(lineNumber);
633 UnityPrint(UnityStrExpected);
634 UnityPrintMask((UNITY_UINT)mask, (UNITY_UINT)expected);
635 UnityPrint(UnityStrWas);
636 UnityPrintMask((UNITY_UINT)mask, (UNITY_UINT)actual);
637 UnityAddMsgIfSpecified(msg);
643void UnityAssertEqualNumber(
const UNITY_INT expected,
const UNITY_INT actual,
644 const char *msg,
const UNITY_LINE_TYPE lineNumber,
645 const UNITY_DISPLAY_STYLE_T style) {
646 RETURN_IF_FAIL_OR_IGNORE;
648 if (expected != actual) {
649 UnityTestResultsFailBegin(lineNumber);
650 UnityPrint(UnityStrExpected);
651 UnityPrintNumberByStyle(expected, style);
652 UnityPrint(UnityStrWas);
653 UnityPrintNumberByStyle(actual, style);
654 UnityAddMsgIfSpecified(msg);
660void UnityAssertGreaterOrLessOrEqualNumber(
const UNITY_INT threshold,
661 const UNITY_INT actual,
662 const UNITY_COMPARISON_T compare,
664 const UNITY_LINE_TYPE lineNumber,
665 const UNITY_DISPLAY_STYLE_T style) {
667 RETURN_IF_FAIL_OR_IGNORE;
669 if ((threshold == actual) && (compare & UNITY_EQUAL_TO)) {
672 if ((threshold == actual)) {
676 if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) {
677 if ((actual > threshold) && (compare & UNITY_SMALLER_THAN)) {
680 if ((actual < threshold) && (compare & UNITY_GREATER_THAN)) {
685 if (((UNITY_UINT)actual > (UNITY_UINT)threshold) &&
686 (compare & UNITY_SMALLER_THAN)) {
689 if (((UNITY_UINT)actual < (UNITY_UINT)threshold) &&
690 (compare & UNITY_GREATER_THAN)) {
696 UnityTestResultsFailBegin(lineNumber);
697 UnityPrint(UnityStrExpected);
698 UnityPrintNumberByStyle(actual, style);
699 if (compare & UNITY_GREATER_THAN) {
700 UnityPrint(UnityStrGt);
702 if (compare & UNITY_SMALLER_THAN) {
703 UnityPrint(UnityStrLt);
705 if (compare & UNITY_EQUAL_TO) {
706 UnityPrint(UnityStrOrEqual);
708 if (compare == UNITY_NOT_EQUAL) {
709 UnityPrint(UnityStrNotEqual);
711 UnityPrintNumberByStyle(threshold, style);
712 UnityAddMsgIfSpecified(msg);
717#define UnityPrintPointlessAndBail() \
719 UnityTestResultsFailBegin(lineNumber); \
720 UnityPrint(UnityStrPointless); \
721 UnityAddMsgIfSpecified(msg); \
722 UNITY_FAIL_AND_BAIL; \
726void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
727 UNITY_INTERNAL_PTR actual,
728 const UNITY_UINT32 num_elements,
const char *msg,
729 const UNITY_LINE_TYPE lineNumber,
730 const UNITY_DISPLAY_STYLE_T style,
731 const UNITY_FLAGS_T flags) {
732 UNITY_UINT32 elements = num_elements;
733 unsigned int length = style & 0xF;
734 unsigned int increment = 0;
736 RETURN_IF_FAIL_OR_IGNORE;
738 if (num_elements == 0) {
739 UnityPrintPointlessAndBail();
742 if (expected == actual) {
746 if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) {
750 while ((elements > 0) && (elements--)) {
751 UNITY_INT expect_val;
752 UNITY_INT actual_val;
756 expect_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT8 *)expected;
757 actual_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT8 *)actual;
758 increment =
sizeof(UNITY_INT8);
762 expect_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT16 *)expected;
763 actual_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT16 *)actual;
764 increment =
sizeof(UNITY_INT16);
767#ifdef UNITY_SUPPORT_64
769 expect_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT64 *)expected;
770 actual_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT64 *)actual;
771 increment =
sizeof(UNITY_INT64);
777 expect_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT32 *)expected;
778 actual_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT32 *)actual;
779 increment =
sizeof(UNITY_INT32);
784 if (expect_val != actual_val) {
785 if ((style & UNITY_DISPLAY_RANGE_UINT) &&
787 (UNITY_INT_WIDTH / 8))) {
790 mask = (mask << 8 * length) - 1;
794 UnityTestResultsFailBegin(lineNumber);
795 UnityPrint(UnityStrElement);
796 UnityPrintNumberUnsigned(num_elements - elements - 1);
797 UnityPrint(UnityStrExpected);
798 UnityPrintNumberByStyle(expect_val, style);
799 UnityPrint(UnityStrWas);
800 UnityPrintNumberByStyle(actual_val, style);
801 UnityAddMsgIfSpecified(msg);
805 if (flags == UNITY_ARRAY_TO_ARRAY) {
806 expected = (UNITY_INTERNAL_PTR)((
const char *)expected + increment);
808 actual = (UNITY_INTERNAL_PTR)((
const char *)actual + increment);
813#ifndef UNITY_EXCLUDE_FLOAT
815#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
816 if (isinf(expected) && isinf(actual) && \
817 (((expected) < 0) == ((actual) < 0))) \
819 if (UNITY_NAN_CHECK) \
821 (diff) = (actual) - (expected); \
825 (delta) = -(delta); \
826 return !(isnan(diff) || isinf(diff) || ((diff) > (delta)))
828#ifndef UNITY_NAN_NOT_EQUAL_NAN
829#define UNITY_NAN_CHECK isnan(expected) && isnan(actual)
831#define UNITY_NAN_CHECK 0
834#ifndef UNITY_EXCLUDE_FLOAT_PRINT
835#define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \
837 UnityPrint(UnityStrExpected); \
838 UnityPrintFloat(expected); \
839 UnityPrint(UnityStrWas); \
840 UnityPrintFloat(actual); \
843#define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \
844 UnityPrint(UnityStrDelta)
848static int UnityFloatsWithin(UNITY_FLOAT delta, UNITY_FLOAT expected,
849 UNITY_FLOAT actual) {
851 UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff);
855void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE
const UNITY_FLOAT *expected,
856 UNITY_PTR_ATTRIBUTE
const UNITY_FLOAT *actual,
857 const UNITY_UINT32 num_elements,
859 const UNITY_LINE_TYPE lineNumber,
860 const UNITY_FLAGS_T flags) {
861 UNITY_UINT32 elements = num_elements;
862 UNITY_PTR_ATTRIBUTE
const UNITY_FLOAT *ptr_expected = expected;
863 UNITY_PTR_ATTRIBUTE
const UNITY_FLOAT *ptr_actual = actual;
865 RETURN_IF_FAIL_OR_IGNORE;
868 UnityPrintPointlessAndBail();
871 if (expected == actual) {
875 if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected,
876 (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) {
881 if (!UnityFloatsWithin(*ptr_expected * UNITY_FLOAT_PRECISION, *ptr_expected,
883 UnityTestResultsFailBegin(lineNumber);
884 UnityPrint(UnityStrElement);
885 UnityPrintNumberUnsigned(num_elements - elements - 1);
886 UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT((UNITY_DOUBLE)*ptr_expected,
887 (UNITY_DOUBLE)*ptr_actual);
888 UnityAddMsgIfSpecified(msg);
891 if (flags == UNITY_ARRAY_TO_ARRAY) {
899void UnityAssertFloatsWithin(
const UNITY_FLOAT delta,
900 const UNITY_FLOAT expected,
901 const UNITY_FLOAT actual,
const char *msg,
902 const UNITY_LINE_TYPE lineNumber) {
903 RETURN_IF_FAIL_OR_IGNORE;
905 if (!UnityFloatsWithin(delta, expected, actual)) {
906 UnityTestResultsFailBegin(lineNumber);
907 UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT((UNITY_DOUBLE)expected,
908 (UNITY_DOUBLE)actual);
909 UnityAddMsgIfSpecified(msg);
915void UnityAssertFloatSpecial(
const UNITY_FLOAT actual,
const char *msg,
916 const UNITY_LINE_TYPE lineNumber,
917 const UNITY_FLOAT_TRAIT_T style) {
918 const char *trait_names[] = {UnityStrInf, UnityStrNegInf, UnityStrNaN,
920 UNITY_INT should_be_trait = ((UNITY_INT)style & 1);
921 UNITY_INT is_trait = !should_be_trait;
922 UNITY_INT trait_index = (UNITY_INT)(style >> 1);
924 RETURN_IF_FAIL_OR_IGNORE;
926#pragma GCC diagnostic ignored "-Wswitch-enum"
927#pragma GCC diagnostic push
929 case UNITY_FLOAT_IS_INF:
930 case UNITY_FLOAT_IS_NOT_INF:
931 is_trait = isinf(actual) && (actual > 0);
933 case UNITY_FLOAT_IS_NEG_INF:
934 case UNITY_FLOAT_IS_NOT_NEG_INF:
935 is_trait = isinf(actual) && (actual < 0);
938 case UNITY_FLOAT_IS_NAN:
939 case UNITY_FLOAT_IS_NOT_NAN:
940 is_trait = isnan(actual) ? 1 : 0;
943 case UNITY_FLOAT_IS_DET:
945 case UNITY_FLOAT_IS_NOT_DET:
946 is_trait = !isinf(actual) && !isnan(actual);
951 trait_names[0] = UnityStrInvalidFloatTrait;
954#pragma GCC diagnostic pop
956 if (is_trait != should_be_trait) {
957 UnityTestResultsFailBegin(lineNumber);
958 UnityPrint(UnityStrExpected);
959 if (!should_be_trait) {
960 UnityPrint(UnityStrNot);
962 UnityPrint(trait_names[trait_index]);
963 UnityPrint(UnityStrWas);
964#ifndef UNITY_EXCLUDE_FLOAT_PRINT
965 UnityPrintFloat((UNITY_DOUBLE)actual);
967 if (should_be_trait) {
968 UnityPrint(UnityStrNot);
970 UnityPrint(trait_names[trait_index]);
972 UnityAddMsgIfSpecified(msg);
980#ifndef UNITY_EXCLUDE_DOUBLE
981static int UnityDoublesWithin(UNITY_DOUBLE delta, UNITY_DOUBLE expected,
982 UNITY_DOUBLE actual) {
984 UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff);
988void UnityAssertEqualDoubleArray(
989 UNITY_PTR_ATTRIBUTE
const UNITY_DOUBLE *expected,
990 UNITY_PTR_ATTRIBUTE
const UNITY_DOUBLE *actual,
991 const UNITY_UINT32 num_elements,
const char *msg,
992 const UNITY_LINE_TYPE lineNumber,
const UNITY_FLAGS_T flags) {
993 UNITY_UINT32 elements = num_elements;
994 UNITY_PTR_ATTRIBUTE
const UNITY_DOUBLE *ptr_expected = expected;
995 UNITY_PTR_ATTRIBUTE
const UNITY_DOUBLE *ptr_actual = actual;
997 RETURN_IF_FAIL_OR_IGNORE;
1000 UnityPrintPointlessAndBail();
1003 if (expected == actual) {
1007 if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected,
1008 (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) {
1009 UNITY_FAIL_AND_BAIL;
1012 while (elements--) {
1013 if (!UnityDoublesWithin(*ptr_expected * UNITY_DOUBLE_PRECISION,
1014 *ptr_expected, *ptr_actual)) {
1015 UnityTestResultsFailBegin(lineNumber);
1016 UnityPrint(UnityStrElement);
1017 UnityPrintNumberUnsigned(num_elements - elements - 1);
1018 UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(*ptr_expected, *ptr_actual);
1019 UnityAddMsgIfSpecified(msg);
1020 UNITY_FAIL_AND_BAIL;
1022 if (flags == UNITY_ARRAY_TO_ARRAY) {
1030void UnityAssertDoublesWithin(
const UNITY_DOUBLE delta,
1031 const UNITY_DOUBLE expected,
1032 const UNITY_DOUBLE actual,
const char *msg,
1033 const UNITY_LINE_TYPE lineNumber) {
1034 RETURN_IF_FAIL_OR_IGNORE;
1036 if (!UnityDoublesWithin(delta, expected, actual)) {
1037 UnityTestResultsFailBegin(lineNumber);
1038 UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual);
1039 UnityAddMsgIfSpecified(msg);
1040 UNITY_FAIL_AND_BAIL;
1045void UnityAssertDoubleSpecial(
const UNITY_DOUBLE actual,
const char *msg,
1046 const UNITY_LINE_TYPE lineNumber,
1047 const UNITY_FLOAT_TRAIT_T style) {
1048 const char *trait_names[] = {UnityStrInf, UnityStrNegInf, UnityStrNaN,
1050 UNITY_INT should_be_trait = ((UNITY_INT)style & 1);
1051 UNITY_INT is_trait = !should_be_trait;
1052 UNITY_INT trait_index = (UNITY_INT)(style >> 1);
1054 RETURN_IF_FAIL_OR_IGNORE;
1057 case UNITY_FLOAT_IS_INF:
1058 case UNITY_FLOAT_IS_NOT_INF:
1059 is_trait = isinf(actual) && (actual > 0);
1061 case UNITY_FLOAT_IS_NEG_INF:
1062 case UNITY_FLOAT_IS_NOT_NEG_INF:
1063 is_trait = isinf(actual) && (actual < 0);
1066 case UNITY_FLOAT_IS_NAN:
1067 case UNITY_FLOAT_IS_NOT_NAN:
1068 is_trait = isnan(actual) ? 1 : 0;
1071 case UNITY_FLOAT_IS_DET:
1073 case UNITY_FLOAT_IS_NOT_DET:
1074 is_trait = !isinf(actual) && !isnan(actual);
1079 trait_names[0] = UnityStrInvalidFloatTrait;
1083 if (is_trait != should_be_trait) {
1084 UnityTestResultsFailBegin(lineNumber);
1085 UnityPrint(UnityStrExpected);
1086 if (!should_be_trait) {
1087 UnityPrint(UnityStrNot);
1089 UnityPrint(trait_names[trait_index]);
1090 UnityPrint(UnityStrWas);
1091#ifndef UNITY_EXCLUDE_FLOAT_PRINT
1092 UnityPrintFloat(actual);
1094 if (should_be_trait) {
1095 UnityPrint(UnityStrNot);
1097 UnityPrint(trait_names[trait_index]);
1099 UnityAddMsgIfSpecified(msg);
1100 UNITY_FAIL_AND_BAIL;
1107void UnityAssertNumbersWithin(
const UNITY_UINT delta,
const UNITY_INT expected,
1108 const UNITY_INT actual,
const char *msg,
1109 const UNITY_LINE_TYPE lineNumber,
1110 const UNITY_DISPLAY_STYLE_T style) {
1111 RETURN_IF_FAIL_OR_IGNORE;
1113 if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) {
1114 if (actual > expected) {
1115 Unity.CurrentTestFailed =
1116 (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta);
1118 Unity.CurrentTestFailed =
1119 (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta);
1122 if ((UNITY_UINT)actual > (UNITY_UINT)expected) {
1123 Unity.CurrentTestFailed =
1124 (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta);
1126 Unity.CurrentTestFailed =
1127 (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta);
1131 if (Unity.CurrentTestFailed) {
1132 UnityTestResultsFailBegin(lineNumber);
1133 UnityPrint(UnityStrDelta);
1134 UnityPrintNumberByStyle((UNITY_INT)delta, style);
1135 UnityPrint(UnityStrExpected);
1136 UnityPrintNumberByStyle(expected, style);
1137 UnityPrint(UnityStrWas);
1138 UnityPrintNumberByStyle(actual, style);
1139 UnityAddMsgIfSpecified(msg);
1140 UNITY_FAIL_AND_BAIL;
1145void UnityAssertNumbersArrayWithin(
1146 const UNITY_UINT delta, UNITY_INTERNAL_PTR expected,
1147 UNITY_INTERNAL_PTR actual,
const UNITY_UINT32 num_elements,
const char *msg,
1148 const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style,
1149 const UNITY_FLAGS_T flags) {
1150 UNITY_UINT32 elements = num_elements;
1151 unsigned int length = style & 0xF;
1152 unsigned int increment = 0;
1154 RETURN_IF_FAIL_OR_IGNORE;
1156 if (num_elements == 0) {
1157 UnityPrintPointlessAndBail();
1160 if (expected == actual) {
1164 if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) {
1165 UNITY_FAIL_AND_BAIL;
1168 while ((elements > 0) && (elements--)) {
1169 UNITY_INT expect_val;
1170 UNITY_INT actual_val;
1174 expect_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT8 *)expected;
1175 actual_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT8 *)actual;
1176 increment =
sizeof(UNITY_INT8);
1180 expect_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT16 *)expected;
1181 actual_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT16 *)actual;
1182 increment =
sizeof(UNITY_INT16);
1185#ifdef UNITY_SUPPORT_64
1187 expect_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT64 *)expected;
1188 actual_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT64 *)actual;
1189 increment =
sizeof(UNITY_INT64);
1195 expect_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT32 *)expected;
1196 actual_val = *(UNITY_PTR_ATTRIBUTE
const UNITY_INT32 *)actual;
1197 increment =
sizeof(UNITY_INT32);
1202 if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) {
1203 if (actual_val > expect_val) {
1204 Unity.CurrentTestFailed =
1205 (((UNITY_UINT)actual_val - (UNITY_UINT)expect_val) > delta);
1207 Unity.CurrentTestFailed =
1208 (((UNITY_UINT)expect_val - (UNITY_UINT)actual_val) > delta);
1211 if ((UNITY_UINT)actual_val > (UNITY_UINT)expect_val) {
1212 Unity.CurrentTestFailed =
1213 (((UNITY_UINT)actual_val - (UNITY_UINT)expect_val) > delta);
1215 Unity.CurrentTestFailed =
1216 (((UNITY_UINT)expect_val - (UNITY_UINT)actual_val) > delta);
1220 if (Unity.CurrentTestFailed) {
1221 if ((style & UNITY_DISPLAY_RANGE_UINT) &&
1223 (UNITY_INT_WIDTH / 8))) {
1226 mask = (mask << 8 * length) - 1;
1230 UnityTestResultsFailBegin(lineNumber);
1231 UnityPrint(UnityStrDelta);
1232 UnityPrintNumberByStyle((UNITY_INT)delta, style);
1233 UnityPrint(UnityStrElement);
1234 UnityPrintNumberUnsigned(num_elements - elements - 1);
1235 UnityPrint(UnityStrExpected);
1236 UnityPrintNumberByStyle(expect_val, style);
1237 UnityPrint(UnityStrWas);
1238 UnityPrintNumberByStyle(actual_val, style);
1239 UnityAddMsgIfSpecified(msg);
1240 UNITY_FAIL_AND_BAIL;
1243 if (flags == UNITY_ARRAY_TO_ARRAY) {
1244 expected = (UNITY_INTERNAL_PTR)((
const char *)expected + increment);
1246 actual = (UNITY_INTERNAL_PTR)((
const char *)actual + increment);
1251void UnityAssertEqualString(
const char *expected,
const char *actual,
1252 const char *msg,
const UNITY_LINE_TYPE lineNumber) {
1255 RETURN_IF_FAIL_OR_IGNORE;
1258 if (expected && actual) {
1259 for (i = 0; expected[i] || actual[i]; i++) {
1260 if (expected[i] != actual[i]) {
1261 Unity.CurrentTestFailed = 1;
1267 if (expected != actual) {
1268 Unity.CurrentTestFailed = 1;
1272 if (Unity.CurrentTestFailed) {
1273 UnityTestResultsFailBegin(lineNumber);
1274 UnityPrintExpectedAndActualStrings(expected, actual);
1275 UnityAddMsgIfSpecified(msg);
1276 UNITY_FAIL_AND_BAIL;
1281void UnityAssertEqualStringLen(
const char *expected,
const char *actual,
1282 const UNITY_UINT32 length,
const char *msg,
1283 const UNITY_LINE_TYPE lineNumber) {
1286 RETURN_IF_FAIL_OR_IGNORE;
1289 if (expected && actual) {
1290 for (i = 0; (i < length) && (expected[i] || actual[i]); i++) {
1291 if (expected[i] != actual[i]) {
1292 Unity.CurrentTestFailed = 1;
1298 if (expected != actual) {
1299 Unity.CurrentTestFailed = 1;
1303 if (Unity.CurrentTestFailed) {
1304 UnityTestResultsFailBegin(lineNumber);
1305 UnityPrintExpectedAndActualStringsLen(expected, actual, length);
1306 UnityAddMsgIfSpecified(msg);
1307 UNITY_FAIL_AND_BAIL;
1312void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected,
1313 const char **actual,
1314 const UNITY_UINT32 num_elements,
1316 const UNITY_LINE_TYPE lineNumber,
1317 const UNITY_FLAGS_T flags) {
1320 const char *expd = NULL;
1321 const char *act = NULL;
1323 RETURN_IF_FAIL_OR_IGNORE;
1326 if (num_elements == 0) {
1327 UnityPrintPointlessAndBail();
1330 if ((
const void *)expected == (
const void *)actual) {
1334 if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected,
1335 (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) {
1336 UNITY_FAIL_AND_BAIL;
1339 if (flags != UNITY_ARRAY_TO_ARRAY) {
1340 expd = (
const char *)expected;
1345 if (flags == UNITY_ARRAY_TO_ARRAY) {
1346 expd = ((
const char *
const *)expected)[j];
1351 for (i = 0; expd[i] || act[i]; i++) {
1352 if (expd[i] != act[i]) {
1353 Unity.CurrentTestFailed = 1;
1360 Unity.CurrentTestFailed = 1;
1364 if (Unity.CurrentTestFailed) {
1365 UnityTestResultsFailBegin(lineNumber);
1366 if (num_elements > 1) {
1367 UnityPrint(UnityStrElement);
1368 UnityPrintNumberUnsigned(j);
1370 UnityPrintExpectedAndActualStrings(expd, act);
1371 UnityAddMsgIfSpecified(msg);
1372 UNITY_FAIL_AND_BAIL;
1374 }
while (++j < num_elements);
1378void UnityAssertEqualMemory(UNITY_INTERNAL_PTR expected,
1379 UNITY_INTERNAL_PTR actual,
1380 const UNITY_UINT32 length,
1381 const UNITY_UINT32 num_elements,
const char *msg,
1382 const UNITY_LINE_TYPE lineNumber,
1383 const UNITY_FLAGS_T flags) {
1384 UNITY_PTR_ATTRIBUTE
const unsigned char *ptr_exp =
1385 (UNITY_PTR_ATTRIBUTE
const unsigned char *)expected;
1386 UNITY_PTR_ATTRIBUTE
const unsigned char *ptr_act =
1387 (UNITY_PTR_ATTRIBUTE
const unsigned char *)actual;
1388 UNITY_UINT32 elements = num_elements;
1391 RETURN_IF_FAIL_OR_IGNORE;
1393 if ((elements == 0) || (length == 0)) {
1394 UnityPrintPointlessAndBail();
1397 if (expected == actual) {
1401 if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) {
1402 UNITY_FAIL_AND_BAIL;
1405 while (elements--) {
1408 if (*ptr_exp != *ptr_act) {
1409 UnityTestResultsFailBegin(lineNumber);
1410 UnityPrint(UnityStrMemory);
1411 if (num_elements > 1) {
1412 UnityPrint(UnityStrElement);
1413 UnityPrintNumberUnsigned(num_elements - elements - 1);
1415 UnityPrint(UnityStrByte);
1416 UnityPrintNumberUnsigned(length - bytes - 1);
1417 UnityPrint(UnityStrExpected);
1418 UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8);
1419 UnityPrint(UnityStrWas);
1420 UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8);
1421 UnityAddMsgIfSpecified(msg);
1422 UNITY_FAIL_AND_BAIL;
1427 if (flags == UNITY_ARRAY_TO_VAL) {
1428 ptr_exp = (UNITY_PTR_ATTRIBUTE
const unsigned char *)expected;
1439#ifdef UNITY_SUPPORT_64
1442#ifndef UNITY_EXCLUDE_FLOAT
1445#ifndef UNITY_EXCLUDE_DOUBLE
1450UNITY_INTERNAL_PTR UnityNumToPtr(
const UNITY_INT num,
const UNITY_UINT8 size) {
1453 UnityQuickCompare.i8 = (UNITY_INT8)num;
1454 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i8);
1457 UnityQuickCompare.i16 = (UNITY_INT16)num;
1458 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i16);
1460#ifdef UNITY_SUPPORT_64
1462 UnityQuickCompare.i64 = (UNITY_INT64)num;
1463 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i64);
1467 UnityQuickCompare.i32 = (UNITY_INT32)num;
1468 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i32);
1472#ifndef UNITY_EXCLUDE_FLOAT
1474UNITY_INTERNAL_PTR UnityFloatToPtr(
const float num) {
1475 UnityQuickCompare.f = num;
1476 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.f);
1480#ifndef UNITY_EXCLUDE_DOUBLE
1482UNITY_INTERNAL_PTR UnityDoubleToPtr(
const double num) {
1483 UnityQuickCompare.d = num;
1484 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.d);
1491#ifdef UNITY_INCLUDE_PRINT_FORMATTED
1492static void UnityPrintFVA(
const char *format, va_list va) {
1493 const char *pch = format;
1504 const int number = va_arg(va,
int);
1505 UnityPrintNumber((UNITY_INT)number);
1508#ifndef UNITY_EXCLUDE_FLOAT_PRINT
1511 const double number = va_arg(va,
double);
1512 UnityPrintFloat((UNITY_DOUBLE)number);
1517 const unsigned int number = va_arg(va,
unsigned int);
1518 UnityPrintNumberUnsigned((UNITY_UINT)number);
1522 const unsigned int number = va_arg(va,
unsigned int);
1523 const UNITY_UINT mask = (UNITY_UINT)0 - (UNITY_UINT)1;
1524 UNITY_OUTPUT_CHAR(
'0');
1525 UNITY_OUTPUT_CHAR(
'b');
1526 UnityPrintMask(mask, (UNITY_UINT)number);
1532 const unsigned int number = va_arg(va,
unsigned int);
1533 UNITY_OUTPUT_CHAR(
'0');
1534 UNITY_OUTPUT_CHAR(
'x');
1535 UnityPrintNumberHex((UNITY_UINT)number, 8);
1539 const int ch = va_arg(va,
int);
1540 UnityPrintChar((
const char *)&ch);
1544 const char *
string = va_arg(va,
const char *);
1549 UnityPrintChar(pch);
1554 UNITY_OUTPUT_CHAR(
'%');
1555 UnityPrintChar(pch);
1561#ifdef UNITY_OUTPUT_COLOR
1563 else if ((*pch == 27) && (*(pch + 1) ==
'[')) {
1564 pch += UnityPrintAnsiEscapeString(pch);
1568 else if (*pch ==
'\n') {
1571 UnityPrintChar(pch);
1579void UnityPrintF(
const UNITY_LINE_TYPE line,
const char *format, ...) {
1580 UnityTestResultsBegin(Unity.TestFile, line);
1582 if (format != NULL) {
1585 va_start(va, format);
1586 UnityPrintFVA(format, va);
1598void UnityFail(
const char *msg,
const UNITY_LINE_TYPE line) {
1599 RETURN_IF_FAIL_OR_IGNORE;
1601 UnityTestResultsBegin(Unity.TestFile, line);
1602 UnityPrint(UnityStrFail);
1604 UNITY_OUTPUT_CHAR(
':');
1606#ifdef UNITY_PRINT_TEST_CONTEXT
1607 UNITY_PRINT_TEST_CONTEXT();
1609#ifndef UNITY_EXCLUDE_DETAILS
1610 if (Unity.CurrentDetail1) {
1611 UnityPrint(UnityStrDetail1Name);
1612 UnityPrint(Unity.CurrentDetail1);
1613 if (Unity.CurrentDetail2) {
1614 UnityPrint(UnityStrDetail2Name);
1615 UnityPrint(Unity.CurrentDetail2);
1617 UnityPrint(UnityStrSpacer);
1620 if (msg[0] !=
' ') {
1621 UNITY_OUTPUT_CHAR(
' ');
1626 UNITY_FAIL_AND_BAIL;
1630void UnityIgnore(
const char *msg,
const UNITY_LINE_TYPE line) {
1631 RETURN_IF_FAIL_OR_IGNORE;
1633 UnityTestResultsBegin(Unity.TestFile, line);
1634 UnityPrint(UnityStrIgnore);
1636 UNITY_OUTPUT_CHAR(
':');
1637 UNITY_OUTPUT_CHAR(
' ');
1640 UNITY_IGNORE_AND_BAIL;
1644void UnityMessage(
const char *msg,
const UNITY_LINE_TYPE line) {
1645 UnityTestResultsBegin(Unity.TestFile, line);
1648 UNITY_OUTPUT_CHAR(
':');
1649 UNITY_OUTPUT_CHAR(
' ');
1658#ifndef UNITY_SKIP_DEFAULT_RUNNER
1659void UnityDefaultTestRun(UnityTestFunction Func,
const char *FuncName,
1660 const int FuncLineNum) {
1661 Unity.CurrentTestName = FuncName;
1662 Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum;
1663 Unity.NumberOfTests++;
1664 UNITY_CLR_DETAILS();
1665 UNITY_EXEC_TIME_START();
1666 if (TEST_PROTECT()) {
1670 if (TEST_PROTECT()) {
1673 UNITY_EXEC_TIME_STOP();
1674 UnityConcludeTest();
1679void UnitySetTestFile(
const char *filename) { Unity.TestFile = filename; }
1682void UnityBegin(
const char *filename) {
1683 Unity.TestFile = filename;
1684 Unity.CurrentTestName = NULL;
1685 Unity.CurrentTestLineNumber = 0;
1686 Unity.NumberOfTests = 0;
1687 Unity.TestFailures = 0;
1688 Unity.TestIgnores = 0;
1689 Unity.CurrentTestFailed = 0;
1690 Unity.CurrentTestIgnored = 0;
1692 UNITY_CLR_DETAILS();
1693 UNITY_OUTPUT_START();
1699 UnityPrint(UnityStrBreaker);
1701 UnityPrintNumber((UNITY_INT)(Unity.NumberOfTests));
1702 UnityPrint(UnityStrResultsTests);
1703 UnityPrintNumber((UNITY_INT)(Unity.TestFailures));
1704 UnityPrint(UnityStrResultsFailures);
1705 UnityPrintNumber((UNITY_INT)(Unity.TestIgnores));
1706 UnityPrint(UnityStrResultsIgnored);
1708 if (Unity.TestFailures == 0U) {
1709 UnityPrint(UnityStrOk);
1711 UnityPrint(UnityStrFail);
1712#ifdef UNITY_DIFFERENTIATE_FINAL_FAIL
1713 UNITY_OUTPUT_CHAR(
'E');
1714 UNITY_OUTPUT_CHAR(
'D');
1719 UNITY_OUTPUT_COMPLETE();
1720 return (
int)(Unity.TestFailures);
1726#ifdef UNITY_USE_COMMAND_LINE_ARGS
1728char *UnityOptionIncludeNamed = NULL;
1729char *UnityOptionExcludeNamed = NULL;
1730int UnityVerbosity = 1;
1733int UnityParseOptions(
int argc,
char **argv) {
1735 UnityOptionIncludeNamed = NULL;
1736 UnityOptionExcludeNamed = NULL;
1738 for (i = 1; i < argc; i++) {
1739 if (argv[i][0] ==
'-') {
1740 switch (argv[i][1]) {
1745 if (argv[i][2] ==
'=') {
1746 UnityOptionIncludeNamed = &argv[i][3];
1747 }
else if (++i < argc) {
1748 UnityOptionIncludeNamed = argv[i];
1750 UnityPrint(
"ERROR: No Test String to Include Matches For");
1762 if (argv[i][2] ==
'=') {
1763 UnityOptionExcludeNamed = &argv[i][3];
1764 }
else if (++i < argc) {
1765 UnityOptionExcludeNamed = argv[i];
1767 UnityPrint(
"ERROR: No Test String to Exclude Matches For");
1773 UnityPrint(
"ERROR: Unknown Option ");
1774 UNITY_OUTPUT_CHAR(argv[i][1]);
1785int IsStringInBiggerString(
const char *longstring,
const char *shortstring) {
1786 const char *lptr = longstring;
1787 const char *sptr = shortstring;
1788 const char *lnext = lptr;
1798 while (*lptr && *sptr && (*lptr == *sptr)) {
1827int UnityStringArgumentMatches(
const char *str) {
1835 while (ptr1[0] != 0) {
1836 if ((ptr1[0] ==
'"') || (ptr1[0] ==
'\'')) {
1845 if ((ptr2[0] ==
':') && (ptr2[1] != 0) && (ptr2[0] !=
'\'') &&
1846 (ptr2[0] !=
'"') && (ptr2[0] !=
',')) {
1849 }
while ((ptr2[0] != 0) && (ptr2[0] !=
'\'') && (ptr2[0] !=
'"') &&
1852 while ((ptr2[0] != 0) && ((ptr2[0] ==
':') || (ptr2[0] ==
'\'') ||
1853 (ptr2[0] ==
'"') || (ptr2[0] ==
','))) {
1858 retval = IsStringInBiggerString(Unity.TestFile, ptr1);
1864 if ((retval == 2) && (ptrf != 0)) {
1865 if (IsStringInBiggerString(Unity.CurrentTestName, ptrf)) {
1871 if (IsStringInBiggerString(Unity.CurrentTestName, ptr1) == 1) {
1883int UnityTestMatches(
void) {
1886 if (UnityOptionIncludeNamed) {
1887 retval = UnityStringArgumentMatches(UnityOptionIncludeNamed);
1893 if (UnityOptionExcludeNamed) {
1894 if (UnityStringArgumentMatches(UnityOptionExcludeNamed)) {