Adding a total time for each test package in the OVERALL SUMMARY
authorPatrik Svestka <patrik.svestka@gmail.com>
Fri, 24 Aug 2018 19:19:47 +0200
changeset 253 3747e4b3256b
parent 252 135a52fc8891
child 254 70c9861ad62f
Adding a total time for each test package in the OVERALL SUMMARY
rakelib/test.rake
--- a/rakelib/test.rake	Fri Aug 24 10:57:45 2018 +0200
+++ b/rakelib/test.rake	Fri Aug 24 19:19:47 2018 +0200
@@ -5,9 +5,9 @@
 # A helper class to keep a summary of a test report
 class TestReportSummary
   SUMMARIES = []
-  PATTERN = /tests=\"(?<run>\d+)\".+failures=\"(?<failed>\d+)\" errors=\"(?<errors>\d+)\" skipped=\"(?<skipped>\d+)\"/
+  PATTERN = /tests="(?<run>\d+)".+failures="(?<failed>\d+)" errors="(?<errors>\d+)" skipped="(?<skipped>\d+)" time="(?<time>\d+\.\d+)"/
 
-  attr_reader :pkg, :run, :failed, :errors, :skipped
+  attr_reader :pkg, :run, :failed, :errors, :skipped, :time
 
   def passed
     @run - @failed - @errors - @skipped
@@ -16,6 +16,13 @@
   def outcome
     (@failed > 0 or @errors > 0) ? 'FAILED' : 'PASSED'
   end
+  
+  def execution_time
+    hours   = (@time/3600).floor
+    minutes = (@time/60).floor
+    seconds = (@time%60).round
+    "#{hours}h:#{minutes}m:#{seconds}s"
+  end
 
   # Creates a new summary for given package and report file.
   def initialize(pkg_name, report_file)
@@ -30,6 +37,7 @@
     @failed = matches['failed'].to_i
     @errors = matches['errors'].to_i
     @skipped = matches['skipped'].to_i
+    @time = matches['time'].to_f
   end
 end
 
@@ -158,14 +166,15 @@
     puts 'OVERALL SUMMARY'
     puts
     TestReportSummary::SUMMARIES.each do |test_summary|
-      puts "%-20s %s - %d run, %d passed, %d skipped, %d failed, %d errors" % [
+      puts "%-20s %s - %d run, %d passed, %d skipped, %d failed, %d errors, execution time: %s" % [
         test_summary.pkg,
         test_summary.outcome,
         test_summary.run,
         test_summary.passed,
         test_summary.skipped,
         test_summary.failed,
-        test_summary.errors
+        test_summary.errors,
+        test_summary.execution_time
       ]
       outcome = 'FAILED' if test_summary.failed > 0 or test_summary.errors > 0
     end