cJSON/auto/parse_output.rb
Max Bruckner ab77a80e9b Squashed 'tests/unity/' changes from 1f52255..f96c055
f96c055 this is a minor release
2c7629a Documentation Updates
b8bfb01 Add support for AStyle in test makefile. It’s going to assume you have it installed.
e36d8b5 Merge pull request #276 from wolf99/pdf-to-markdown
1e43967 Add EACH_EQUAL changes
e2cc679 Add newlines after headings for best practice, trim trailing spaces & convert sneaky incorrectly coded chars
192d517 Remove PDFs
c48f6c9 Add Github Markdown versions of documents
2a5b24f Finished updating all Ruby scripts to match our coding standard. Woo!
3e0a712 Started to flesh out rubocop settings for this project. Added rakefile tasks to do so. Updated first script to make it compliant.
23f9c16 Another round of fixing things that the stylizer “corrected” for me.
3a6cca3 Fixed things that the stylizer “autocorrected” to wrong. ;)
3062c39 Starting to enforce our coding style. The first step is that we’ve pulled in Rubocop to check out Ruby syntax. There is likely a bit of customization to do yet AND there is definitely that backlog of todo’s that we just told it to ignore.
550d58b Attempt to fix remaining issues with casting
ee038c2 Ha! Forgot to add the correct comment style
d6b3508 Clean up some const issues, particularly when moving between single and double pointers
4ffafce Finish updating documentation to match
083564b Update docs to also understand the new Each Equal handlers
0dddf49 also update strings to support each element of an array.
a11a137 Added memory each equal assertion
d8d67a7 Added each_equal assertions for float and double
b7956ea Added more tests for all the numerical types when performing each_equal assertions
7fe3191 Added some tests to prove this works. Still work in progress
56eeacd prepare for comparing value to array by setting up explicit compare of array to array in ints
7b80885 Merge pull request #272 from FSMaxB/gcc43-wconversion
0781e74 Add our coding standard to documentation
c3658a0 Dropped support for pre-2.0 versions of Ruby (not even rubylang supports them anymore)
8a45ccf Use custom mock prefix when searching for mock header files. #263
689610b reorder includes in generated test runners
43c7511 stdlib.h explicitly called in fixtures when malloc used, now. (Fixes issue #268)
1c556d2 Fix -Wconversion with gcc-4.3
8723d50 Turn UNITY_OUTPUT_FLUSH off by default. Added a quick-define for the most common case: UNITY_USE_FLUSH_STDOUT. Clarified documentation. Fixes issue #269
c67a4ff - Add ability to detect TEST_FILE(“filename.c”) specifications in test files
41ee499 Tiny tweaks to make Unity fit in more smoothly with Ceedling

git-subtree-dir: tests/unity
git-subtree-split: f96c05532b3e00c9ca77e58fc07f9401cd46510d
2017-04-27 02:54:33 +02:00

221 lines
6.8 KiB
Ruby

#============================================================
# Author: John Theofanopoulos
# A simple parser. Takes the output files generated during the build process and
# extracts information relating to the tests.
#
# Notes:
# To capture an output file under VS builds use the following:
# devenv [build instructions] > Output.txt & type Output.txt
#
# To capture an output file under GCC/Linux builds use the following:
# make | tee Output.txt
#
# To use this parser use the following command
# ruby parseOutput.rb [options] [file]
# options: -xml : produce a JUnit compatible XML file
# file : file to scan for results
#============================================================
class ParseOutput
def initialize
@test_flag = false
@xml_out = false
@array_list = false
@total_tests = false
@class_index = false
end
# Set the flag to indicate if there will be an XML output file or not
def set_xml_output
@xml_out = true
end
# if write our output to XML
def write_xml_output
output = File.open('report.xml', 'w')
output << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@array_list.each do |item|
output << item << "\n"
end
output << "</testsuite>\n"
end
# This function will try and determine when the suite is changed. This is
# is the name that gets added to the classname parameter.
def test_suite_verify(test_suite_name)
return if @test_flag
@test_flag = true
# Split the path name
test_name = test_suite_name.split('/')
# Remove the extension
base_name = test_name[test_name.size - 1].split('.')
@test_suite = 'test.' + base_name[0]
printf "New Test: %s\n", @test_suite
end
# Test was flagged as having passed so format the output
def test_passed(array)
last_item = array.length - 1
test_name = array[last_item - 1]
test_suite_verify(array[@class_name])
printf "%-40s PASS\n", test_name
return unless @xml_out
@array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '"/>'
end
# Test was flagged as having passed so format the output.
# This is using the Unity fixture output and not the original Unity output.
def test_passed_unity_fixture(array)
test_suite = array[0].sub('TEST(', '')
test_suite = test_suite.sub(',', '')
test_name = array[1].sub(')', '')
return unless @xml_out
@array_list.push ' <testcase classname="' + test_suite + '" name="' + test_name + '"/>'
end
# Test was flagged as being ingored so format the output
def test_ignored(array)
last_item = array.length - 1
test_name = array[last_item - 2]
reason = array[last_item].chomp
test_suite_verify(array[@class_name])
printf "%-40s IGNORED\n", test_name
if test_name.start_with? 'TEST('
array2 = test_name.split(' ')
@test_suite = array2[0].sub('TEST(', '')
@test_suite = @test_suite.sub(',', '')
test_name = array2[1].sub(')', '')
end
return unless @xml_out
@array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '">'
@array_list.push ' <skipped type="TEST IGNORED"> ' + reason + ' </skipped>'
@array_list.push ' </testcase>'
end
# Test was flagged as having failed so format the line
def test_failed(array)
last_item = array.length - 1
test_name = array[last_item - 2]
reason = array[last_item].chomp + ' at line: ' + array[last_item - 3]
test_suite_verify(array[@class_name])
printf "%-40s FAILED\n", test_name
if test_name.start_with? 'TEST('
array2 = test_name.split(' ')
@test_suite = array2[0].sub('TEST(', '')
@test_suite = @test_suite.sub(',', '')
test_name = array2[1].sub(')', '')
end
return unless @xml_out
@array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '">'
@array_list.push ' <failure type="ASSERT FAILED"> ' + reason + ' </failure>'
@array_list.push ' </testcase>'
end
# Figure out what OS we are running on. For now we are assuming if it's not Windows it must
# be Unix based.
def detect_os
os = RUBY_PLATFORM.split('-')
@class_name = if os.size == 2
if os[1] == 'mingw32'
1
else
0
end
else
0
end
end
# Main function used to parse the file that was captured.
def process(name)
@test_flag = false
@array_list = []
detect_os
puts 'Parsing file: ' + name
test_pass = 0
test_fail = 0
test_ignore = 0
puts ''
puts '=================== RESULTS ====================='
puts ''
File.open(name).each do |line|
# Typical test lines look like this:
# <path>/<test_file>.c:36:test_tc1000_opsys:FAIL: Expected 1 Was 0
# <path>/<test_file>.c:112:test_tc5004_initCanChannel:IGNORE: Not Yet Implemented
# <path>/<test_file>.c:115:test_tc5100_initCanVoidPtrs:PASS
#
# where path is different on Unix vs Windows devices (Windows leads with a drive letter)
line_array = line.split(':')
# If we were able to split the line then we can look to see if any of our target words
# were found. Case is important.
if (line_array.size >= 4) || (line.start_with? 'TEST(')
# Determine if this test passed
if line.include? ':PASS'
test_passed(line_array)
test_pass += 1
elsif line.include? ':FAIL:'
test_failed(line_array)
test_fail += 1
elsif line.include? ':IGNORE:'
test_ignored(line_array)
test_ignore += 1
elsif line.start_with? 'TEST('
if line.include? ' PASS'
line_array = line.split(' ')
test_passed_unity_fixture(line_array)
test_pass += 1
end
# If none of the keywords are found there are no more tests for this suite so clear
# the test flag
else
@test_flag = false
end
else
@test_flag = false
end
end
puts ''
puts '=================== SUMMARY ====================='
puts ''
puts 'Tests Passed : ' + test_pass.to_s
puts 'Tests Failed : ' + test_fail.to_s
puts 'Tests Ignored : ' + test_ignore.to_s
@total_tests = test_pass + test_fail + test_ignore
return unless @xml_out
heading = '<testsuite tests="' + @total_tests.to_s + '" failures="' + test_fail.to_s + '"' + ' skips="' + test_ignore.to_s + '">'
@array_list.insert(0, heading)
write_xml_output
end
end
# If the command line has no values in, used a default value of Output.txt
parse_my_file = ParseOutput.new
if ARGV.size >= 1
ARGV.each do |a|
if a == '-xml'
parse_my_file.set_xml_output
else
parse_my_file.process(a)
break
end
end
end