Quiet output for unity?

155 views Asked by At

I have Grenning's book. On page 20 he has the output from a unity example. It shows no passing tests, just ". . ." for each passing test.

I downloaded the unity source and am running it in a simulator for my target processor. I see every test case listed - passing ones and failing ones.

I don't see any option I can define in unity.h that would only print out the failing test cases and the summary. I have a lot of tests and my stdout window is really cluttered right now.

Is that some magic handled by the generate test runner ruby script that I am not using (in the auto or extras directories)? Or is there a basic option I am missing.

This is representative of what my output looks like now

C:[path]\ut_main.c:80:test_fred_condition_foo:PASS
C:[path]\ut_main.c:85:test_fred_condition_bar:FAIL: Expected 1
C:[path]\ut_main.c:90:test_fred_condition_baz:PASS
C:[path]\ut_main.c:95:test_fred_condition_qux

-----------------------
4 Tests 1 Failures 0 Ignored
FAIL

I'd rather it be like:

.
C:[path]\ut_main.c:85:test_fred_condition_bar:FAIL: Expected 1
. . 

-----------------------
4 Tests 1 Failures 0 Ignored
FAIL
1

There are 1 answers

0
Nick On BEST ANSWER

I modified UnityConcludeTest() in unity.c to solve this problem.

It was this:

void UnityConcludeTest(void)
{
    if (Unity.CurrentTestIgnored)
    {
        Unity.TestIgnores++;
    }
    else if (!Unity.CurrentTestFailed)
    {
        UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
        UnityPrint(UnityStrPass);
    }
    else
    {
        Unity.TestFailures++;
    }

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

I changed it to this

void UnityConcludeTest(void)
{
    if (Unity.CurrentTestIgnored)
    {
        UNITY_PRINT_EOL;
        Unity.TestIgnores++;
    }
    else if (!Unity.CurrentTestFailed)
    {
#ifdef UNITY_QUIET
        UnityPrint(".");
#else
        UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
        UnityPrint(UnityStrPass);
        UNITY_PRINT_EOL;            
#endif
    }
    else
    {
        UNITY_PRINT_EOL;
        Unity.TestFailures++;
    }

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

I also added UNITY_PRINT_EOL; at the beginning of UnityTestResultsBegin and UnityEnd (there was already one, I added another).

That did the trick + it put a blank space between each message to make everything more readable.