From 2b725883f7b43660f0f5b36046ed628cf61b9999 Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Fri, 27 Nov 2020 10:10:01 +0300 Subject: [PATCH 01/10] parse_output should parse color output now --- auto/parse_output.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index d72c6e8..d5515d5 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -288,6 +288,17 @@ class ParseOutput line_array.push('No reason given') test_ignored(line_array) @test_ignored += 1 + elsif line_array.size >= 4 + if line_array[3].include? 'PASS' + test_passed(line_array) + @test_passed += 1 + elsif line_array[3].include? 'FAIL' + test_failed(line_array) + @test_failed += 1 + elsif line_array[3].include? 'IGNORE:' + test_ignored(line_array) + @test_ignored += 1 + end end @total_tests = @test_passed + @test_failed + @test_ignored end From 10d593d4138af9b841e715b3535bf31550411b51 Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Fri, 27 Nov 2020 10:23:54 +0300 Subject: [PATCH 02/10] parse_output test_suite tag can be passed as arg now --- auto/parse_output.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index d5515d5..f0c062b 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -18,6 +18,9 @@ # To use this parser use the following command # ruby parseOutput.rb [options] [file] # options: -xml : produce a JUnit compatible XML file +# -suiteRequiredSuiteName +# : replace default test suite name to +# "RequiredSuiteName" (can be any name) # file: file to scan for results #============================================================ @@ -33,6 +36,9 @@ class ParseOutput @array_list = false # current suite name and statistics + ## testsuite name + @real_test_suite_name = 'Unity' + ## classname for testcase @test_suite = nil @total_tests = 0 @test_passed = 0 @@ -45,6 +51,12 @@ class ParseOutput @xml_out = true end + # Set the flag to indicate if there will be an XML output file or not + def set_test_suite_name(cli_arg) + @real_test_suite_name = cli_arg['-suite'.length..-1] + puts 'Real test suite name will be \'' + @real_test_suite_name + '\'' + end + # If write our output to XML def write_xml_output output = File.open('report.xml', 'w') @@ -57,7 +69,7 @@ class ParseOutput # 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 = '' + heading = '' @array_list.insert(0, heading) # Push back the closing tag @array_list.push '' @@ -325,6 +337,8 @@ if ARGV.size >= 1 ARGV.each do |arg| if arg == '-xml' parse_my_file.set_xml_output + elsif arg.start_with?('-suite') + parse_my_file.set_test_suite_name(arg) else parse_my_file.process(arg) break From 474d2018007b28abc41900f3606592c308b5443a Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Fri, 27 Nov 2020 11:40:47 +0300 Subject: [PATCH 03/10] parse_output: test names can contain double-quoted string now --- auto/parse_output.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index f0c062b..6d9b17c 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -57,6 +57,10 @@ class ParseOutput puts 'Real test suite name will be \'' + @real_test_suite_name + '\'' end + def xml_encode_s(s) + return s.encode(:xml => :attr) + end + # If write our output to XML def write_xml_output output = File.open('report.xml', 'w') @@ -69,7 +73,7 @@ class ParseOutput # 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 = '' + heading = '' @array_list.insert(0, heading) # Push back the closing tag @array_list.push '' @@ -77,19 +81,19 @@ class ParseOutput # Pushes xml output data to the array list, which will be written later def push_xml_output_passed(test_name) - @array_list.push ' ' + @array_list.push ' ' 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 ' ' + @array_list.push ' ' @array_list.push ' ' + reason + '' @array_list.push ' ' 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 ' ' + @array_list.push ' ' @array_list.push ' ' + reason + '' @array_list.push ' ' end From e32809c529b8dc81f5b41bf6165dc3325df8ff30 Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Fri, 27 Nov 2020 16:10:26 +0300 Subject: [PATCH 04/10] Trying to fix errors of non-ASCII characters while parsing --- auto/parse_output.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index 6d9b17c..afdd993 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -250,7 +250,7 @@ class ParseOutput puts '' puts '=================== RESULTS =====================' puts '' - File.open(file_name).each do |line| + File.open(file_name, :encoding => "UTF-8").each do |line| # Typical test lines look like these: # ---------------------------------------------------- # 1. normal output: From 5089be60e0030fd08948ce145db439973e62e3df Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Fri, 27 Nov 2020 23:02:55 +0300 Subject: [PATCH 05/10] parse_output accepting all symbols now Methods with their args can contain colons (':') now --- auto/parse_output.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index afdd993..314a33f 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -29,6 +29,7 @@ class ParseOutput def initialize # internal data @class_name_idx = 0 + @result_usual_idx = 3 @path_delim = nil # xml output related @@ -250,7 +251,8 @@ class ParseOutput puts '' puts '=================== RESULTS =====================' puts '' - File.open(file_name, :encoding => "UTF-8").each do |line| + # Apply binary encoding. Bad symbols will be unchanged + File.open(file_name, "rb").each do |line| # Typical test lines look like these: # ---------------------------------------------------- # 1. normal output: @@ -305,13 +307,18 @@ class ParseOutput test_ignored(line_array) @test_ignored += 1 elsif line_array.size >= 4 - if line_array[3].include? 'PASS' + # ':' symbol will be valid in function args now + real_method_name = line_array[@result_usual_idx - 1..-2].join(':') + line_array = line_array[0..@result_usual_idx - 2] + [real_method_name] + [line_array[-1]] + + # We will check output from color compilation + if line_array[@result_usual_idx].include? 'PASS' test_passed(line_array) @test_passed += 1 - elsif line_array[3].include? 'FAIL' + elsif line_array[@result_usual_idx].include? 'FAIL' test_failed(line_array) @test_failed += 1 - elsif line_array[3].include? 'IGNORE:' + elsif line_array[@result_usual_idx].include? 'IGNORE' test_ignored(line_array) @test_ignored += 1 end From cc36e0d82b99d2a457a5599bebc68c1616dbf5a8 Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Mon, 30 Nov 2020 12:14:52 +0300 Subject: [PATCH 06/10] Fix failed & ignored tests color parsing --- auto/parse_output.rb | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index 314a33f..7d8a4c2 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -169,6 +169,10 @@ class ParseOutput # Test was flagged as having passed so format the output def test_passed(array) + # ':' symbol will be valid in function args now + real_method_name = array[@result_usual_idx - 1..-2].join(':') + array = array[0..@result_usual_idx - 2] + [real_method_name] + [array[-1]] + last_item = array.length - 1 test_name = array[last_item - 1] test_suite_verify(array[@class_name_idx]) @@ -181,6 +185,10 @@ class ParseOutput # Test was flagged as having failed so format the line def test_failed(array) + # ':' symbol will be valid in function args now + real_method_name = array[@result_usual_idx - 1..-3].join(':') + array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..-1] + last_item = array.length - 1 test_name = array[last_item - 2] reason = array[last_item].chomp.lstrip + ' at line: ' + array[last_item - 3] @@ -204,6 +212,10 @@ class ParseOutput # Test was flagged as being ignored so format the output def test_ignored(array) + # ':' symbol will be valid in function args now + real_method_name = array[@result_usual_idx - 1..-3].join(':') + array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..-1] + last_item = array.length - 1 test_name = array[last_item - 2] reason = array[last_item].chomp.lstrip @@ -307,18 +319,18 @@ class ParseOutput test_ignored(line_array) @test_ignored += 1 elsif line_array.size >= 4 - # ':' symbol will be valid in function args now - real_method_name = line_array[@result_usual_idx - 1..-2].join(':') - line_array = line_array[0..@result_usual_idx - 2] + [real_method_name] + [line_array[-1]] - # We will check output from color compilation - if line_array[@result_usual_idx].include? 'PASS' + if line_array[@result_usual_idx..-1].any? {|l| l.include? 'PASS'} test_passed(line_array) @test_passed += 1 - elsif line_array[@result_usual_idx].include? 'FAIL' + elsif line_array[@result_usual_idx..-1].any? {|l| l.include? 'FAIL'} test_failed(line_array) @test_failed += 1 - elsif line_array[@result_usual_idx].include? 'IGNORE' + elsif line_array[@result_usual_idx..-2].any? {|l| l.include? 'IGNORE'} + test_ignored(line_array) + @test_ignored += 1 + elsif line_array[@result_usual_idx..-1].any? {|l| l.include? 'IGNORE'} + line_array.push('No reason given') test_ignored(line_array) @test_ignored += 1 end From edf6a52bfdb58267a345df124e0294af156e0c5d Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Thu, 3 Dec 2020 16:26:20 +0300 Subject: [PATCH 07/10] Test time parsing was added (cherry picked from commit f2fe9fd4ad78c574af08afaa91d402b37464b131) --- auto/parse_output.rb | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index 7d8a4c2..92d62d9 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -81,20 +81,20 @@ class ParseOutput end # Pushes xml output data to the array list, which will be written later - def push_xml_output_passed(test_name) - @array_list.push ' ' + def push_xml_output_passed(test_name, execution_time = 0) + @array_list.push ' ' 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 ' ' + def push_xml_output_failed(test_name, reason, execution_time = 0) + @array_list.push ' ' @array_list.push ' ' + reason + '' @array_list.push ' ' 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 ' ' + def push_xml_output_ignored(test_name, reason, execution_time = 0) + @array_list.push ' ' @array_list.push ' ' + reason + '' @array_list.push ' ' end @@ -174,13 +174,14 @@ class ParseOutput array = array[0..@result_usual_idx - 2] + [real_method_name] + [array[-1]] last_item = array.length - 1 + test_time = get_test_time(array[last_item]) test_name = array[last_item - 1] test_suite_verify(array[@class_name_idx]) - printf "%-40s PASS\n", test_name + printf "%-40s PASS %10d ms\n", test_name, test_time return unless @xml_out - 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 line @@ -190,6 +191,7 @@ class ParseOutput array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..-1] last_item = array.length - 1 + test_time = get_test_time(array[last_item]) test_name = array[last_item - 2] reason = array[last_item].chomp.lstrip + ' at line: ' + array[last_item - 3] class_name = array[@class_name_idx] @@ -205,9 +207,9 @@ class ParseOutput end test_suite_verify(class_name) - 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 @@ -217,6 +219,7 @@ class ParseOutput array = array[0..@result_usual_idx - 3] + [real_method_name] + array[-2..-1] last_item = array.length - 1 + test_time = get_test_time(array[last_item]) test_name = array[last_item - 2] reason = array[last_item].chomp.lstrip class_name = array[@class_name_idx] @@ -232,9 +235,17 @@ class ParseOutput 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 + + def get_test_time(value_with_time) + test_time_array = value_with_time.scan(/\((-?\d+.?\d*) ms\)\s*$/).flatten.map do |arg_value_str| + arg_value_str.include?('.') ? arg_value_str.to_f : arg_value_str.to_i + end + + test_time_array.any? ? test_time_array[0] : 0 end # Adjusts the os specific members according to the current path style @@ -330,7 +341,7 @@ class ParseOutput test_ignored(line_array) @test_ignored += 1 elsif line_array[@result_usual_idx..-1].any? {|l| l.include? 'IGNORE'} - line_array.push('No reason given') + line_array.push('No reason given (' + get_test_time(line_array[@result_usual_idx..-1]).to_s + ' ms)') test_ignored(line_array) @test_ignored += 1 end From 32608af4f50eb36f52fa5bd5cf34b4c9dea40c0b Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Thu, 3 Dec 2020 16:49:49 +0300 Subject: [PATCH 08/10] Test passing time will be in seconds now (for xml output) (cherry picked from commit 39d54e2913b0c3a18106a13705fed2fb8ab7f4b0) --- auto/parse_output.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index 92d62d9..8d541f1 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -82,19 +82,19 @@ class ParseOutput # Pushes xml output data to the array list, which will be written later def push_xml_output_passed(test_name, execution_time = 0) - @array_list.push ' ' + @array_list.push ' ' end # Pushes xml output data to the array list, which will be written later def push_xml_output_failed(test_name, reason, execution_time = 0) - @array_list.push ' ' + @array_list.push ' ' @array_list.push ' ' + reason + '' @array_list.push ' ' end # Pushes xml output data to the array list, which will be written later def push_xml_output_ignored(test_name, reason, execution_time = 0) - @array_list.push ' ' + @array_list.push ' ' @array_list.push ' ' + reason + '' @array_list.push ' ' end @@ -240,6 +240,7 @@ class ParseOutput push_xml_output_ignored(test_name, reason, test_time) if @xml_out end + # Test time will be in ms def get_test_time(value_with_time) test_time_array = value_with_time.scan(/\((-?\d+.?\d*) ms\)\s*$/).flatten.map do |arg_value_str| arg_value_str.include?('.') ? arg_value_str.to_f : arg_value_str.to_i From 2dbfd0594c575688fe4d81aeb4cadd58dbc396f4 Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Mon, 28 Feb 2022 16:11:32 +0300 Subject: [PATCH 09/10] Adding time feature description --- auto/parse_output.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index 8d541f1..ea9fa0b 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -14,6 +14,7 @@ # - normal output (raw unity) # - fixture output (unity_fixture.h/.c) # - fixture output with verbose flag set ("-v") +# - time output flag set (UNITY_INCLUDE_EXEC_TIME define enabled with milliseconds output) # # To use this parser use the following command # ruby parseOutput.rb [options] [file] From 824eb5f5c54c1288437e34e5d002f9e80dbafbbb Mon Sep 17 00:00:00 2001 From: Alex Overchenko Date: Mon, 28 Feb 2022 16:59:52 +0300 Subject: [PATCH 10/10] Fixing Rubocop code style --- auto/parse_output.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/auto/parse_output.rb b/auto/parse_output.rb index ea9fa0b..864104b 100644 --- a/auto/parse_output.rb +++ b/auto/parse_output.rb @@ -54,13 +54,13 @@ class ParseOutput end # Set the flag to indicate if there will be an XML output file or not - def set_test_suite_name(cli_arg) - @real_test_suite_name = cli_arg['-suite'.length..-1] + def test_suite_name=(cli_arg) + @real_test_suite_name = cli_arg puts 'Real test suite name will be \'' + @real_test_suite_name + '\'' end - def xml_encode_s(s) - return s.encode(:xml => :attr) + def xml_encode_s(str) + str.encode(:xml => :attr) end # If write our output to XML @@ -277,7 +277,7 @@ class ParseOutput puts '=================== RESULTS =====================' puts '' # Apply binary encoding. Bad symbols will be unchanged - File.open(file_name, "rb").each do |line| + File.open(file_name, 'rb').each do |line| # Typical test lines look like these: # ---------------------------------------------------- # 1. normal output: @@ -333,16 +333,16 @@ class ParseOutput @test_ignored += 1 elsif line_array.size >= 4 # We will check output from color compilation - if line_array[@result_usual_idx..-1].any? {|l| l.include? 'PASS'} + if line_array[@result_usual_idx..-1].any? { |l| l.include? 'PASS' } test_passed(line_array) @test_passed += 1 - elsif line_array[@result_usual_idx..-1].any? {|l| l.include? 'FAIL'} + elsif line_array[@result_usual_idx..-1].any? { |l| l.include? 'FAIL' } test_failed(line_array) @test_failed += 1 - elsif line_array[@result_usual_idx..-2].any? {|l| l.include? 'IGNORE'} + elsif line_array[@result_usual_idx..-2].any? { |l| l.include? 'IGNORE' } test_ignored(line_array) @test_ignored += 1 - elsif line_array[@result_usual_idx..-1].any? {|l| l.include? 'IGNORE'} + elsif line_array[@result_usual_idx..-1].any? { |l| l.include? 'IGNORE' } line_array.push('No reason given (' + get_test_time(line_array[@result_usual_idx..-1]).to_s + ' ms)') test_ignored(line_array) @test_ignored += 1 @@ -374,7 +374,7 @@ if ARGV.size >= 1 if arg == '-xml' parse_my_file.set_xml_output elsif arg.start_with?('-suite') - parse_my_file.set_test_suite_name(arg) + parse_my_file.test_suite_name = arg.delete_prefix('-suite') else parse_my_file.process(arg) break