Skip to content

Parse test execution time in unity fixture output #659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions auto/parse_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,41 +131,44 @@ def prepare_fixture_line(line)
def test_passed_unity_fixture(array)
class_name = array[0]
test_name = array[1]
test_time = get_test_time(array[array.length - 1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this needs to be enabled by something, as by default we do not have the timing information.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing :)
Yes indeed, the timing output has to be enabled using UNITY_INCLUDE_EXEC_TIME flag

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so shouldnt there be an if statement, otherwise you are just accessing test_name in the worst case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if the execution time is not present get_test_time will receive a string that wont match the "( ms)" pattern and return 0 (that strategy was already applied for normal unity output)

test_suite_verify(class_name)
printf "%-40s PASS\n", test_name
printf "%-40s PASS %10d ms\n", test_name, test_time

push_xml_output_passed(test_name) if @xml_out
push_xml_output_passed(test_name, test_time) if @xml_out
end

# Test was flagged as having failed so format the output.
# This is using the Unity fixture output and not the original Unity output.
def test_failed_unity_fixture(array)
class_name = array[0]
test_name = array[1]
test_time = get_test_time(array[array.length - 1])
test_suite_verify(class_name)
reason_array = array[2].split(':')
reason = reason_array[-1].lstrip.chomp + ' at line: ' + reason_array[-4]

printf "%-40s FAILED\n", test_name
printf "%-40s FAILED %10d ms\n", test_name, test_time

push_xml_output_failed(test_name, reason) if @xml_out
push_xml_output_failed(test_name, reason, test_time) if @xml_out
end

# Test was flagged as being ignored so format the output.
# This is using the Unity fixture output and not the original Unity output.
def test_ignored_unity_fixture(array)
class_name = array[0]
test_name = array[1]
test_time = get_test_time(array[array.length - 1])
reason = 'No reason given'
if array.size > 2
reason_array = array[2].split(':')
tmp_reason = reason_array[-1].lstrip.chomp
reason = tmp_reason == 'IGNORE' ? 'No reason given' : tmp_reason
end
test_suite_verify(class_name)
printf "%-40s IGNORED\n", test_name
printf "%-40s IGNORED %10d ms\n", test_name, test_time

push_xml_output_ignored(test_name, reason) if @xml_out
push_xml_output_ignored(test_name, reason, test_time) if @xml_out
end

# Test was flagged as having passed so format the output
Expand Down
7 changes: 7 additions & 0 deletions extras/fixture/src/unity_fixture.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ void UnityIgnoreTest(const char* printableName, const char* group, const char* n
if (UnityFixture.Verbose)
{
UnityPrint(printableName);
UNITY_EXEC_TIME_START();
UNITY_EXEC_TIME_STOP();
UNITY_PRINT_EXEC_TIME();
UNITY_PRINT_EOL();
}
else if (UnityFixture.Silent)
Expand Down Expand Up @@ -286,6 +289,8 @@ void UnityConcludeFixtureTest(void)
if (Unity.CurrentTestIgnored)
{
Unity.TestIgnores++;
UNITY_EXEC_TIME_STOP();
UNITY_PRINT_EXEC_TIME();
UNITY_PRINT_EOL();
}
else if (!Unity.CurrentTestFailed)
Expand All @@ -302,6 +307,8 @@ void UnityConcludeFixtureTest(void)
else /* Unity.CurrentTestFailed */
{
Unity.TestFailures++;
UNITY_EXEC_TIME_STOP();
UNITY_PRINT_EXEC_TIME();
UNITY_PRINT_EOL();
}

Expand Down