mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-08-13 22:57:53 +00:00
modified to have a bit more generic and useful interface
git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@30 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
+39
-41
@@ -6,73 +6,65 @@ require 'fileutils'
|
|||||||
require 'set'
|
require 'set'
|
||||||
|
|
||||||
class UnityTestSummary
|
class UnityTestSummary
|
||||||
|
|
||||||
include FileUtils::Verbose
|
include FileUtils::Verbose
|
||||||
|
|
||||||
|
attr_reader :report, :total_tests, :failures, :ignored
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@report = ''
|
||||||
|
@total_tests = 0
|
||||||
|
@failures = 0
|
||||||
|
@ignored = 0
|
||||||
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
|
|
||||||
$stderr.flush
|
|
||||||
$stdout.flush
|
|
||||||
|
|
||||||
# Clean up result file names
|
# Clean up result file names
|
||||||
results = @targets.map {|target| target.gsub(/\\/,'/')}
|
results = @targets.map {|target| target.gsub(/\\/,'/')}
|
||||||
|
|
||||||
# Dig through each result file, looking for details on pass/fail:
|
# Dig through each result file, looking for details on pass/fail:
|
||||||
total_tests = 0
|
|
||||||
total_failures = 0
|
|
||||||
total_ignored = 0
|
|
||||||
|
|
||||||
failure_output = ""
|
failure_output = ""
|
||||||
ignore_output = ""
|
ignore_output = ""
|
||||||
|
|
||||||
results.each do |result_file|
|
results.each do |result_file|
|
||||||
lines = File.readlines(result_file).map { |line| line.chomp }
|
lines = File.readlines(result_file).map { |line| line.chomp }
|
||||||
if lines.length == 0
|
if lines.length == 0
|
||||||
puts "Empty test result file: #{result_file}"
|
raise "Empty test result file: #{result_file}"
|
||||||
else
|
else
|
||||||
summary_line = -2
|
summary_line = -2
|
||||||
output = get_details(result_file, lines)
|
output = get_details(result_file, lines)
|
||||||
failure_output += output[:failures] if !output[:failures].empty?
|
failure_output += output[:failures] if !output[:failures].empty?
|
||||||
ignore_output += output[:ignores] if !output[:ignores].empty?
|
ignore_output += output[:ignores] if !output[:ignores].empty?
|
||||||
tests,failures,ignored = parse_test_summary(lines[summary_line])
|
tests,failures,ignored = parse_test_summary(lines[summary_line])
|
||||||
total_tests += tests
|
@total_tests += tests
|
||||||
total_failures += failures
|
@failures += failures
|
||||||
total_ignored += ignored
|
@ignored += ignored
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if total_ignored > 0
|
if @ignored > 0
|
||||||
puts "\n"
|
@report += "\n"
|
||||||
puts "--------------------------\n"
|
@report += "--------------------------\n"
|
||||||
puts "UNITY IGNORED TEST SUMMARY\n"
|
@report += "UNITY IGNORED TEST SUMMARY\n"
|
||||||
puts "--------------------------\n"
|
@report += "--------------------------\n"
|
||||||
puts ignore_output
|
@report += ignore_output
|
||||||
end
|
end
|
||||||
|
|
||||||
if total_failures > 0
|
if @failures > 0
|
||||||
puts "\n"
|
@report += "\n"
|
||||||
puts "--------------------------\n"
|
@report += "--------------------------\n"
|
||||||
puts "UNITY FAILED TEST SUMMARY\n"
|
@report += "UNITY FAILED TEST SUMMARY\n"
|
||||||
puts "--------------------------\n"
|
@report += "--------------------------\n"
|
||||||
puts failure_output
|
@report += failure_output
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "\n"
|
@report += "\n"
|
||||||
puts "--------------------------\n"
|
@report += "--------------------------\n"
|
||||||
puts "OVERALL UNITY TEST SUMMARY\n"
|
@report += "OVERALL UNITY TEST SUMMARY\n"
|
||||||
puts "--------------------------\n"
|
@report += "--------------------------\n"
|
||||||
puts "TOTAL TESTS: #{total_tests} TOTAL FAILURES: #{total_failures} IGNORED: #{total_ignored}\n"
|
@report += "TOTAL TESTS: #{@total_tests} TOTAL FAILURES: #{@failures} IGNORED: #{@ignored}\n"
|
||||||
puts "\n"
|
@report += "\n"
|
||||||
|
|
||||||
return total_failures
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def usage(err_msg=nil)
|
|
||||||
puts err_msg if err_msg
|
|
||||||
puts "Usage: unity_test_summary.rb"
|
|
||||||
exit 1
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_targets(target_array)
|
def set_targets(target_array)
|
||||||
@targets = target_array
|
@targets = target_array
|
||||||
end
|
end
|
||||||
@@ -81,6 +73,12 @@ class UnityTestSummary
|
|||||||
@root = path
|
@root = path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def usage(err_msg=nil)
|
||||||
|
puts err_msg if err_msg
|
||||||
|
puts "Usage: unity_test_summary.rb"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
@@targets=nil
|
@@targets=nil
|
||||||
|
|||||||
Reference in New Issue
Block a user