3 |
3 |
4 |
4 |
5 # A helper class to keep a summary of a test report |
5 # A helper class to keep a summary of a test report |
6 class TestReportSummary |
6 class TestReportSummary |
7 SUMMARIES = [] |
7 SUMMARIES = [] |
8 PATTERN = /tests=\"(?<run>\d+)\".+failures=\"(?<failed>\d+)\" errors=\"(?<errors>\d+)\" skipped=\"(?<skipped>\d+)\"/ |
8 PATTERN = /tests="(?<run>\d+)".+failures="(?<failed>\d+)" errors="(?<errors>\d+)" skipped="(?<skipped>\d+)" time="(?<time>\d+\.\d+)"/ |
9 |
9 |
10 attr_reader :pkg, :run, :failed, :errors, :skipped |
10 attr_reader :pkg, :run, :failed, :errors, :skipped, :time |
11 |
11 |
12 def passed |
12 def passed |
13 @run - @failed - @errors - @skipped |
13 @run - @failed - @errors - @skipped |
14 end |
14 end |
15 |
15 |
16 def outcome |
16 def outcome |
17 (@failed > 0 or @errors > 0) ? 'FAILED' : 'PASSED' |
17 (@failed > 0 or @errors > 0) ? 'FAILED' : 'PASSED' |
|
18 end |
|
19 |
|
20 def execution_time |
|
21 hours = (@time/3600).floor |
|
22 minutes = (@time/60).floor |
|
23 seconds = (@time%60).round |
|
24 "#{hours}h:#{minutes}m:#{seconds}s" |
18 end |
25 end |
19 |
26 |
20 # Creates a new summary for given package and report file. |
27 # Creates a new summary for given package and report file. |
21 def initialize(pkg_name, report_file) |
28 def initialize(pkg_name, report_file) |
22 raise Exception.new("Report file does not exist! #{report_file}") unless File.exist? report_file |
29 raise Exception.new("Report file does not exist! #{report_file}") unless File.exist? report_file |
28 raise Exception.new(%q{Cannot "parse" report file!}) unless matches |
35 raise Exception.new(%q{Cannot "parse" report file!}) unless matches |
29 @run = matches['run'].to_i |
36 @run = matches['run'].to_i |
30 @failed = matches['failed'].to_i |
37 @failed = matches['failed'].to_i |
31 @errors = matches['errors'].to_i |
38 @errors = matches['errors'].to_i |
32 @skipped = matches['skipped'].to_i |
39 @skipped = matches['skipped'].to_i |
|
40 @time = matches['time'].to_f |
33 end |
41 end |
34 end |
42 end |
35 |
43 |
36 desc 'Run tests' |
44 desc 'Run tests' |
37 task :test => :'test:all' |
45 task :test => :'test:all' |
156 end |
164 end |
157 puts |
165 puts |
158 puts 'OVERALL SUMMARY' |
166 puts 'OVERALL SUMMARY' |
159 puts |
167 puts |
160 TestReportSummary::SUMMARIES.each do |test_summary| |
168 TestReportSummary::SUMMARIES.each do |test_summary| |
161 puts "%-20s %s - %d run, %d passed, %d skipped, %d failed, %d errors" % [ |
169 puts "%-20s %s - %d run, %d passed, %d skipped, %d failed, %d errors, execution time: %s" % [ |
162 test_summary.pkg, |
170 test_summary.pkg, |
163 test_summary.outcome, |
171 test_summary.outcome, |
164 test_summary.run, |
172 test_summary.run, |
165 test_summary.passed, |
173 test_summary.passed, |
166 test_summary.skipped, |
174 test_summary.skipped, |
167 test_summary.failed, |
175 test_summary.failed, |
168 test_summary.errors |
176 test_summary.errors, |
|
177 test_summary.execution_time |
169 ] |
178 ] |
170 outcome = 'FAILED' if test_summary.failed > 0 or test_summary.errors > 0 |
179 outcome = 'FAILED' if test_summary.failed > 0 or test_summary.errors > 0 |
171 end |
180 end |
172 puts |
181 puts |
173 puts outcome |
182 puts outcome |