2017-02-07 21:30:57 +01:00
|
|
|
# ==========================================
|
|
|
|
# Unity Project - A Test Framework for C
|
|
|
|
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
|
|
|
# [Released under MIT License. Please refer to license.txt for details]
|
|
|
|
# ==========================================
|
|
|
|
|
2017-04-27 02:54:33 +02:00
|
|
|
# !/usr/bin/ruby
|
2017-02-07 21:30:57 +01:00
|
|
|
#
|
|
|
|
# unity_test_summary.rb
|
|
|
|
#
|
|
|
|
require 'fileutils'
|
|
|
|
require 'set'
|
|
|
|
|
|
|
|
class UnityTestSummary
|
|
|
|
include FileUtils::Verbose
|
|
|
|
|
|
|
|
attr_reader :report, :total_tests, :failures, :ignored
|
2017-04-27 02:54:33 +02:00
|
|
|
attr_writer :targets, :root
|
2017-02-07 21:30:57 +01:00
|
|
|
|
2017-04-27 02:54:33 +02:00
|
|
|
def initialize(_opts = {})
|
2017-02-07 21:30:57 +01:00
|
|
|
@report = ''
|
|
|
|
@total_tests = 0
|
|
|
|
@failures = 0
|
|
|
|
@ignored = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
# Clean up result file names
|
2017-04-27 02:54:33 +02:00
|
|
|
results = @targets.map { |target| target.tr('\\', '/') }
|
2017-02-07 21:30:57 +01:00
|
|
|
|
|
|
|
# Dig through each result file, looking for details on pass/fail:
|
|
|
|
failure_output = []
|
|
|
|
ignore_output = []
|
|
|
|
|
|
|
|
results.each do |result_file|
|
2017-04-27 02:54:33 +02:00
|
|
|
lines = File.readlines(result_file).map(&:chomp)
|
|
|
|
|
|
|
|
raise "Empty test result file: #{result_file}" if lines.empty?
|
|
|
|
|
|
|
|
output = get_details(result_file, lines)
|
|
|
|
failure_output << output[:failures] unless output[:failures].empty?
|
|
|
|
ignore_output << output[:ignores] unless output[:ignores].empty?
|
|
|
|
tests, failures, ignored = parse_test_summary(lines)
|
|
|
|
@total_tests += tests
|
|
|
|
@failures += failures
|
|
|
|
@ignored += ignored
|
2017-02-07 21:30:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if @ignored > 0
|
|
|
|
@report += "\n"
|
|
|
|
@report += "--------------------------\n"
|
|
|
|
@report += "UNITY IGNORED TEST SUMMARY\n"
|
|
|
|
@report += "--------------------------\n"
|
|
|
|
@report += ignore_output.flatten.join("\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
if @failures > 0
|
|
|
|
@report += "\n"
|
|
|
|
@report += "--------------------------\n"
|
|
|
|
@report += "UNITY FAILED TEST SUMMARY\n"
|
|
|
|
@report += "--------------------------\n"
|
|
|
|
@report += failure_output.flatten.join("\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
@report += "\n"
|
|
|
|
@report += "--------------------------\n"
|
|
|
|
@report += "OVERALL UNITY TEST SUMMARY\n"
|
|
|
|
@report += "--------------------------\n"
|
|
|
|
@report += "#{@total_tests} TOTAL TESTS #{@failures} TOTAL FAILURES #{@ignored} IGNORED\n"
|
|
|
|
@report += "\n"
|
|
|
|
end
|
|
|
|
|
2017-04-27 02:54:33 +02:00
|
|
|
def usage(err_msg = nil)
|
2017-02-07 21:30:57 +01:00
|
|
|
puts "\nERROR: "
|
|
|
|
puts err_msg if err_msg
|
|
|
|
puts "\nUsage: unity_test_summary.rb result_file_directory/ root_path/"
|
2017-04-27 02:54:33 +02:00
|
|
|
puts ' result_file_directory - The location of your results files.'
|
|
|
|
puts ' Defaults to current directory if not specified.'
|
|
|
|
puts ' Should end in / if specified.'
|
|
|
|
puts ' root_path - Helpful for producing more verbose output if using relative paths.'
|
2017-02-07 21:30:57 +01:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2017-04-27 02:54:33 +02:00
|
|
|
def get_details(_result_file, lines)
|
|
|
|
results = { failures: [], ignores: [], successes: [] }
|
2017-02-07 21:30:57 +01:00
|
|
|
lines.each do |line|
|
2017-04-27 02:54:33 +02:00
|
|
|
_src_file, _src_line, _test_name, status, _msg = line.split(/:/)
|
|
|
|
line_out = (@root && (@root != 0) ? "#{@root}#{line}" : line).gsub(/\//, '\\')
|
|
|
|
case status
|
|
|
|
when 'IGNORE' then results[:ignores] << line_out
|
|
|
|
when 'FAIL' then results[:failures] << line_out
|
|
|
|
when 'PASS' then results[:successes] << line_out
|
2017-02-07 21:30:57 +01:00
|
|
|
end
|
|
|
|
end
|
2017-04-27 02:54:33 +02:00
|
|
|
results
|
2017-02-07 21:30:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def parse_test_summary(summary)
|
2017-04-27 02:54:33 +02:00
|
|
|
raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ }
|
|
|
|
[Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i]
|
2017-02-07 21:30:57 +01:00
|
|
|
end
|
|
|
|
|
2017-04-27 02:54:33 +02:00
|
|
|
def here
|
|
|
|
File.expand_path(File.dirname(__FILE__))
|
|
|
|
end
|
2017-02-07 21:30:57 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if $0 == __FILE__
|
|
|
|
|
2017-04-27 02:54:33 +02:00
|
|
|
# parse out the command options
|
|
|
|
opts, args = ARGV.partition { |v| v =~ /^--\w+/ }
|
|
|
|
opts.map! { |v| v[2..-1].to_sym }
|
2017-02-07 21:30:57 +01:00
|
|
|
|
2017-04-27 02:54:33 +02:00
|
|
|
# create an instance to work with
|
2017-02-07 21:30:57 +01:00
|
|
|
uts = UnityTestSummary.new(opts)
|
|
|
|
|
|
|
|
begin
|
2017-04-27 02:54:33 +02:00
|
|
|
# look in the specified or current directory for result files
|
2017-02-07 21:30:57 +01:00
|
|
|
args[0] ||= './'
|
2017-04-27 02:54:33 +02:00
|
|
|
targets = "#{ARGV[0].tr('\\', '/')}**/*.test*"
|
2017-02-07 21:30:57 +01:00
|
|
|
results = Dir[targets]
|
|
|
|
raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty?
|
2017-04-27 02:54:33 +02:00
|
|
|
uts.targets = results
|
2017-02-07 21:30:57 +01:00
|
|
|
|
2017-04-27 02:54:33 +02:00
|
|
|
# set the root path
|
2017-02-07 21:30:57 +01:00
|
|
|
args[1] ||= Dir.pwd + '/'
|
2017-04-27 02:54:33 +02:00
|
|
|
uts.root = ARGV[1]
|
2017-02-07 21:30:57 +01:00
|
|
|
|
2017-04-27 02:54:33 +02:00
|
|
|
# run the summarizer
|
2017-02-07 21:30:57 +01:00
|
|
|
puts uts.run
|
2017-04-27 02:54:33 +02:00
|
|
|
rescue StandardError => e
|
2017-02-07 21:30:57 +01:00
|
|
|
uts.usage e.message
|
|
|
|
end
|
|
|
|
end
|