Fixed whitespaces and formatting
Added more expressiveness to the code
Fixed some of the rubocop hints
#============================================================
# Author: John Theofanopoulos
-# A simple parser. Takes the output files generated during the build process and
-# extracts information relating to the tests.
+# 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:
+# To capture an output file under Linux builds use the following:
# make | tee Output.txt
#
# To use this parser use the following command
# file: file to scan for results
#============================================================
+# Parser class for handling the input file
class ParseOutput
def initialize
@xml_out = false
@@ -44,19 +45,18 @@ class ParseOutput
# 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)
-
# Split the path name
test_name = test_suite_name.split(@path_delim)
# Remove the extension and extract the base_name
base_name = test_name[test_name.size - 1].split('.')[0]
- # Is this a new test suite?
- if base_name.to_s != @test_suite.to_s
+ # Return if the test suite hasn't changed
+ return unless base_name.to_s != @test_suite.to_s
+
@test_suite = base_name
printf "New Test: %s\n", @test_suite
end
- end
# Test was flagged as having passed so format the output
def test_passed(array)
@@ -78,6 +78,7 @@ class ParseOutput
test_name = array[1].sub(')', '')
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 + '"/>'
@@ -152,10 +153,10 @@ class ParseOutput
end
# Main function used to parse the file that was captured.
- def process(name)
+ def process(file_name)
@array_list = []
- puts 'Parsing file: ' + name
+ puts 'Parsing file: ' + file_name
test_pass = 0
test_fail = 0
@@ -163,7 +164,7 @@ class ParseOutput
puts ''
puts '=================== RESULTS ====================='
puts ''
- File.open(name).each do |line|
+ File.open(file_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
@@ -219,11 +220,11 @@ end
parse_my_file = ParseOutput.new
if ARGV.size >= 1
- ARGV.each do |a|
- if a == '-xml'
+ ARGV.each do |arg|
+ if arg == '-xml'
parse_my_file.set_xml_output
else
- parse_my_file.process(a)
+ parse_my_file.process(arg)
break
end
end
