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# ========================================== 6 7#!/usr/bin/ruby 8# 9# unity_test_summary.rb 10# 11require 'fileutils' 12require 'set' 13 14class UnityTestSummary 15 include FileUtils::Verbose 16 17 attr_reader :report, :total_tests, :failures, :ignored 18 19 def initialize 20 @report = '' 21 @total_tests = 0 22 @failures = 0 23 @ignored = 0 24 end 25 26 def run 27 # Clean up result file names 28 results = @targets.map {|target| target.gsub(/\\/,'/')} 29 30 # Dig through each result file, looking for details on pass/fail: 31 failure_output = [] 32 ignore_output = [] 33 34 results.each do |result_file| 35 lines = File.readlines(result_file).map { |line| line.chomp } 36 if lines.length == 0 37 raise "Empty test result file: #{result_file}" 38 else 39 output = get_details(result_file, lines) 40 failure_output << output[:failures] unless output[:failures].empty? 41 ignore_output << output[:ignores] unless output[:ignores].empty? 42 tests,failures,ignored = parse_test_summary(lines) 43 @total_tests += tests 44 @failures += failures 45 @ignored += ignored 46 end 47 end 48 49 if @ignored > 0 50 @report += "\n" 51 @report += "--------------------------\n" 52 @report += "UNITY IGNORED TEST SUMMARY\n" 53 @report += "--------------------------\n" 54 @report += ignore_output.flatten.join("\n") 55 end 56 57 if @failures > 0 58 @report += "\n" 59 @report += "--------------------------\n" 60 @report += "UNITY FAILED TEST SUMMARY\n" 61 @report += "--------------------------\n" 62 @report += failure_output.flatten.join("\n") 63 end 64 65 @report += "\n" 66 @report += "--------------------------\n" 67 @report += "OVERALL UNITY TEST SUMMARY\n" 68 @report += "--------------------------\n" 69 @report += "#{@total_tests} TOTAL TESTS #{@failures} TOTAL FAILURES #{@ignored} IGNORED\n" 70 @report += "\n" 71 end 72 73 def set_targets(target_array) 74 @targets = target_array 75 end 76 77 def set_root_path(path) 78 @root = path 79 end 80 81 def usage(err_msg=nil) 82 puts err_msg if err_msg 83 puts "Usage: unity_test_summary.rb" 84 exit 1 85 end 86 87 protected 88 89 @@targets=nil 90 @@path=nil 91 @@root=nil 92 93 def get_details(result_file, lines) 94 results = { :failures => [], :ignores => [], :successes => [] } 95 lines.each do |line| 96 src_file,src_line,test_name,status,msg = line.split(/:/) 97 line_out = ((@root and (@root != 0)) ? "#{@root}#{line}" : line ).gsub(/\//, "\\") 98 case(status) 99 when 'IGNORE' then results[:ignores] << line_out 100 when 'FAIL' then results[:failures] << line_out 101 when 'PASS' then results[:successes] << line_out 102 end 103 end 104 return results 105 end 106 107 def parse_test_summary(summary) 108 if summary[-3..-1].join("\n") =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ 109 [$1.to_i,$2.to_i,$3.to_i] 110 else 111 raise "Couldn't parse test results: #{summary}" 112 end 113 end 114 115 def here; File.expand_path(File.dirname(__FILE__)); end 116 117end 118 119if $0 == __FILE__ 120 script = UnityTestSummary.new 121 begin 122 script.run 123 rescue Exception => e 124 script.usage e.message 125 end 126end 127