unity.c 35.6 KB
Newer Older
1
/* =========================================================================
2
    Unity Project - A Test Framework for C
3
    Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams
4
    [Released under MIT License. Please refer to license.txt for details]
5
============================================================================ */
6

G
greg-williams 已提交
7 8
#include "unity.h"
#include <stdio.h>
M
mvandervoord 已提交
9
#include <string.h>
G
greg-williams 已提交
10

11 12
#define UNITY_FAIL_AND_BAIL   { Unity.CurrentTestFailed  = 1; longjmp(Unity.AbortFrame, 1); }
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; longjmp(Unity.AbortFrame, 1); }
13 14
/// return prematurely if we are already in failure or ignore state
#define UNITY_SKIP_EXECUTION  { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
M
mvandervoord 已提交
15
#define UNITY_PRINT_EOL       { UNITY_OUTPUT_CHAR('\n'); }
M
mvandervoord 已提交
16

17
struct _Unity Unity;
G
greg-williams 已提交
18

19
const char* UnityStrNull     = "NULL";
20
const char* UnityStrSpacer   = ". ";
M
mvandervoord 已提交
21 22 23 24
const char* UnityStrExpected = " Expected ";
const char* UnityStrWas      = " Was ";
const char* UnityStrTo       = " To ";
const char* UnityStrElement  = " Element ";
25 26
const char* UnityStrByte     = " Byte ";
const char* UnityStrMemory   = " Memory Mismatch.";
M
mvandervoord 已提交
27
const char* UnityStrDelta    = " Values Not Within Delta ";
28
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
29 30
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
const char* UnityStrNullPointerForActual  = " Actual pointer was NULL";
31
const char* UnityStrNot      = "Not ";
32 33 34
const char* UnityStrInf      = "Infinity";
const char* UnityStrNegInf   = "Negative Infinity";
const char* UnityStrNaN      = "NaN";
35
const char* UnityStrDet      = "Determinate";
36 37 38
const char* UnityStrErrFloat = "Unity Floating Point Disabled";
const char* UnityStrErrDouble= "Unity Double Precision Disabled";
const char* UnityStrErr64    = "Unity 64-bit Support Disabled";
M
mvandervoord 已提交
39

40
#ifndef UNITY_EXCLUDE_FLOAT
41 42 43 44 45 46
// Dividing by these constants produces +/- infinity.
// The rationale is given in UnityAssertFloatIsInf's body.
static const _UF f_zero = 0.0f;
#ifndef UNITY_EXCLUDE_DOUBLE
static const _UD d_zero = 0.0;
#endif
47
#endif
48

49
// compiler-generic print formatting masks
50
const _U_UINT UnitySizeMask[] =
51
{
52 53
    255u,         // 0xFF
    65535u,       // 0xFFFF
M
 
mvandervoord 已提交
54
    65535u,
55
    4294967295u,  // 0xFFFFFFFF
M
 
mvandervoord 已提交
56 57 58
    4294967295u,
    4294967295u,
    4294967295u
59 60 61 62 63
#ifdef UNITY_SUPPORT_64
    ,0xFFFFFFFFFFFFFFFF
#endif
};

64 65 66
void UnityPrintFail(void);
void UnityPrintOk(void);

M
mvandervoord 已提交
67
//-----------------------------------------------
68
// Pretty Printers & Test Result Output Handlers
M
mvandervoord 已提交
69 70
//-----------------------------------------------

71
void UnityPrint(const char* string)
G
greg-williams 已提交
72
{
73
    const char* pch = string;
G
greg-williams 已提交
74 75 76 77 78

    if (pch != NULL)
    {
        while (*pch)
        {
M
mvandervoord 已提交
79
            // printable characters plus CR & LF are printed
M
mvandervoord 已提交
80
            if ((*pch <= 126) && (*pch >= 32))
M
mvandervoord 已提交
81 82 83
            {
                UNITY_OUTPUT_CHAR(*pch);
            }
M
mvandervoord 已提交
84 85 86 87 88 89 90 91 92 93 94 95
            //write escaped carriage returns
            else if (*pch == 13)
            {
                UNITY_OUTPUT_CHAR('\\');
                UNITY_OUTPUT_CHAR('r');
            }
            //write escaped line feeds
            else if (*pch == 10)
            {
                UNITY_OUTPUT_CHAR('\\');
                UNITY_OUTPUT_CHAR('n');
            }
M
mvandervoord 已提交
96 97 98 99
            // unprintable characters are shown as codes
            else
            {
                UNITY_OUTPUT_CHAR('\\');
100
                UnityPrintNumberHex((_U_UINT)*pch, 2);
M
mvandervoord 已提交
101
            }
G
greg-williams 已提交
102 103 104 105 106
            pch++;
        }
    }
}

M
mvandervoord 已提交
107
//-----------------------------------------------
M
mvandervoord 已提交
108
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
G
greg-williams 已提交
109
{
M
mvandervoord 已提交
110 111 112 113 114 115
    if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
    {
        UnityPrintNumber(number);
    }
    else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
    {
116
        UnityPrintNumberUnsigned(  (_U_UINT)number  &  UnitySizeMask[((_U_UINT)style & (_U_UINT)0x0F) - 1]  );
M
mvandervoord 已提交
117 118
    }
    else
G
greg-williams 已提交
119
    {
120
        UnityPrintNumberHex((_U_UINT)number, (char)((style & 0x000F) << 1));
G
greg-williams 已提交
121 122 123
    }
}

M
mvandervoord 已提交
124
//-----------------------------------------------
G
greg-williams 已提交
125
/// basically do an itoa using as little ram as possible
M
mvandervoord 已提交
126
void UnityPrintNumber(const _U_SINT number_to_print)
G
greg-williams 已提交
127
{
M
mvandervoord 已提交
128 129 130
    _U_SINT divisor = 1;
    _U_SINT next_divisor;
    _U_SINT number = number_to_print;
G
greg-williams 已提交
131 132 133

    if (number < 0)
    {
134
        UNITY_OUTPUT_CHAR('-');
G
greg-williams 已提交
135 136 137 138
        number = -number;
    }

    // figure out initial divisor
M
mvandervoord 已提交
139
    while (number / divisor > 9)
G
greg-williams 已提交
140
    {
M
mvandervoord 已提交
141 142 143 144 145
        next_divisor = divisor * 10;
        if (next_divisor > divisor)
            divisor = next_divisor;
        else
            break;
G
greg-williams 已提交
146 147
    }

M
mvandervoord 已提交
148
    // now mod and print, then divide divisor
G
greg-williams 已提交
149 150
    do
    {
151
        UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
M
mvandervoord 已提交
152
        divisor /= 10;
G
greg-williams 已提交
153
    }
M
mvandervoord 已提交
154
    while (divisor > 0);
G
greg-williams 已提交
155 156
}

M
mvandervoord 已提交
157
//-----------------------------------------------
G
greg-williams 已提交
158
/// basically do an itoa using as little ram as possible
M
mvandervoord 已提交
159
void UnityPrintNumberUnsigned(const _U_UINT number)
G
greg-williams 已提交
160
{
M
mvandervoord 已提交
161 162
    _U_UINT divisor = 1;
    _U_UINT next_divisor;
G
greg-williams 已提交
163 164

    // figure out initial divisor
M
mvandervoord 已提交
165
    while (number / divisor > 9)
G
greg-williams 已提交
166
    {
M
mvandervoord 已提交
167 168 169 170 171
        next_divisor = divisor * 10;
        if (next_divisor > divisor)
            divisor = next_divisor;
        else
            break;
G
greg-williams 已提交
172 173
    }

M
mvandervoord 已提交
174
    // now mod and print, then divide divisor
G
greg-williams 已提交
175 176
    do
    {
177
        UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
M
mvandervoord 已提交
178
        divisor /= 10;
G
greg-williams 已提交
179
    }
M
mvandervoord 已提交
180
    while (divisor > 0);
G
greg-williams 已提交
181 182
}

M
mvandervoord 已提交
183
//-----------------------------------------------
M
mvandervoord 已提交
184
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
G
greg-williams 已提交
185
{
M
mvandervoord 已提交
186
    _U_UINT nibble;
M
mvandervoord 已提交
187
    char nibbles = nibbles_to_print;
188 189
    UNITY_OUTPUT_CHAR('0');
    UNITY_OUTPUT_CHAR('x');
G
greg-williams 已提交
190 191 192 193 194 195

    while (nibbles > 0)
    {
        nibble = (number >> (--nibbles << 2)) & 0x0000000F;
        if (nibble <= 9)
        {
196
            UNITY_OUTPUT_CHAR((char)('0' + nibble));
G
greg-williams 已提交
197 198 199
        }
        else
        {
200
            UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
G
greg-williams 已提交
201 202 203 204
        }
    }
}

M
mvandervoord 已提交
205
//-----------------------------------------------
M
mvandervoord 已提交
206
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
G
greg-williams 已提交
207
{
208
    _U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
209
    _US32 i;
G
greg-williams 已提交
210

M
mvandervoord 已提交
211
    for (i = 0; i < UNITY_INT_WIDTH; i++)
G
greg-williams 已提交
212
    {
213
        if (current_bit & mask)
G
greg-williams 已提交
214
        {
215
            if (current_bit & number)
G
greg-williams 已提交
216
            {
217
                UNITY_OUTPUT_CHAR('1');
G
greg-williams 已提交
218 219 220
            }
            else
            {
221
                UNITY_OUTPUT_CHAR('0');
G
greg-williams 已提交
222 223 224 225
            }
        }
        else
        {
226
            UNITY_OUTPUT_CHAR('X');
G
greg-williams 已提交
227
        }
228
        current_bit = current_bit >> 1;
G
greg-williams 已提交
229 230 231
    }
}

M
mvandervoord 已提交
232
//-----------------------------------------------
233 234 235 236 237 238 239 240 241
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(_UF number)
{
    char TempBuffer[32];
    sprintf(TempBuffer, "%.6f", number);
    UnityPrint(TempBuffer);
}
#endif

242 243 244 245 246 247 248 249 250 251 252 253
//-----------------------------------------------

void UnityPrintFail(void)
{
    UnityPrint("FAIL");
}

void UnityPrintOk(void)
{
    UnityPrint("OK");
}

M
mvandervoord 已提交
254
//-----------------------------------------------
M
mvandervoord 已提交
255
void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
256
{
257
    UNITY_PRINT_EOL;
258
    UnityPrint(file);
259
    UNITY_OUTPUT_CHAR(':');
260
    UnityPrintNumber((_U_SINT)line);
261
    UNITY_OUTPUT_CHAR(':');
G
greg-williams 已提交
262
    UnityPrint(Unity.CurrentTestName);
263
    UNITY_OUTPUT_CHAR(':');
G
greg-williams 已提交
264 265
}

M
mvandervoord 已提交
266
//-----------------------------------------------
M
mvandervoord 已提交
267
void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
268
{
M
mvandervoord 已提交
269
    UnityTestResultsBegin(Unity.TestFile, line);
270 271 272
    UnityPrint("FAIL:");
}

M
mvandervoord 已提交
273
//-----------------------------------------------
274
void UnityConcludeTest(void)
G
greg-williams 已提交
275 276 277 278 279 280 281
{
    if (Unity.CurrentTestIgnored)
    {
        Unity.TestIgnores++;
    }
    else if (!Unity.CurrentTestFailed)
    {
282
        UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
M
mvandervoord 已提交
283
        UnityPrint("PASS");
G
greg-williams 已提交
284 285 286 287 288 289 290 291 292 293
    }
    else
    {
        Unity.TestFailures++;
    }

    Unity.CurrentTestFailed = 0;
    Unity.CurrentTestIgnored = 0;
}

M
mvandervoord 已提交
294
//-----------------------------------------------
M
mvandervoord 已提交
295 296 297 298 299 300 301 302 303
void UnityAddMsgIfSpecified(const char* msg)
{
    if (msg)
    {
        UnityPrint(UnityStrSpacer);
        UnityPrint(msg);
    }
}

304 305 306
//-----------------------------------------------
void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
{
M
mvandervoord 已提交
307 308 309 310 311 312 313 314 315
    UnityPrint(UnityStrExpected);
    if (expected != NULL)
    {
        UNITY_OUTPUT_CHAR('\'');
        UnityPrint(expected);
        UNITY_OUTPUT_CHAR('\'');
    }
    else
    {
316
      UnityPrint(UnityStrNull);
M
mvandervoord 已提交
317 318 319 320 321 322 323 324 325 326
    }
    UnityPrint(UnityStrWas);
    if (actual != NULL)
    {
        UNITY_OUTPUT_CHAR('\'');
        UnityPrint(actual);
        UNITY_OUTPUT_CHAR('\'');
    }
    else
    {
327
      UnityPrint(UnityStrNull);
M
mvandervoord 已提交
328
    }
329 330
}

331 332 333 334
//-----------------------------------------------
// Assertion & Control Helpers
//-----------------------------------------------

335
int UnityCheckArraysForNull(UNITY_PTR_ATTRIBUTE const void* expected, UNITY_PTR_ATTRIBUTE const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
336 337 338 339
{
    //return true if they are both NULL
    if ((expected == NULL) && (actual == NULL))
        return 1;
340

341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
    //throw error if just expected is NULL
    if (expected == NULL)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrNullPointerForExpected);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }

    //throw error if just actual is NULL
    if (actual == NULL)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrNullPointerForActual);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
358

359 360 361
    //return false if neither is NULL
    return 0;
}
362

M
mvandervoord 已提交
363 364 365 366
//-----------------------------------------------
// Assertion Functions
//-----------------------------------------------

M
mvandervoord 已提交
367 368 369
void UnityAssertBits(const _U_SINT mask,
                     const _U_SINT expected,
                     const _U_SINT actual,
370
                     const char* msg,
M
mvandervoord 已提交
371
                     const UNITY_LINE_TYPE lineNumber)
G
greg-williams 已提交
372
{
373
    UNITY_SKIP_EXECUTION;
374

G
greg-williams 已提交
375 376
    if ((mask & expected) != (mask & actual))
    {
377
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
378
        UnityPrint(UnityStrExpected);
379
        UnityPrintMask((_U_UINT)mask, (_U_UINT)expected);
M
mvandervoord 已提交
380
        UnityPrint(UnityStrWas);
381
        UnityPrintMask((_U_UINT)mask, (_U_UINT)actual);
M
mvandervoord 已提交
382 383
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
384 385 386
    }
}

M
mvandervoord 已提交
387
//-----------------------------------------------
M
mvandervoord 已提交
388 389
void UnityAssertEqualNumber(const _U_SINT expected,
                            const _U_SINT actual,
M
mvandervoord 已提交
390 391 392
                            const char* msg,
                            const UNITY_LINE_TYPE lineNumber,
                            const UNITY_DISPLAY_STYLE_T style)
393
{
394 395
    UNITY_SKIP_EXECUTION;

396 397
    if (expected != actual)
    {
398
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
399
        UnityPrint(UnityStrExpected);
400
        UnityPrintNumberByStyle(expected, style);
M
mvandervoord 已提交
401
        UnityPrint(UnityStrWas);
402
        UnityPrintNumberByStyle(actual, style);
M
mvandervoord 已提交
403 404
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
405 406 407
    }
}

M
mvandervoord 已提交
408
//-----------------------------------------------
409 410
void UnityAssertEqualIntArray(UNITY_PTR_ATTRIBUTE const void* expected,
                              UNITY_PTR_ATTRIBUTE const void* actual,
411
                              const _UU32 num_elements,
412
                              const char* msg,
M
mvandervoord 已提交
413
                              const UNITY_LINE_TYPE lineNumber,
414 415
                              const UNITY_DISPLAY_STYLE_T style)
{
416
    _UU32 elements = num_elements;
417 418
    UNITY_PTR_ATTRIBUTE const _US8* ptr_exp = (UNITY_PTR_ATTRIBUTE _US8*)expected;
    UNITY_PTR_ATTRIBUTE const _US8* ptr_act = (UNITY_PTR_ATTRIBUTE _US8*)actual;
419

420
    UNITY_SKIP_EXECUTION;
421

422 423 424 425 426 427 428
    if (elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
429

430
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
431
        return;
432

433 434 435
    // If style is UNITY_DISPLAY_STYLE_INT, we'll fall into the default case rather than the INT16 or INT32 (etc) case
    // as UNITY_DISPLAY_STYLE_INT includes a flag for UNITY_DISPLAY_RANGE_AUTO, which the width-specific
    // variants do not. Therefore remove this flag.
436
    switch(style & (UNITY_DISPLAY_STYLE_T)(~UNITY_DISPLAY_RANGE_AUTO))
437 438
    {
        case UNITY_DISPLAY_STYLE_HEX8:
M
mvandervoord 已提交
439 440
        case UNITY_DISPLAY_STYLE_INT8:
        case UNITY_DISPLAY_STYLE_UINT8:
441 442
            while (elements--)
            {
M
mvandervoord 已提交
443
                if (*ptr_exp != *ptr_act)
444 445 446 447 448
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
M
mvandervoord 已提交
449
                    UnityPrintNumberByStyle(*ptr_exp, style);
450
                    UnityPrint(UnityStrWas);
M
mvandervoord 已提交
451
                    UnityPrintNumberByStyle(*ptr_act, style);
452 453 454
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
M
mvandervoord 已提交
455 456
                ptr_exp += 1;
                ptr_act += 1;
457 458 459
            }
            break;
        case UNITY_DISPLAY_STYLE_HEX16:
M
mvandervoord 已提交
460 461
        case UNITY_DISPLAY_STYLE_INT16:
        case UNITY_DISPLAY_STYLE_UINT16:
462 463
            while (elements--)
            {
464
                if (*(UNITY_PTR_ATTRIBUTE _US16*)ptr_exp != *(UNITY_PTR_ATTRIBUTE _US16*)ptr_act)
465 466 467 468 469
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
470
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US16*)ptr_exp, style);
471
                    UnityPrint(UnityStrWas);
472
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US16*)ptr_act, style);
473 474 475
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
M
mvandervoord 已提交
476 477
                ptr_exp += 2;
                ptr_act += 2;
478 479
            }
            break;
M
mvandervoord 已提交
480 481 482 483 484 485
#ifdef UNITY_SUPPORT_64
        case UNITY_DISPLAY_STYLE_HEX64:
        case UNITY_DISPLAY_STYLE_INT64:
        case UNITY_DISPLAY_STYLE_UINT64:
            while (elements--)
            {
486
                if (*(UNITY_PTR_ATTRIBUTE _US64*)ptr_exp != *(UNITY_PTR_ATTRIBUTE _US64*)ptr_act)
M
mvandervoord 已提交
487 488 489 490 491
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
492
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US64*)ptr_exp, style);
M
mvandervoord 已提交
493
                    UnityPrint(UnityStrWas);
494
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US64*)ptr_act, style);
M
mvandervoord 已提交
495 496 497 498 499 500 501 502
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
                ptr_exp += 8;
                ptr_act += 8;
            }
            break;
#endif
503 504 505
        default:
            while (elements--)
            {
506
                if (*(UNITY_PTR_ATTRIBUTE _US32*)ptr_exp != *(UNITY_PTR_ATTRIBUTE _US32*)ptr_act)
507 508 509 510 511
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
512
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US32*)ptr_exp, style);
513
                    UnityPrint(UnityStrWas);
514
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US32*)ptr_act, style);
515 516 517
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
M
mvandervoord 已提交
518 519
                ptr_exp += 4;
                ptr_act += 4;
520 521 522 523 524
            }
            break;
    }
}

M
mvandervoord 已提交
525
//-----------------------------------------------
526
#ifndef UNITY_EXCLUDE_FLOAT
527 528
void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
                                UNITY_PTR_ATTRIBUTE const _UF* actual,
529
                                const _UU32 num_elements,
530 531 532
                                const char* msg,
                                const UNITY_LINE_TYPE lineNumber)
{
533
    _UU32 elements = num_elements;
534 535
    UNITY_PTR_ATTRIBUTE const _UF* ptr_expected = expected;
    UNITY_PTR_ATTRIBUTE const _UF* ptr_actual = actual;
M
mvandervoord 已提交
536
    _UF diff, tol;
537

538
    UNITY_SKIP_EXECUTION;
539

540 541
    if (elements == 0)
    {
542
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
543 544 545
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
546
    }
547

548
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
549
        return;
550 551 552

    while (elements--)
    {
553
        diff = *ptr_expected - *ptr_actual;
554 555
        if (diff < 0.0f)
          diff = 0.0f - diff;
M
mvandervoord 已提交
556
        tol = UNITY_FLOAT_PRECISION * *ptr_expected;
557 558
        if (tol < 0.0f)
            tol = 0.0f - tol;
559

560 561
        //This first part of this condition will catch any NaN or Infinite values
        if ((diff * 0.0f != 0.0f) || (diff > tol))
562
        {
563
            UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
564
            UnityPrint(UnityStrElement);
565
            UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
566 567 568 569 570 571
#ifdef UNITY_FLOAT_VERBOSE
            UnityPrint(UnityStrExpected);
            UnityPrintFloat(*ptr_expected);
            UnityPrint(UnityStrWas);
            UnityPrintFloat(*ptr_actual);
#else
572
            UnityPrint(UnityStrDelta);
573
#endif
M
mvandervoord 已提交
574 575
            UnityAddMsgIfSpecified(msg);
            UNITY_FAIL_AND_BAIL;
M
mvandervoord 已提交
576
        }
577 578
        ptr_expected++;
        ptr_actual++;
M
mvandervoord 已提交
579 580 581
    }
}

M
mvandervoord 已提交
582
//-----------------------------------------------
583 584 585
void UnityAssertFloatsWithin(const _UF delta,
                             const _UF expected,
                             const _UF actual,
586
                             const char* msg,
M
mvandervoord 已提交
587
                             const UNITY_LINE_TYPE lineNumber)
G
greg-williams 已提交
588
{
589 590
    _UF diff = actual - expected;
    _UF pos_delta = delta;
591

592
    UNITY_SKIP_EXECUTION;
593

594
    if (diff < 0.0f)
G
greg-williams 已提交
595
    {
596
        diff = 0.0f - diff;
G
greg-williams 已提交
597
    }
598
    if (pos_delta < 0.0f)
599 600 601
    {
        pos_delta = 0.0f - pos_delta;
    }
602

603 604
    //This first part of this condition will catch any NaN or Infinite values
    if ((diff * 0.0f != 0.0f) || (pos_delta < diff))
G
greg-williams 已提交
605
    {
606
        UnityTestResultsFailBegin(lineNumber);
607 608 609 610 611 612
#ifdef UNITY_FLOAT_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrintFloat(expected);
        UnityPrint(UnityStrWas);
        UnityPrintFloat(actual);
#else
M
mvandervoord 已提交
613
        UnityPrint(UnityStrDelta);
614
#endif
M
mvandervoord 已提交
615 616
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
617 618
    }
}
M
mvandervoord 已提交
619

620
//-----------------------------------------------
621 622 623 624
void UnityAssertFloatSpecial(const _UF actual,
                             const char* msg,
                             const UNITY_LINE_TYPE lineNumber,
                             const UNITY_FLOAT_STYLE_T style)
625 626 627
{
    UNITY_SKIP_EXECUTION;

628
    const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
629 630 631
    _U_SINT should_be_trait   = ((_U_SINT)style & 1);
    _U_SINT is_trait          = !should_be_trait;
    _U_SINT trait_index       = style >> 1;
632

633
    switch(style)
634
    {
635 636 637 638 639 640 641 642 643 644
        //To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly
        //We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise
        case UNITY_FLOAT_IS_INF:
        case UNITY_FLOAT_IS_NOT_INF:
            is_trait = ((1.0f / f_zero) == actual) ? 1 : 0;
            break;
        case UNITY_FLOAT_IS_NEG_INF:
        case UNITY_FLOAT_IS_NOT_NEG_INF:
            is_trait = ((-1.0f / f_zero) == actual) ? 1 : 0;
            break;
645

646 647 648 649 650
        //NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN.
        case UNITY_FLOAT_IS_NAN:
        case UNITY_FLOAT_IS_NOT_NAN:
            is_trait = (actual == actual) ? 0 : 1;
            break;
651 652 653 654 655 656 657 658 659

        //A determinate number is non infinite and not NaN. (therefore the opposite of the two above)
        case UNITY_FLOAT_IS_DET:
        case UNITY_FLOAT_IS_NOT_DET:
            if ( (actual != actual) || ((1.0f / f_zero) == actual) || ((-1.0f / f_zero) == actual) )
                is_trait = 0;
            else
                is_trait = 1;
            break;
660
    }
661

662
    if (is_trait != should_be_trait)
663 664 665
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrExpected);
666
        if (!should_be_trait)
667
            UnityPrint(UnityStrNot);
668
        UnityPrint(trait_names[trait_index]);
669
        UnityPrint(UnityStrWas);
670
#ifdef UNITY_FLOAT_VERBOSE
671 672
        UnityPrintFloat(actual);
#else
673
        if (should_be_trait)
674
            UnityPrint(UnityStrNot);
675
        UnityPrint(trait_names[trait_index]);
676 677 678 679 680 681
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

M
mvandervoord 已提交
682 683 684 685
#endif //not UNITY_EXCLUDE_FLOAT

//-----------------------------------------------
#ifndef UNITY_EXCLUDE_DOUBLE
686 687
void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
                                 UNITY_PTR_ATTRIBUTE const _UD* actual,
M
mvandervoord 已提交
688 689 690 691 692
                                 const _UU32 num_elements,
                                 const char* msg,
                                 const UNITY_LINE_TYPE lineNumber)
{
    _UU32 elements = num_elements;
693 694
    UNITY_PTR_ATTRIBUTE const _UD* ptr_expected = expected;
    UNITY_PTR_ATTRIBUTE const _UD* ptr_actual = actual;
M
mvandervoord 已提交
695 696 697
    _UD diff, tol;

    UNITY_SKIP_EXECUTION;
698

M
mvandervoord 已提交
699 700 701 702 703 704 705
    if (elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
706

707
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
M
mvandervoord 已提交
708 709 710 711 712 713 714 715 716 717
        return;

    while (elements--)
    {
        diff = *ptr_expected - *ptr_actual;
        if (diff < 0.0)
          diff = 0.0 - diff;
        tol = UNITY_DOUBLE_PRECISION * *ptr_expected;
        if (tol < 0.0)
            tol = 0.0 - tol;
718

719
        //This first part of this condition will catch any NaN or Infinite values
720
        if ((diff * 0.0 != 0.0) || (diff > tol))
M
mvandervoord 已提交
721 722 723 724 725 726 727 728 729 730 731
        {
            UnityTestResultsFailBegin(lineNumber);
            UnityPrint(UnityStrElement);
            UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
#ifdef UNITY_DOUBLE_VERBOSE
            UnityPrint(UnityStrExpected);
            UnityPrintFloat((float)(*ptr_expected));
            UnityPrint(UnityStrWas);
            UnityPrintFloat((float)(*ptr_actual));
#else
            UnityPrint(UnityStrDelta);
732
#endif
M
mvandervoord 已提交
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
            UnityAddMsgIfSpecified(msg);
            UNITY_FAIL_AND_BAIL;
        }
        ptr_expected++;
        ptr_actual++;
    }
}

//-----------------------------------------------
void UnityAssertDoublesWithin(const _UD delta,
                              const _UD expected,
                              const _UD actual,
                              const char* msg,
                              const UNITY_LINE_TYPE lineNumber)
{
    _UD diff = actual - expected;
    _UD pos_delta = delta;

    UNITY_SKIP_EXECUTION;
752

753
    if (diff < 0.0)
M
mvandervoord 已提交
754
    {
755
        diff = 0.0 - diff;
M
mvandervoord 已提交
756
    }
757
    if (pos_delta < 0.0)
M
mvandervoord 已提交
758
    {
759
        pos_delta = 0.0 - pos_delta;
M
mvandervoord 已提交
760 761
    }

762
    //This first part of this condition will catch any NaN or Infinite values
763
    if ((diff * 0.0 != 0.0) || (pos_delta < diff))
M
mvandervoord 已提交
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
    {
        UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_DOUBLE_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrintFloat((float)expected);
        UnityPrint(UnityStrWas);
        UnityPrintFloat((float)actual);
#else
        UnityPrint(UnityStrDelta);
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

779
//-----------------------------------------------
780 781 782 783 784

void UnityAssertDoubleSpecial(const _UD actual,
                              const char* msg,
                              const UNITY_LINE_TYPE lineNumber,
                              const UNITY_FLOAT_STYLE_T style)
785 786 787
{
    UNITY_SKIP_EXECUTION;

788 789 790 791 792 793
    const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
    _U_SINT should_be_trait   = ((_U_SINT)style & 1);
    _U_SINT is_trait          = !should_be_trait;
    _U_SINT trait_index       = style >> 1;

    switch(style)
794
    {
795 796 797 798 799 800 801 802 803 804
        //To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly
        //We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise
        case UNITY_FLOAT_IS_INF:
        case UNITY_FLOAT_IS_NOT_INF:
            is_trait = ((1.0 / d_zero) == actual) ? 1 : 0;
            break;
        case UNITY_FLOAT_IS_NEG_INF:
        case UNITY_FLOAT_IS_NOT_NEG_INF:
            is_trait = ((-1.0 / d_zero) == actual) ? 1 : 0;
            break;
805

806 807 808 809 810
        //NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN.
        case UNITY_FLOAT_IS_NAN:
        case UNITY_FLOAT_IS_NOT_NAN:
            is_trait = (actual == actual) ? 0 : 1;
            break;
811

812 813 814 815 816 817 818 819
        //A determinate number is non infinite and not NaN. (therefore the opposite of the two above)
        case UNITY_FLOAT_IS_DET:
        case UNITY_FLOAT_IS_NOT_DET:
            if ( (actual != actual) || ((1.0 / d_zero) == actual) || ((-1.0 / d_zero) == actual) )
                is_trait = 0;
            else
                is_trait = 1;
            break;
820 821
    }

822
    if (is_trait != should_be_trait)
823 824 825
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrExpected);
826 827 828
        if (!should_be_trait)
            UnityPrint(UnityStrNot);
        UnityPrint(trait_names[trait_index]);
829
        UnityPrint(UnityStrWas);
830 831
#ifdef UNITY_DOUBLE_VERBOSE
        UnityPrintFloat(actual);
832
#else
833 834 835
        if (should_be_trait)
            UnityPrint(UnityStrNot);
        UnityPrint(trait_names[trait_index]);
836 837 838 839 840 841
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

842

M
mvandervoord 已提交
843
#endif // not UNITY_EXCLUDE_DOUBLE
G
greg-williams 已提交
844

M
mvandervoord 已提交
845
//-----------------------------------------------
M
mvandervoord 已提交
846 847 848
void UnityAssertNumbersWithin( const _U_SINT delta,
                               const _U_SINT expected,
                               const _U_SINT actual,
M
mvandervoord 已提交
849 850 851
                               const char* msg,
                               const UNITY_LINE_TYPE lineNumber,
                               const UNITY_DISPLAY_STYLE_T style)
G
greg-williams 已提交
852
{
853
    UNITY_SKIP_EXECUTION;
854

M
mvandervoord 已提交
855
    if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
G
greg-williams 已提交
856
    {
M
mvandervoord 已提交
857 858 859 860
        if (actual > expected)
          Unity.CurrentTestFailed = ((actual - expected) > delta);
        else
          Unity.CurrentTestFailed = ((expected - actual) > delta);
G
greg-williams 已提交
861
    }
M
mvandervoord 已提交
862
    else
G
greg-williams 已提交
863
    {
M
mvandervoord 已提交
864 865
        if ((_U_UINT)actual > (_U_UINT)expected)
            Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
M
mvandervoord 已提交
866
        else
M
mvandervoord 已提交
867
            Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
868 869
    }

M
mvandervoord 已提交
870
    if (Unity.CurrentTestFailed)
871
    {
872
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
873 874 875 876 877 878 879 880
        UnityPrint(UnityStrDelta);
        UnityPrintNumberByStyle(delta, style);
        UnityPrint(UnityStrExpected);
        UnityPrintNumberByStyle(expected, style);
        UnityPrint(UnityStrWas);
        UnityPrintNumberByStyle(actual, style);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
881 882 883
    }
}

M
mvandervoord 已提交
884
//-----------------------------------------------
885 886 887
void UnityAssertEqualString(const char* expected,
                            const char* actual,
                            const char* msg,
M
mvandervoord 已提交
888
                            const UNITY_LINE_TYPE lineNumber)
G
greg-williams 已提交
889
{
890
    _UU32 i;
G
greg-williams 已提交
891

892
    UNITY_SKIP_EXECUTION;
893

G
greg-williams 已提交
894 895 896 897 898 899 900 901
    // if both pointers not null compare the strings
    if (expected && actual)
    {
        for (i = 0; expected[i] || actual[i]; i++)
        {
            if (expected[i] != actual[i])
            {
                Unity.CurrentTestFailed = 1;
902
                break;
G
greg-williams 已提交
903 904 905 906 907 908 909 910 911 912 913 914 915
            }
        }
    }
    else
    { // handle case of one pointers being null (if both null, test should pass)
        if (expected != actual)
        {
            Unity.CurrentTestFailed = 1;
        }
    }

    if (Unity.CurrentTestFailed)
    {
916
      UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
917
      UnityPrintExpectedAndActualStrings(expected, actual);
918 919
      UnityAddMsgIfSpecified(msg);
      UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
920 921 922
    }
}

M
mvandervoord 已提交
923 924 925 926 927 928 929 930
//-----------------------------------------------
void UnityAssertEqualStringArray( const char** expected,
                                  const char** actual,
                                  const _UU32 num_elements,
                                  const char* msg,
                                  const UNITY_LINE_TYPE lineNumber)
{
    _UU32 i, j = 0;
931

932
    UNITY_SKIP_EXECUTION;
933

M
mvandervoord 已提交
934 935 936 937 938 939 940 941 942
    // if no elements, it's an error
    if (num_elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }

943
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
944
        return;
945

M
mvandervoord 已提交
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
    do
    {
        // if both pointers not null compare the strings
        if (expected[j] && actual[j])
        {
            for (i = 0; expected[j][i] || actual[j][i]; i++)
            {
                if (expected[j][i] != actual[j][i])
                {
                    Unity.CurrentTestFailed = 1;
                    break;
                }
            }
        }
        else
        { // handle case of one pointers being null (if both null, test should pass)
            if (expected[j] != actual[j])
            {
                Unity.CurrentTestFailed = 1;
            }
        }

        if (Unity.CurrentTestFailed)
        {
            UnityTestResultsFailBegin(lineNumber);
            if (num_elements > 1)
            {
                UnityPrint(UnityStrElement);
974
                UnityPrintNumberByStyle((j), UNITY_DISPLAY_STYLE_UINT);
M
mvandervoord 已提交
975
            }
M
mvandervoord 已提交
976
            UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
M
mvandervoord 已提交
977 978
            UnityAddMsgIfSpecified(msg);
            UNITY_FAIL_AND_BAIL;
979
        }
M
mvandervoord 已提交
980 981 982 983
    } while (++j < num_elements);
}

//-----------------------------------------------
984 985
void UnityAssertEqualMemory( UNITY_PTR_ATTRIBUTE const void* expected,
                             UNITY_PTR_ATTRIBUTE const void* actual,
986 987
                             const _UU32 length,
                             const _UU32 num_elements,
M
mvandervoord 已提交
988 989
                             const char* msg,
                             const UNITY_LINE_TYPE lineNumber)
990
{
991 992
    UNITY_PTR_ATTRIBUTE unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE unsigned char*)expected;
    UNITY_PTR_ATTRIBUTE unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE unsigned char*)actual;
993
    _UU32 elements = num_elements;
994
    _UU32 bytes;
995 996

    UNITY_SKIP_EXECUTION;
997

998 999
    if ((elements == 0) || (length == 0))
    {
1000
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
1001 1002 1003
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
1004
    }
1005

1006
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
1007
        return;
1008

1009
    while (elements--)
1010
    {
1011 1012 1013
        /////////////////////////////////////
        bytes = length;
        while (bytes--)
1014
        {
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
            if (*ptr_exp != *ptr_act)
            {
                UnityTestResultsFailBegin(lineNumber);
                UnityPrint(UnityStrMemory);
                if (num_elements > 1)
                {
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                }
                UnityPrint(UnityStrByte);
                UnityPrintNumberByStyle((length - bytes - 1), UNITY_DISPLAY_STYLE_UINT);
                UnityPrint(UnityStrExpected);
                UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8);
                UnityPrint(UnityStrWas);
                UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8);
                UnityAddMsgIfSpecified(msg);
                UNITY_FAIL_AND_BAIL;
            }
            ptr_exp += 1;
            ptr_act += 1;
1035
        }
1036
        /////////////////////////////////////
1037

1038 1039 1040
    }
}

M
mvandervoord 已提交
1041 1042 1043 1044 1045
//-----------------------------------------------
// Control Functions
//-----------------------------------------------

void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
1046
{
1047 1048
    UNITY_SKIP_EXECUTION;

M
mvandervoord 已提交
1049
    UnityTestResultsBegin(Unity.TestFile, line);
1050
    UnityPrintFail();
M
mvandervoord 已提交
1051
    if (msg != NULL)
1052 1053
    {
      UNITY_OUTPUT_CHAR(':');
1054 1055
      if (msg[0] != ' ')
      {
1056
        UNITY_OUTPUT_CHAR(' ');
M
mvandervoord 已提交
1057
      }
M
mvandervoord 已提交
1058
      UnityPrint(msg);
1059
    }
M
mvandervoord 已提交
1060
    UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
1061 1062
}

M
mvandervoord 已提交
1063
//-----------------------------------------------
M
mvandervoord 已提交
1064
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
1065
{
1066 1067
    UNITY_SKIP_EXECUTION;

M
mvandervoord 已提交
1068
    UnityTestResultsBegin(Unity.TestFile, line);
1069
    UnityPrint("IGNORE");
M
mvandervoord 已提交
1070
    if (msg != NULL)
1071 1072
    {
      UNITY_OUTPUT_CHAR(':');
1073
      UNITY_OUTPUT_CHAR(' ');
M
mvandervoord 已提交
1074
      UnityPrint(msg);
1075
    }
M
mvandervoord 已提交
1076
    UNITY_IGNORE_AND_BAIL;
G
greg-williams 已提交
1077 1078
}

1079
//-----------------------------------------------
1080
#ifdef UNITY_SUPPORT_WEAK
1081 1082
UNITY_WEAK void setUp(void) { }
UNITY_WEAK void tearDown(void) { }
1083
#else
1084 1085
void setUp(void);
void tearDown(void);
1086 1087
#endif
//-----------------------------------------------
1088 1089 1090
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
{
    Unity.CurrentTestName = FuncName;
1091
    Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum;
1092
    Unity.NumberOfTests++;
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
    if (TEST_PROTECT())
    {
        setUp();
        Func();
    }
    if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
    {
        tearDown();
    }
    UnityConcludeTest();
}

M
mvandervoord 已提交
1105
//-----------------------------------------------
1106
void UnityBegin(void)
G
greg-williams 已提交
1107
{
1108 1109 1110
    Unity.TestFile = NULL;
    Unity.CurrentTestName = NULL;
    Unity.CurrentTestLineNumber = 0;
G
greg-williams 已提交
1111
    Unity.NumberOfTests = 0;
1112 1113 1114 1115
    Unity.TestFailures = 0;
    Unity.TestIgnores = 0;
    Unity.CurrentTestFailed = 0;
    Unity.CurrentTestIgnored = 0;
G
greg-williams 已提交
1116 1117
}

M
mvandervoord 已提交
1118
//-----------------------------------------------
1119
int UnityEnd(void)
G
greg-williams 已提交
1120
{
1121
    UNITY_PRINT_EOL;
M
mvandervoord 已提交
1122
    UnityPrint("-----------------------");
M
mvandervoord 已提交
1123
    UNITY_PRINT_EOL;
1124
    UnityPrintNumber((_U_SINT)(Unity.NumberOfTests));
G
greg-williams 已提交
1125
    UnityPrint(" Tests ");
1126
    UnityPrintNumber((_U_SINT)(Unity.TestFailures));
G
greg-williams 已提交
1127
    UnityPrint(" Failures ");
1128
    UnityPrintNumber((_U_SINT)(Unity.TestIgnores));
M
mvandervoord 已提交
1129
    UnityPrint(" Ignored");
M
mvandervoord 已提交
1130
    UNITY_PRINT_EOL;
G
greg-williams 已提交
1131 1132
    if (Unity.TestFailures == 0U)
    {
1133
        UnityPrintOk();
G
greg-williams 已提交
1134 1135 1136
    }
    else
    {
1137
        UnityPrintFail();
G
greg-williams 已提交
1138
    }
M
mvandervoord 已提交
1139
    UNITY_PRINT_EOL;
1140
    return (int)(Unity.TestFailures);
G
greg-williams 已提交
1141
}
1142 1143 1144 1145

//-----------------------------------------------