提交 0937bf72 编写于 作者: F Fabian Zahn

- Removed member variable @test_flag

- Fixed stdout output if fixture is active
- Refactored the state manipulation of @test_suite and moved it completely into test_suite_verify()
上级 d9cd6988
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
class ParseOutput class ParseOutput
def initialize def initialize
@test_flag = false
@xml_out = false @xml_out = false
@array_list = false @array_list = false
@class_name = 0
@test_suite = nil
@total_tests = false @total_tests = false
@class_index = false
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
...@@ -30,7 +30,7 @@ class ParseOutput ...@@ -30,7 +30,7 @@ class ParseOutput
@xml_out = true @xml_out = true
end end
# if write our output to XML # If write our output to XML
def write_xml_output def write_xml_output
output = File.open('report.xml', 'w') output = File.open('report.xml', 'w')
output << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" output << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
...@@ -40,12 +40,10 @@ class ParseOutput ...@@ -40,12 +40,10 @@ class ParseOutput
output << "</testsuite>\n" output << "</testsuite>\n"
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
# is the name that gets added to the classname parameter. # is the name that gets added to the classname parameter.
def test_suite_verify(test_suite_name) def test_suite_verify(test_suite_name)
return if @test_flag
@test_flag = true
# Split the path name # Split the path name
test_name = if @class_name == 1 test_name = if @class_name == 1
test_suite_name.split('\\') # Windows test_suite_name.split('\\') # Windows
...@@ -53,10 +51,15 @@ class ParseOutput ...@@ -53,10 +51,15 @@ class ParseOutput
test_suite_name.split('/') # Unix based test_suite_name.split('/') # Unix based
end end
# Remove the extension # Remove the extension and extract the base_name
base_name = test_name[test_name.size - 1].split('.') base_name = test_name[test_name.size - 1].split('.')[0]
@test_suite = 'test.' + base_name[0]
printf "New Test: %s\n", @test_suite # Is this a new test suite?
if base_name.to_s != @test_suite.to_s
@test_suite = base_name
printf "New Test: %s\n", @test_suite
end
end end
# Test was flagged as having passed so format the output # Test was flagged as having passed so format the output
...@@ -77,7 +80,8 @@ class ParseOutput ...@@ -77,7 +80,8 @@ class ParseOutput
test_suite = array[0].sub('TEST(', '') test_suite = array[0].sub('TEST(', '')
test_suite = test_suite.sub(',', '') test_suite = test_suite.sub(',', '')
test_name = array[1].sub(')', '') test_name = array[1].sub(')', '')
test_suite_verify(array[@class_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 + '"/>' @array_list.push ' <testcase classname="' + test_suite + '" name="' + test_name + '"/>'
...@@ -88,16 +92,21 @@ class ParseOutput ...@@ -88,16 +92,21 @@ class ParseOutput
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
test_suite_verify(array[@class_name]) class_name = array[@class_name]
printf "%-40s IGNORED\n", test_name
if test_name.start_with? 'TEST(' if test_name.start_with? 'TEST('
array2 = test_name.split(' ') array2 = test_name.split(' ')
@test_suite = array2[0].sub('TEST(', '')
@test_suite = @test_suite.sub(',', '') test_suite = array2[0].sub('TEST(', '')
test_suite = test_suite.sub(',', '')
class_name = test_suite
test_name = array2[1].sub(')', '') test_name = array2[1].sub(')', '')
end end
test_suite_verify(class_name)
printf "%-40s IGNORED\n", test_name
return unless @xml_out return unless @xml_out
@array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '">' @array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '">'
...@@ -110,16 +119,21 @@ class ParseOutput ...@@ -110,16 +119,21 @@ class ParseOutput
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 + ' at line: ' + array[last_item - 3]
test_suite_verify(array[@class_name]) class_name = array[@class_name]
printf "%-40s FAILED\n", test_name
if test_name.start_with? 'TEST(' if test_name.start_with? 'TEST('
array2 = test_name.split(' ') array2 = test_name.split(' ')
@test_suite = array2[0].sub('TEST(', '')
@test_suite = @test_suite.sub(',', '') test_suite = array2[0].sub('TEST(', '')
test_suite = test_suite.sub(',', '')
class_name = test_suite
test_name = array2[1].sub(')', '') test_name = array2[1].sub(')', '')
end end
test_suite_verify(class_name)
printf "%-40s FAILED\n", test_name
return unless @xml_out return unless @xml_out
@array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '">' @array_list.push ' <testcase classname="' + @test_suite + '" name="' + test_name + '">'
...@@ -144,7 +158,6 @@ class ParseOutput ...@@ -144,7 +158,6 @@ class ParseOutput
# Main function used to parse the file that was captured. # Main function used to parse the file that was captured.
def process(name) def process(name)
@test_flag = false
@array_list = [] @array_list = []
detect_os detect_os
...@@ -189,13 +202,7 @@ class ParseOutput ...@@ -189,13 +202,7 @@ class ParseOutput
test_passed_unity_fixture(line_array) test_passed_unity_fixture(line_array)
test_pass += 1 test_pass += 1
end 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 end
else
@test_flag = false
end end
end end
puts '' puts ''
...@@ -208,7 +215,7 @@ class ParseOutput ...@@ -208,7 +215,7 @@ class ParseOutput
return unless @xml_out return unless @xml_out
heading = '<testsuite name="' + @test_suite.to_s + '" tests="' + @total_tests.to_s + '" failures="' + test_fail.to_s + '"' + ' skips="' + test_ignore.to_s + '">' heading = '<testsuite name="Unity" tests="' + @total_tests.to_s + '" failures="' + test_fail.to_s + '"' + ' skips="' + test_ignore.to_s + '">'
@array_list.insert(0, heading) @array_list.insert(0, heading)
write_xml_output write_xml_output
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册