提交 1994bf9d 编写于 作者: F Fabian Zahn

Fixed unity fixture output and added methods for each of the different...

Fixed unity fixture output and added methods for each of the different outputs. Added documentation.
Fixed some whitespaces.
Refactored class_name to class_name_idx (expressiveness).
Refactored the xml output to methods (extensibility).
上级 7a437665
#============================================================ #============================================================
# Author: John Theofanopoulos # Author: John Theofanopoulos
# A simple parser. Takes the output files generated during the # A simple parser. Takes the output files generated during the
# build process and extracts information relating to the tests. # build process and extracts information relating to the tests.
# #
# Notes: # Notes:
# To capture an output file under VS builds use the following: # To capture an output file under VS builds use the following:
# devenv [build instructions] > Output.txt & type Output.txt # devenv [build instructions] > Output.txt & type Output.txt
# #
# To capture an output file under Linux builds use the following: # To capture an output file under Linux builds use the following:
# make | tee Output.txt # make | tee Output.txt
# #
# To use this parser use the following command # To use this parser use the following command
# ruby parseOutput.rb [options] [file] # ruby parseOutput.rb [options] [file]
# options: -xml : produce a JUnit compatible XML file # options: -xml : produce a JUnit compatible XML file
# file: file to scan for results # file: file to scan for results
#============================================================ #============================================================
# Parser class for handling the input file # Parser class for handling the input file
class ParseOutput class ParseOutput
def initialize def initialize
# internal data
@class_name_idx = 0
@path_delim = nil
# xml output related
@xml_out = false @xml_out = false
@array_list = false @array_list = false
@class_name = 0
# current suite name and statistics
@test_suite = nil @test_suite = nil
@total_tests = false @total_tests = 0
@path_delim = nil @test_passed = 0
@test_failed = 0
@test_ignored = 0
end end
# Set the flag to indicate if there will be an XML output file or not # Set the flag to indicate if there will be an XML output file or not
...@@ -39,7 +47,34 @@ class ParseOutput ...@@ -39,7 +47,34 @@ class ParseOutput
@array_list.each do |item| @array_list.each do |item|
output << item << "\n" output << item << "\n"
end end
output << "</testsuite>\n" end
# Pushes the suite info as xml to the array list, which will be written later
def push_xml_output_suite_info
# Insert opening tag at front
heading = '<testsuite name="Unity" tests="' + @total_tests.to_s + '" failures="' + @test_failed.to_s + '"' + ' skips="' + @test_ignored.to_s + '">'
@array_list.insert(0, heading)
# Push back the closing tag
@array_list.push '</testsuite>'
end
# Pushes xml output data to the array list, which will be written later
def push_xml_output_passed(test_name)
@array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '"/>'
end
# Pushes xml output data to the array list, which will be written later
def push_xml_output_failed(test_name, reason)
@array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '">'
@array_list.push ' <failure type="ASSERT FAILED">' + reason + '</failure>'
@array_list.push ' </testcase>'
end
# Pushes xml output data to the array list, which will be written later
def push_xml_output_ignored(test_name, reason)
@array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '">'
@array_list.push ' <skipped type="TEST IGNORED">' + reason + '</skipped>'
@array_list.push ' </testcase>'
end end
# This function will try and determine when the suite is changed. This is # This function will try and determine when the suite is changed. This is
...@@ -58,38 +93,76 @@ class ParseOutput ...@@ -58,38 +93,76 @@ class ParseOutput
printf "New Test: %s\n", @test_suite printf "New Test: %s\n", @test_suite
end end
# Test was flagged as having passed so format the output # Prepares the line for verbose fixture output ("-v")
def test_passed(array) def prepare_fixture_line(line)
last_item = array.length - 1 line = line.sub('IGNORE_TEST(', '')
test_name = array[last_item - 1] line = line.sub('TEST(', '')
test_suite_verify(array[@class_name]) line = line.sub(')', ',')
line = line.chomp
array = line.split(',')
array.map { |x| x.to_s.lstrip.chomp }
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)
class_name = array[0]
test_name = array[1]
test_suite_verify(class_name)
printf "%-40s PASS\n", test_name printf "%-40s PASS\n", test_name
return unless @xml_out push_xml_output_passed(test_name) if @xml_out
end
@array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '"/>' # 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_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
push_xml_output_failed(test_name, reason) if @xml_out
end end
# Test was flagged as having passed so format the output. # Test was flagged as being ignored so format the output.
# This is using the Unity fixture output and not the original Unity output. # This is using the Unity fixture output and not the original Unity output.
def test_passed_unity_fixture(array) def test_ignored_unity_fixture(array)
test_suite = array[0].sub('TEST(', '') class_name = array[0]
test_suite = test_suite.sub(',', '') test_name = array[1]
test_name = array[1].sub(')', '') reason = 'No reason given'
test_suite_verify(array[@class_name]) 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
push_xml_output_ignored(test_name, reason) if @xml_out
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_idx])
printf "%-40s PASS\n", test_name printf "%-40s PASS\n", test_name
return unless @xml_out return unless @xml_out
@array_list.push ' <testcase classname="' + test_suite + '" name="' + test_name + '"/>' push_xml_output_passed(test_name) if @xml_out
end end
# Test was flagged as being ignored so format the output # Test was flagged as having failed so format the line
def test_ignored(array) def test_failed(array)
last_item = array.length - 1 last_item = array.length - 1
test_name = array[last_item - 2] test_name = array[last_item - 2]
reason = array[last_item].chomp.lstrip reason = array[last_item].chomp.lstrip + ' at line: ' + array[last_item - 3]
class_name = array[@class_name] class_name = array[@class_name_idx]
if test_name.start_with? 'TEST(' if test_name.start_with? 'TEST('
array2 = test_name.split(' ') array2 = test_name.split(' ')
...@@ -102,21 +175,17 @@ class ParseOutput ...@@ -102,21 +175,17 @@ class ParseOutput
end end
test_suite_verify(class_name) test_suite_verify(class_name)
printf "%-40s IGNORED\n", test_name printf "%-40s FAILED\n", test_name
return unless @xml_out
@array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '">' push_xml_output_failed(test_name, reason) if @xml_out
@array_list.push ' <skipped type="TEST IGNORED">' + reason + '</skipped>'
@array_list.push ' </testcase>'
end end
# Test was flagged as having failed so format the line # Test was flagged as being ignored so format the output
def test_failed(array) def test_ignored(array)
last_item = array.length - 1 last_item = array.length - 1
test_name = array[last_item - 2] test_name = array[last_item - 2]
reason = array[last_item].chomp.lstrip + ' at line: ' + array[last_item - 3] reason = array[last_item].chomp.lstrip
class_name = array[@class_name] class_name = array[@class_name_idx]
if test_name.start_with? 'TEST(' if test_name.start_with? 'TEST('
array2 = test_name.split(' ') array2 = test_name.split(' ')
...@@ -129,13 +198,9 @@ class ParseOutput ...@@ -129,13 +198,9 @@ class ParseOutput
end end
test_suite_verify(class_name) test_suite_verify(class_name)
printf "%-40s FAILED\n", test_name printf "%-40s IGNORED\n", test_name
return unless @xml_out
@array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '">' push_xml_output_ignored(test_name, reason) if @xml_out
@array_list.push ' <failure type="ASSERT FAILED">' + reason + '</failure>'
@array_list.push ' </testcase>'
end end
# Adjusts the os specific members according to the current path style # Adjusts the os specific members according to the current path style
...@@ -143,11 +208,11 @@ class ParseOutput ...@@ -143,11 +208,11 @@ class ParseOutput
def set_os_specifics(line) def set_os_specifics(line)
if line.include? '\\' if line.include? '\\'
# Windows X:\Y\Z # Windows X:\Y\Z
@class_name = 1 @class_name_idx = 1
@path_delim = '\\' @path_delim = '\\'
else else
# Unix Based /X/Y/Z # Unix Based /X/Y/Z
@class_name = 0 @class_name_idx = 0
@path_delim = '/' @path_delim = '/'
end end
end end
...@@ -158,9 +223,9 @@ class ParseOutput ...@@ -158,9 +223,9 @@ class ParseOutput
puts 'Parsing file: ' + file_name puts 'Parsing file: ' + file_name
test_pass = 0 @test_passed = 0
test_fail = 0 @test_failed = 0
test_ignore = 0 @test_ignored = 0
puts '' puts ''
puts '=================== RESULTS =====================' puts '=================== RESULTS ====================='
puts '' puts ''
...@@ -175,43 +240,52 @@ class ParseOutput ...@@ -175,43 +240,52 @@ class ParseOutput
line_array = line.split(':') line_array = line.split(':')
# If we were able to split the line then we can look to see if any of our target words # 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. # were found. Case is important.
if (line_array.size >= 4) || (line.start_with? 'TEST(') if (line_array.size >= 4) || (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(')
# Determine if this test passed
if line.include? ':PASS' # check if the output is fixture output (with verbose flag "-v")
if (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(')
line_array = prepare_fixture_line(line)
if line.include? ' PASS'
test_passed_unity_fixture(line_array)
@test_passed += 1
elsif line.include? 'FAIL'
test_failed_unity_fixture(line_array)
@test_failed += 1
elsif line.include? 'IGNORE'
test_ignored_unity_fixture(line_array)
@test_ignored += 1
end
# normal output / fixture output (without verbose "-v")
elsif line.include? ':PASS'
test_passed(line_array) test_passed(line_array)
test_pass += 1 @test_passed += 1
elsif line.include? ':FAIL' elsif line.include? ':FAIL'
test_failed(line_array) test_failed(line_array)
test_fail += 1 @test_failed += 1
elsif line.include? ':IGNORE:' elsif line.include? ':IGNORE:'
test_ignored(line_array) test_ignored(line_array)
test_ignore += 1 @test_ignored += 1
elsif line.include? ':IGNORE' elsif line.include? ':IGNORE'
line_array.push('No reason given') line_array.push('No reason given')
test_ignored(line_array) test_ignored(line_array)
test_ignore += 1 @test_ignored += 1
elsif line.start_with? 'TEST('
if line.include? ' PASS'
line_array = line.split(' ')
test_passed_unity_fixture(line_array)
test_pass += 1
end
end end
@total_tests = @test_passed + @test_failed + @test_ignored
end end
end end
puts '' puts ''
puts '=================== SUMMARY =====================' puts '=================== SUMMARY ====================='
puts '' puts ''
puts 'Tests Passed : ' + test_pass.to_s puts 'Tests Passed : ' + @test_passed.to_s
puts 'Tests Failed : ' + test_fail.to_s puts 'Tests Failed : ' + @test_failed.to_s
puts 'Tests Ignored : ' + test_ignore.to_s puts 'Tests Ignored : ' + @test_ignored.to_s
@total_tests = test_pass + test_fail + test_ignore
return unless @xml_out return unless @xml_out
heading = '<testsuite name="Unity" tests="' + @total_tests.to_s + '" failures="' + test_fail.to_s + '"' + ' skips="' + test_ignore.to_s + '">' # push information about the suite
@array_list.insert(0, heading) push_xml_output_suite_info
# write xml output file
write_xml_output write_xml_output
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册