1 # ==========================================
2 # Unity Project - A Test Framework for C
3 # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
4 # [Released under MIT License. Please refer to license.txt for details]
5 # ==========================================
9 # unity_test_summary.rb
14 class UnityTestSummary
15 include FileUtils::Verbose
17 attr_reader :report, :total_tests, :failures, :ignored
19 def initialize(opts = {})
29 # Clean up result file names
30 results = @targets.map {|target| target.gsub(/\\/,'/')}
32 # Dig through each result file, looking for details on pass/fail:
36 results.each do |result_file|
37 lines = File.readlines(result_file).map { |line| line.chomp }
39 raise "Empty test result file: #{result_file}"
41 output = get_details(result_file, lines)
42 failure_output << output[:failures] unless output[:failures].empty?
43 ignore_output << output[:ignores] unless output[:ignores].empty?
44 tests,failures,ignored = parse_test_summary(lines)
53 @report += "--------------------------\n"
54 @report += "UNITY IGNORED TEST SUMMARY\n"
55 @report += "--------------------------\n"
56 @report += ignore_output.flatten.join("\n")
61 @report += "--------------------------\n"
62 @report += "UNITY FAILED TEST SUMMARY\n"
63 @report += "--------------------------\n"
64 @report += failure_output.flatten.join("\n")
68 @report += "--------------------------\n"
69 @report += "OVERALL UNITY TEST SUMMARY\n"
70 @report += "--------------------------\n"
71 @report += "#{@total_tests} TOTAL TESTS #{@failures} TOTAL FAILURES #{@ignored} IGNORED\n"
75 def set_targets(target_array)
76 @targets = target_array
79 def set_root_path(path)
83 def usage(err_msg=nil)
85 puts err_msg if err_msg
86 puts "\nUsage: unity_test_summary.rb result_file_directory/ root_path/"
87 puts " result_file_directory - The location of your results files."
88 puts " Defaults to current directory if not specified."
89 puts " Should end in / if specified."
90 puts " root_path - Helpful for producing more verbose output if using relative paths."
96 def get_details(result_file, lines)
97 results = { :failures => [], :ignores => [], :successes => [] }
99 src_file,src_line,test_name,status,msg = line.split(/:/)
100 line_out = ((@root && (@root != 0)) ? "#{@root}#{line}" : line ).gsub(/\//, "\\")
102 when 'IGNORE' then results[:ignores] << line_out
103 when 'FAIL' then results[:failures] << line_out
104 when 'PASS' then results[:successes] << line_out
110 def parse_test_summary(summary)
111 if summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ }
112 [$1.to_i,$2.to_i,$3.to_i]
114 raise "Couldn't parse test results: #{summary}"
118 def here; File.expand_path(File.dirname(__FILE__)); end
124 #parse out the command options
125 opts, args = ARGV.partition {|v| v =~ /^--\w+/}
126 opts.map! {|v| v[2..-1].to_sym }
128 #create an instance to work with
129 uts = UnityTestSummary.new(opts)
132 #look in the specified or current directory for result files
134 targets = "#{ARGV[0].gsub(/\\/, '/')}**/*.test*"
135 results = Dir[targets]
136 raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty?
137 uts.set_targets(results)
140 args[1] ||= Dir.pwd + '/'
141 uts.set_root_path(ARGV[1])
145 rescue Exception => e