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

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

M
mvandervoord 已提交
11 12
#define UNITY_FAIL_AND_BAIL   { Unity.CurrentTestFailed  = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); 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 = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , {{{ 0 }}} };
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 32 33
const char* UnityStrInf      = "Infinity";
const char* UnityStrNegInf   = "Negative Infinity";
const char* UnityStrNaN      = "NaN";
M
mvandervoord 已提交
34

35
#ifndef UNITY_EXCLUDE_FLOAT
36 37 38 39 40 41
// 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
42
#endif
43

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

59 60 61
void UnityPrintFail(void);
void UnityPrintOk(void);

M
mvandervoord 已提交
62
//-----------------------------------------------
63
// Pretty Printers & Test Result Output Handlers
M
mvandervoord 已提交
64 65
//-----------------------------------------------

66
void UnityPrint(const char* string)
G
greg-williams 已提交
67
{
68
    const char* pch = string;
G
greg-williams 已提交
69 70 71 72 73

    if (pch != NULL)
    {
        while (*pch)
        {
M
mvandervoord 已提交
74
            // printable characters plus CR & LF are printed
M
mvandervoord 已提交
75
            if ((*pch <= 126) && (*pch >= 32))
M
mvandervoord 已提交
76 77 78
            {
                UNITY_OUTPUT_CHAR(*pch);
            }
M
mvandervoord 已提交
79 80 81 82 83 84 85 86 87 88 89 90
            //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 已提交
91 92 93 94
            // unprintable characters are shown as codes
            else
            {
                UNITY_OUTPUT_CHAR('\\');
M
mvandervoord 已提交
95
                UnityPrintNumberHex((_U_SINT)*pch, 2);
M
mvandervoord 已提交
96
            }
G
greg-williams 已提交
97 98 99 100 101
            pch++;
        }
    }
}

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

M
mvandervoord 已提交
119
//-----------------------------------------------
G
greg-williams 已提交
120
/// basically do an itoa using as little ram as possible
M
mvandervoord 已提交
121
void UnityPrintNumber(const _U_SINT number_to_print)
G
greg-williams 已提交
122
{
M
mvandervoord 已提交
123 124 125
    _U_SINT divisor = 1;
    _U_SINT next_divisor;
    _U_SINT number = number_to_print;
G
greg-williams 已提交
126 127 128

    if (number < 0)
    {
129
        UNITY_OUTPUT_CHAR('-');
G
greg-williams 已提交
130 131 132 133
        number = -number;
    }

    // figure out initial divisor
M
mvandervoord 已提交
134
    while (number / divisor > 9)
G
greg-williams 已提交
135
    {
M
mvandervoord 已提交
136 137 138 139 140
        next_divisor = divisor * 10;
        if (next_divisor > divisor)
            divisor = next_divisor;
        else
            break;
G
greg-williams 已提交
141 142
    }

M
mvandervoord 已提交
143
    // now mod and print, then divide divisor
G
greg-williams 已提交
144 145
    do
    {
146
        UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
M
mvandervoord 已提交
147
        divisor /= 10;
G
greg-williams 已提交
148
    }
M
mvandervoord 已提交
149
    while (divisor > 0);
G
greg-williams 已提交
150 151
}

M
mvandervoord 已提交
152
//-----------------------------------------------
G
greg-williams 已提交
153
/// basically do an itoa using as little ram as possible
M
mvandervoord 已提交
154
void UnityPrintNumberUnsigned(const _U_UINT number)
G
greg-williams 已提交
155
{
M
mvandervoord 已提交
156 157
    _U_UINT divisor = 1;
    _U_UINT next_divisor;
G
greg-williams 已提交
158 159

    // figure out initial divisor
M
mvandervoord 已提交
160
    while (number / divisor > 9)
G
greg-williams 已提交
161
    {
M
mvandervoord 已提交
162 163 164 165 166
        next_divisor = divisor * 10;
        if (next_divisor > divisor)
            divisor = next_divisor;
        else
            break;
G
greg-williams 已提交
167 168
    }

M
mvandervoord 已提交
169
    // now mod and print, then divide divisor
G
greg-williams 已提交
170 171
    do
    {
172
        UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
M
mvandervoord 已提交
173
        divisor /= 10;
G
greg-williams 已提交
174
    }
M
mvandervoord 已提交
175
    while (divisor > 0);
G
greg-williams 已提交
176 177
}

M
mvandervoord 已提交
178
//-----------------------------------------------
M
mvandervoord 已提交
179
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
G
greg-williams 已提交
180
{
M
mvandervoord 已提交
181
    _U_UINT nibble;
M
mvandervoord 已提交
182
    char nibbles = nibbles_to_print;
183 184
    UNITY_OUTPUT_CHAR('0');
    UNITY_OUTPUT_CHAR('x');
G
greg-williams 已提交
185 186 187 188 189 190

    while (nibbles > 0)
    {
        nibble = (number >> (--nibbles << 2)) & 0x0000000F;
        if (nibble <= 9)
        {
191
            UNITY_OUTPUT_CHAR((char)('0' + nibble));
G
greg-williams 已提交
192 193 194
        }
        else
        {
195
            UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
G
greg-williams 已提交
196 197 198 199
        }
    }
}

M
mvandervoord 已提交
200
//-----------------------------------------------
M
mvandervoord 已提交
201
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
G
greg-williams 已提交
202
{
203
    _U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
204
    _US32 i;
G
greg-williams 已提交
205

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

M
mvandervoord 已提交
227
//-----------------------------------------------
228 229 230 231 232 233 234 235 236
#ifdef UNITY_FLOAT_VERBOSE
void UnityPrintFloat(_UF number)
{
    char TempBuffer[32];
    sprintf(TempBuffer, "%.6f", number);
    UnityPrint(TempBuffer);
}
#endif

237 238 239 240 241 242 243 244 245 246 247 248
//-----------------------------------------------

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

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

M
mvandervoord 已提交
249
//-----------------------------------------------
M
mvandervoord 已提交
250
void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
251
{
252
    UNITY_PRINT_EOL;
253
    UnityPrint(file);
254
    UNITY_OUTPUT_CHAR(':');
G
greg-williams 已提交
255
    UnityPrintNumber(line);
256
    UNITY_OUTPUT_CHAR(':');
G
greg-williams 已提交
257
    UnityPrint(Unity.CurrentTestName);
258
    UNITY_OUTPUT_CHAR(':');
G
greg-williams 已提交
259 260
}

M
mvandervoord 已提交
261
//-----------------------------------------------
M
mvandervoord 已提交
262
void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
263
{
M
mvandervoord 已提交
264
    UnityTestResultsBegin(Unity.TestFile, line);
265 266 267
    UnityPrint("FAIL:");
}

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

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

M
mvandervoord 已提交
290
//-----------------------------------------------
M
mvandervoord 已提交
291 292 293 294 295 296 297 298 299
void UnityAddMsgIfSpecified(const char* msg)
{
    if (msg)
    {
        UnityPrint(UnityStrSpacer);
        UnityPrint(msg);
    }
}

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

327 328 329 330
//-----------------------------------------------
// Assertion & Control Helpers
//-----------------------------------------------

331
int UnityCheckArraysForNull(UNITY_PTR_ATTRIBUTE const void* expected, UNITY_PTR_ATTRIBUTE const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
332 333 334 335
{
    //return true if they are both NULL
    if ((expected == NULL) && (actual == NULL))
        return 1;
336

337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
    //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;
    }
354

355 356 357
    //return false if neither is NULL
    return 0;
}
358

M
mvandervoord 已提交
359 360 361 362
//-----------------------------------------------
// Assertion Functions
//-----------------------------------------------

M
mvandervoord 已提交
363 364 365
void UnityAssertBits(const _U_SINT mask,
                     const _U_SINT expected,
                     const _U_SINT actual,
366
                     const char* msg,
M
mvandervoord 已提交
367
                     const UNITY_LINE_TYPE lineNumber)
G
greg-williams 已提交
368
{
369
    UNITY_SKIP_EXECUTION;
370

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

M
mvandervoord 已提交
383
//-----------------------------------------------
M
mvandervoord 已提交
384 385
void UnityAssertEqualNumber(const _U_SINT expected,
                            const _U_SINT actual,
M
mvandervoord 已提交
386 387 388
                            const char* msg,
                            const UNITY_LINE_TYPE lineNumber,
                            const UNITY_DISPLAY_STYLE_T style)
389
{
390 391
    UNITY_SKIP_EXECUTION;

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

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

416
    UNITY_SKIP_EXECUTION;
417

418 419 420 421 422 423 424
    if (elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
425

426
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
427
        return;
428

429 430 431 432
    // 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.
    switch(style & ~UNITY_DISPLAY_RANGE_AUTO)
433 434
    {
        case UNITY_DISPLAY_STYLE_HEX8:
M
mvandervoord 已提交
435 436
        case UNITY_DISPLAY_STYLE_INT8:
        case UNITY_DISPLAY_STYLE_UINT8:
437 438
            while (elements--)
            {
M
mvandervoord 已提交
439
                if (*ptr_exp != *ptr_act)
440 441 442 443 444
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
M
mvandervoord 已提交
445
                    UnityPrintNumberByStyle(*ptr_exp, style);
446
                    UnityPrint(UnityStrWas);
M
mvandervoord 已提交
447
                    UnityPrintNumberByStyle(*ptr_act, style);
448 449 450
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
M
mvandervoord 已提交
451 452
                ptr_exp += 1;
                ptr_act += 1;
453 454 455
            }
            break;
        case UNITY_DISPLAY_STYLE_HEX16:
M
mvandervoord 已提交
456 457
        case UNITY_DISPLAY_STYLE_INT16:
        case UNITY_DISPLAY_STYLE_UINT16:
458 459
            while (elements--)
            {
460
                if (*(UNITY_PTR_ATTRIBUTE _US16*)ptr_exp != *(UNITY_PTR_ATTRIBUTE _US16*)ptr_act)
461 462 463 464 465
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
466
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US16*)ptr_exp, style);
467
                    UnityPrint(UnityStrWas);
468
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US16*)ptr_act, style);
469 470 471
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
M
mvandervoord 已提交
472 473
                ptr_exp += 2;
                ptr_act += 2;
474 475
            }
            break;
M
mvandervoord 已提交
476 477 478 479 480 481
#ifdef UNITY_SUPPORT_64
        case UNITY_DISPLAY_STYLE_HEX64:
        case UNITY_DISPLAY_STYLE_INT64:
        case UNITY_DISPLAY_STYLE_UINT64:
            while (elements--)
            {
482
                if (*(UNITY_PTR_ATTRIBUTE _US64*)ptr_exp != *(UNITY_PTR_ATTRIBUTE _US64*)ptr_act)
M
mvandervoord 已提交
483 484 485 486 487
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
488
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US64*)ptr_exp, style);
M
mvandervoord 已提交
489
                    UnityPrint(UnityStrWas);
490
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US64*)ptr_act, style);
M
mvandervoord 已提交
491 492 493 494 495 496 497 498
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
                ptr_exp += 8;
                ptr_act += 8;
            }
            break;
#endif
499 500 501
        default:
            while (elements--)
            {
502
                if (*(UNITY_PTR_ATTRIBUTE _US32*)ptr_exp != *(UNITY_PTR_ATTRIBUTE _US32*)ptr_act)
503 504 505 506 507
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
508
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US32*)ptr_exp, style);
509
                    UnityPrint(UnityStrWas);
510
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US32*)ptr_act, style);
511 512 513
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
M
mvandervoord 已提交
514 515
                ptr_exp += 4;
                ptr_act += 4;
516 517 518 519 520
            }
            break;
    }
}

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

534
    UNITY_SKIP_EXECUTION;
535

536 537
    if (elements == 0)
    {
538
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
539 540 541
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
542
    }
543

544
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
545
        return;
546 547 548

    while (elements--)
    {
549
        diff = *ptr_expected - *ptr_actual;
550 551
        if (diff < 0.0f)
          diff = 0.0f - diff;
M
mvandervoord 已提交
552
        tol = UNITY_FLOAT_PRECISION * *ptr_expected;
553 554
        if (tol < 0.0f)
            tol = 0.0f - tol;
555

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

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

588
    UNITY_SKIP_EXECUTION;
589

590
    if (diff < 0.0f)
G
greg-williams 已提交
591
    {
592
        diff = 0.0f - diff;
G
greg-williams 已提交
593
    }
594
    if (pos_delta < 0.0f)
595 596 597
    {
        pos_delta = 0.0f - pos_delta;
    }
598

599 600
    //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 已提交
601
    {
602
        UnityTestResultsFailBegin(lineNumber);
603 604 605 606 607 608
#ifdef UNITY_FLOAT_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrintFloat(expected);
        UnityPrint(UnityStrWas);
        UnityPrintFloat(actual);
#else
M
mvandervoord 已提交
609
        UnityPrint(UnityStrDelta);
610
#endif
M
mvandervoord 已提交
611 612
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
613 614
    }
}
M
mvandervoord 已提交
615

616 617 618 619 620 621 622
//-----------------------------------------------
void UnityAssertFloatIsInf(const _UF actual,
                           const char* msg,
                           const UNITY_LINE_TYPE lineNumber)
{
    UNITY_SKIP_EXECUTION;

623 624 625 626 627 628
    // In Microsoft Visual C++ Express Edition 2008,
    //   if ((1.0f / f_zero) != actual)
    // produces
    //   error C2124: divide or mod by zero
    // As a workaround, place 0 into a variable.
    if ((1.0f / f_zero) != actual)
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
    {
        UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrint(UnityStrInf);
        UnityPrint(UnityStrWas);
        UnityPrintFloat(actual);
#else
        UnityPrint(UnityStrDelta);
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

//-----------------------------------------------
void UnityAssertFloatIsNegInf(const _UF actual,
                              const char* msg,
                              const UNITY_LINE_TYPE lineNumber)
{
    UNITY_SKIP_EXECUTION;

651 652
    // The rationale for not using 1.0f/0.0f is given in UnityAssertFloatIsInf's body.
    if ((-1.0f / f_zero) != actual)
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
    {
        UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrint(UnityStrNegInf);
        UnityPrint(UnityStrWas);
        UnityPrintFloat(actual);
#else
        UnityPrint(UnityStrDelta);
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

//-----------------------------------------------
void UnityAssertFloatIsNaN(const _UF actual,
                           const char* msg,
                           const UNITY_LINE_TYPE lineNumber)
{
    UNITY_SKIP_EXECUTION;

    if (actual == actual)
    {
        UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_FLOAT_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrint(UnityStrNaN);
        UnityPrint(UnityStrWas);
        UnityPrintFloat(actual);
#else
        UnityPrint(UnityStrDelta);
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

M
mvandervoord 已提交
691 692 693 694
#endif //not UNITY_EXCLUDE_FLOAT

//-----------------------------------------------
#ifndef UNITY_EXCLUDE_DOUBLE
695 696
void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
                                 UNITY_PTR_ATTRIBUTE const _UD* actual,
M
mvandervoord 已提交
697 698 699 700 701
                                 const _UU32 num_elements,
                                 const char* msg,
                                 const UNITY_LINE_TYPE lineNumber)
{
    _UU32 elements = num_elements;
702 703
    UNITY_PTR_ATTRIBUTE const _UD* ptr_expected = expected;
    UNITY_PTR_ATTRIBUTE const _UD* ptr_actual = actual;
M
mvandervoord 已提交
704 705 706
    _UD diff, tol;

    UNITY_SKIP_EXECUTION;
707

M
mvandervoord 已提交
708 709 710 711 712 713 714
    if (elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
715

716
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
M
mvandervoord 已提交
717 718 719 720 721 722 723 724 725 726
        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;
727

728
        //This first part of this condition will catch any NaN or Infinite values
729
        if ((diff * 0.0 != 0.0) || (diff > tol))
M
mvandervoord 已提交
730 731 732 733 734 735 736 737 738 739 740
        {
            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);
741
#endif
M
mvandervoord 已提交
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
            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;
761

762
    if (diff < 0.0)
M
mvandervoord 已提交
763
    {
764
        diff = 0.0 - diff;
M
mvandervoord 已提交
765
    }
766
    if (pos_delta < 0.0)
M
mvandervoord 已提交
767
    {
768
        pos_delta = 0.0 - pos_delta;
M
mvandervoord 已提交
769 770
    }

771
    //This first part of this condition will catch any NaN or Infinite values
772
    if ((diff * 0.0 != 0.0) || (pos_delta < diff))
M
mvandervoord 已提交
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
    {
        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;
    }
}

788 789 790 791 792 793 794
//-----------------------------------------------
void UnityAssertDoubleIsInf(const _UD actual,
                            const char* msg,
                            const UNITY_LINE_TYPE lineNumber)
{
    UNITY_SKIP_EXECUTION;

795 796
    // The rationale for not using 1.0/0.0 is given in UnityAssertFloatIsInf's body.
    if ((1.0 / d_zero) != actual)
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
    {
        UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_DOUBLE_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrint(UnityStrInf);
        UnityPrint(UnityStrWas);
        UnityPrintFloat((float)actual);
#else
        UnityPrint(UnityStrDelta);
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

//-----------------------------------------------
void UnityAssertDoubleIsNegInf(const _UD actual,
                               const char* msg,
                               const UNITY_LINE_TYPE lineNumber)
{
    UNITY_SKIP_EXECUTION;

819 820
    // The rationale for not using 1.0/0.0 is given in UnityAssertFloatIsInf's body.
    if ((-1.0 / d_zero) != actual)
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
    {
        UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_DOUBLE_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrint(UnityStrNegInf);
        UnityPrint(UnityStrWas);
        UnityPrintFloat((float)actual);
#else
        UnityPrint(UnityStrDelta);
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

//-----------------------------------------------
void UnityAssertDoubleIsNaN(const _UD actual,
                            const char* msg,
                            const UNITY_LINE_TYPE lineNumber)
{
    UNITY_SKIP_EXECUTION;

    if (actual == actual)
    {
        UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_DOUBLE_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrint(UnityStrNaN);
        UnityPrint(UnityStrWas);
        UnityPrintFloat((float)actual);
#else
        UnityPrint(UnityStrDelta);
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

M
mvandervoord 已提交
859
#endif // not UNITY_EXCLUDE_DOUBLE
G
greg-williams 已提交
860

M
mvandervoord 已提交
861
//-----------------------------------------------
M
mvandervoord 已提交
862 863 864
void UnityAssertNumbersWithin( const _U_SINT delta,
                               const _U_SINT expected,
                               const _U_SINT actual,
M
mvandervoord 已提交
865 866 867
                               const char* msg,
                               const UNITY_LINE_TYPE lineNumber,
                               const UNITY_DISPLAY_STYLE_T style)
G
greg-williams 已提交
868
{
869
    UNITY_SKIP_EXECUTION;
870

M
mvandervoord 已提交
871
    if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
G
greg-williams 已提交
872
    {
M
mvandervoord 已提交
873 874 875 876
        if (actual > expected)
          Unity.CurrentTestFailed = ((actual - expected) > delta);
        else
          Unity.CurrentTestFailed = ((expected - actual) > delta);
G
greg-williams 已提交
877
    }
M
mvandervoord 已提交
878
    else
G
greg-williams 已提交
879
    {
M
mvandervoord 已提交
880 881
        if ((_U_UINT)actual > (_U_UINT)expected)
            Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
M
mvandervoord 已提交
882
        else
M
mvandervoord 已提交
883
            Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
884 885
    }

M
mvandervoord 已提交
886
    if (Unity.CurrentTestFailed)
887
    {
888
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
889 890 891 892 893 894 895 896
        UnityPrint(UnityStrDelta);
        UnityPrintNumberByStyle(delta, style);
        UnityPrint(UnityStrExpected);
        UnityPrintNumberByStyle(expected, style);
        UnityPrint(UnityStrWas);
        UnityPrintNumberByStyle(actual, style);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
897 898 899
    }
}

M
mvandervoord 已提交
900
//-----------------------------------------------
901 902 903
void UnityAssertEqualString(const char* expected,
                            const char* actual,
                            const char* msg,
M
mvandervoord 已提交
904
                            const UNITY_LINE_TYPE lineNumber)
G
greg-williams 已提交
905
{
906
    _UU32 i;
G
greg-williams 已提交
907

908
    UNITY_SKIP_EXECUTION;
909

G
greg-williams 已提交
910 911 912 913 914 915 916 917
    // 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;
918
                break;
G
greg-williams 已提交
919 920 921 922 923 924 925 926 927 928 929 930 931
            }
        }
    }
    else
    { // handle case of one pointers being null (if both null, test should pass)
        if (expected != actual)
        {
            Unity.CurrentTestFailed = 1;
        }
    }

    if (Unity.CurrentTestFailed)
    {
932
      UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
933
      UnityPrintExpectedAndActualStrings(expected, actual);
934 935
      UnityAddMsgIfSpecified(msg);
      UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
936 937 938
    }
}

M
mvandervoord 已提交
939 940 941 942 943 944 945 946
//-----------------------------------------------
void UnityAssertEqualStringArray( const char** expected,
                                  const char** actual,
                                  const _UU32 num_elements,
                                  const char* msg,
                                  const UNITY_LINE_TYPE lineNumber)
{
    _UU32 i, j = 0;
947

948
    UNITY_SKIP_EXECUTION;
949

M
mvandervoord 已提交
950 951 952 953 954 955 956 957 958
    // if no elements, it's an error
    if (num_elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }

959
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
960
        return;
961

M
mvandervoord 已提交
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
    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);
990
                UnityPrintNumberByStyle((j), UNITY_DISPLAY_STYLE_UINT);
M
mvandervoord 已提交
991
            }
M
mvandervoord 已提交
992
            UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
M
mvandervoord 已提交
993 994
            UnityAddMsgIfSpecified(msg);
            UNITY_FAIL_AND_BAIL;
995
        }
M
mvandervoord 已提交
996 997 998 999
    } while (++j < num_elements);
}

//-----------------------------------------------
1000 1001
void UnityAssertEqualMemory( UNITY_PTR_ATTRIBUTE const void* expected,
                             UNITY_PTR_ATTRIBUTE const void* actual,
1002 1003
                             const _UU32 length,
                             const _UU32 num_elements,
M
mvandervoord 已提交
1004 1005
                             const char* msg,
                             const UNITY_LINE_TYPE lineNumber)
1006
{
1007 1008
    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;
1009
    _UU32 elements = num_elements;
1010
    _UU32 bytes;
1011 1012

    UNITY_SKIP_EXECUTION;
1013

1014 1015
    if ((elements == 0) || (length == 0))
    {
1016
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
1017 1018 1019
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
1020
    }
1021

1022
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
1023
        return;
1024

1025
    while (elements--)
1026
    {
1027 1028 1029
        /////////////////////////////////////
        bytes = length;
        while (bytes--)
1030
        {
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
            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;
1051
        }
1052
        /////////////////////////////////////
1053

1054 1055 1056
    }
}

M
mvandervoord 已提交
1057 1058 1059 1060 1061
//-----------------------------------------------
// Control Functions
//-----------------------------------------------

void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
1062
{
1063 1064
    UNITY_SKIP_EXECUTION;

M
mvandervoord 已提交
1065
    UnityTestResultsBegin(Unity.TestFile, line);
1066
    UnityPrintFail();
M
mvandervoord 已提交
1067
    if (msg != NULL)
1068 1069
    {
      UNITY_OUTPUT_CHAR(':');
1070 1071
      if (msg[0] != ' ')
      {
1072
        UNITY_OUTPUT_CHAR(' ');
M
mvandervoord 已提交
1073
      }
M
mvandervoord 已提交
1074
      UnityPrint(msg);
1075
    }
M
mvandervoord 已提交
1076
    UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
1077 1078
}

M
mvandervoord 已提交
1079
//-----------------------------------------------
M
mvandervoord 已提交
1080
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
1081
{
1082 1083
    UNITY_SKIP_EXECUTION;

M
mvandervoord 已提交
1084
    UnityTestResultsBegin(Unity.TestFile, line);
1085
    UnityPrint("IGNORE");
M
mvandervoord 已提交
1086
    if (msg != NULL)
1087 1088
    {
      UNITY_OUTPUT_CHAR(':');
1089
      UNITY_OUTPUT_CHAR(' ');
M
mvandervoord 已提交
1090
      UnityPrint(msg);
1091
    }
M
mvandervoord 已提交
1092
    UNITY_IGNORE_AND_BAIL;
G
greg-williams 已提交
1093 1094
}

1095 1096 1097 1098 1099 1100 1101
//-----------------------------------------------
void setUp(void);
void tearDown(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
{
    Unity.CurrentTestName = FuncName;
    Unity.CurrentTestLineNumber = FuncLineNum;
1102
    Unity.NumberOfTests++;
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
    if (TEST_PROTECT())
    {
        setUp();
        Func();
    }
    if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
    {
        tearDown();
    }
    UnityConcludeTest();
}

M
mvandervoord 已提交
1115
//-----------------------------------------------
1116
void UnityBegin(void)
G
greg-williams 已提交
1117 1118
{
    Unity.NumberOfTests = 0;
1119 1120 1121 1122
    Unity.TestFailures = 0;
    Unity.TestIgnores = 0;
    Unity.CurrentTestFailed = 0;
    Unity.CurrentTestIgnored = 0;
G
greg-williams 已提交
1123 1124
}

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