rakelib/test.rake
changeset 137 e665031cade7
parent 121 dd6b76197aa0
child 140 f5b73114d0f1
--- a/rakelib/test.rake	Mon Mar 06 21:21:07 2017 +0000
+++ b/rakelib/test.rake	Fri Aug 11 09:23:06 2017 +0200
@@ -7,32 +7,25 @@
   SUMMARIES = []
   PATTERN = /tests=\"(?<run>\d+)\".+failures=\"(?<failed>\d+)\" errors=\"(?<errors>\d+)\" skipped=\"(?<skipped>\d+)\"/
 
-  attr_reader :pkg, :run, :failed, :errors, :skipped 
+  attr_reader :pkg, :run, :failed, :errors, :skipped
 
   def passed
-    return @run - @failed - @errors - @skipped
+    @run - @failed - @errors - @skipped
   end
 
   def outcome
-    if @failed > 0 or @errors > 0 then
-      return 'FAILED'
-    else
-      return 'PASSED'
-    end
+    (@failed > 0 or @errors > 0) ? 'FAILED' : 'PASSED'
   end
 
   # Creates a new summary for given package and report file. 
   def initialize(pkg_name, report_file)
-    if not File.exist? report_file then 
-      raise Exception.new("Report file does not exist! #{report_file}");
-    end
+    raise Exception.new("Report file does not exist! #{report_file}") unless File.exist? report_file
     @pkg = pkg_name
     matches = PATTERN.match(IO.read(report_file, 512))
-    if not matches then
-      raise Exception.new("Cannot \"parse\" report file!")
-      # Maybe the buffer is too small? Try to read up more
-      # data....
-    end
+
+    # Maybe the buffer is too small? Try to read up more
+    # data....
+    raise Exception.new(%q{Cannot "parse" report file!}) unless matches
     @run = matches['run'].to_i
     @failed = matches['failed'].to_i
     @errors = matches['errors'].to_i
@@ -40,11 +33,11 @@
   end
 end
 
-desc "Run tests"
-task :'test' => :'test:all'
+desc 'Run tests'
+task :test => :'test:all'
 
-desc "Run tests (alias for target test)"
-task :'tests' => :'test'
+desc 'Run tests (alias for target test)'
+task :tests => :'test'
 
 
 task :'setup:tasks' => :'setup:tasks:test'
@@ -56,7 +49,7 @@
 
   report_dir = File.expand_path(REPORT_DIR)
   tmp_dir = File.expand_path(TMP_DIR)
-  
+
   # Set STX_TMPDIR environment to make sure all temporary files created by 
   # Smalltalk/X goes to a local tmp directory (which should be discarded 
   # regularly). This helps to avoid garbage to heap up on Windows slaves 
@@ -65,32 +58,18 @@
 
   if app
     exe_dir = BUILD_DIR / app.directory
-    if win32?
-      exe = "#{app.executable}.com"
-    else
-      exe = "./#{app.executable}"
-    end
+    win32? ? (exe = "#{app.executable}.com") : (exe = "./#{app.executable}")
   else
     exe_dir = BUILD_DIR / 'stx' / 'projects' / 'smalltalk'
-    if win32?
-      exe = "stx.com"
-    else
-      exe = "./stx"
-    end
+    win32? ? (exe = 'stx.com') : (exe = './stx')
   end
 
-  if not File.directory? tmp_dir then
-    mkdir_p tmp_dir
-  end
+  (mkdir_p tmp_dir) unless File.directory?(tmp_dir)
   chdir exe_dir do
     packages_args = ''
-    packages.each { | p | packages_args += " -p #{p}" }
+    packages.each {|p| packages_args += " -p #{p}"}
 
-    if File.exist?(coveragerportformat_dot_st)
-        runner_opts = "-abortOnSEGV -I --execute #{run_report_st}"
-    else
-        runner_opts = "-I -f #{run_report_st}"
-    end    
+    File.exist?(coveragerportformat_dot_st) ? (runner_opts = "-abortOnSEGV -I --execute #{run_report_st}") : (runner_opts = "-I -f #{run_report_st}")
     sh "#{exe} #{runner_opts} #{global_opts} -i \"#{BUILD_ID}\" -D \"#{report_dir}\" -r #{report} #{report_opts} #{packages_args}"
   end
   rm_rf tmp_dir
@@ -98,10 +77,10 @@
 
 task :'setup:tasks:test' do
   $__testresults__ = []
-  app = project.application  
-  project.packages.each do | pkg |
+  app = project.application
+  project.packages.each do |pkg|
     if pkg.test
-      task "test:package:#{pkg.name}" => [ 'stx:goodies/builder/reports', REPORT_DIR ] do
+      task "test:package:#{pkg.name}" => ['stx:goodies/builder/reports', REPORT_DIR] do
         report_file = File.expand_path(REPORT_DIR) / "#{pkg.name_components.join('_')}-#{BUILD_ID}-Test.xml"
         # Sigh, sigh. On CI server, sometimes it happen that tests are simply not run. 
         # I was not able to debug the issue anyhow, any attempt to attach a debugger,
@@ -112,28 +91,22 @@
         # like this. Sorry. 
         #
         # Let's see if it helps. 
-        for i in 1..5 do
-          if pkg.coverage
-            run_report(app, [ pkg.name ], TESTREPORT_CLASS,  '', '--coverage')
-          else
-            run_report(app, [ pkg.name ], TESTREPORT_CLASS)
-          end
+        5.times do #for i in 1..5 do
+          pkg.coverage ? run_report(app, [pkg.name], TESTREPORT_CLASS, '', '--coverage') : run_report(app, [pkg.name], TESTREPORT_CLASS)
           # Extract summary from XML report and keep it. Yeah, parsing XML
           # using regexps is a bad thing, but it's quick and lot less code!          
-          if File.exist? report_file then            
-            break
-          end          
+          break if File.exist?(report_file)
         end
-        report_summary = TestReportSummary.new(pkg.name, report_file);
-        TestReportSummary::SUMMARIES << report_summary    
+        report_summary = TestReportSummary.new(pkg.name, report_file)
+        TestReportSummary::SUMMARIES << report_summary
       end
       task :'test:packages' => "test:package:#{pkg.name}"
     end
 
     if pkg.lint
-      task "lint:package:#{pkg.name}" => [ 'stx:goodies/builder/reports', REPORT_DIR ]  do
+      task "lint:package:#{pkg.name}" => %W(stx:goodies/builder/reports REPORT_DIR) do
         #puts "LINT DISABLED (because of some bug in recent SmallLint - runs out of memory)"
-        run_report(app, [ pkg.name ], LINTREPORT_CLASS)
+        run_report(app, [pkg.name], LINTREPORT_CLASS)
       end
       task :'lint:packages' => "lint:package:#{pkg.name}"
     end
@@ -141,60 +114,58 @@
 end
 
 task :'setup:tasks' => :'setup:tasks:test'
-task :'test:setup' => :'setup'
-task :'lint:setup' => :'setup'
+task :'test:setup' => :setup
+task :'lint:setup' => :setup
 
-namespace :'test' do
-  task :'all' => [ :'setup', :'pre', :'main', :'post' ]
-  task :'pre'
-  task :'post'
+namespace :test do
+  task :all => %i(setup pre main post)
+  task :pre
+  task :post
 
   directory REPORT_DIR
 
-  task :'setup' => :'setup:dependencies'
+  task :setup => :'setup:dependencies'
 
-  task :'main' => [:'setup', :'packages', :'summary' ]
+  task :main => %i(setup packages summary)
 
-  task :'packages'
+  task :packages
 
-  task :'summary' do
+  task :summary do
     outcome = 'PASSED'
-    puts 
-    puts "OVERALL SUMMARY"
+    puts
+    puts 'OVERALL SUMMARY'
     puts
-    TestReportSummary::SUMMARIES.each do | test_summary |
-      puts "%-20s %s - %d run, %d passed, %d skipped, %d failed, %d errors" % [
-        test_summary.pkg,
-        test_summary.outcome,
-        test_summary.run,
-        test_summary.passed,
-        test_summary.skipped,
-        test_summary.failed,
+    TestReportSummary::SUMMARIES.each do |test_summary|
+      puts "%-20s %s - %d run, %d passed, %d skipped, %d failed, %d errors" % %W(
+        test_summary.pkg
+        test_summary.outcome
+        test_summary.run
+        test_summary.passed
+        test_summary.skipped
+        test_summary.failed
         test_summary.errors
-      ]
-      if test_summary.failed > 0 or test_summary.errors > 0 then
-        outcome = 'FAILED'
-      end
+      )
+      outcome = 'FAILED' if test_summary.failed > 0 or test_summary.errors > 0
     end
     puts
     puts outcome
   end
 end
 
-desc "Run static analysis on the code (SmallLint)"
-task :'lint' => :'lint:all'
+desc 'Run static analysis on the code (SmallLint)'
+task :lint => :'lint:all'
 
 
-namespace :'lint' do
-  task :'all' => [ :'setup', :'pre', :'main', :'post' ]
-  task :'pre'
-  task :'post'
+namespace :lint do
+  task :all => %i(setup pre main post)
+  task :pre
+  task :post
 
   directory REPORT_DIR
 
-  task :'setup'
+  task :setup
 
-  task :'main' => [:'setup', :'packages' ]
+  task :main => %i(setup packages)
 
-  task :'packages'
+  task :packages
 end