rakelib/test.rake
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 28 May 2016 18:36:43 +0100
changeset 22 53b717983dfd
parent 15 5a7b5d08e46b
child 31 2689201485d0
permissions -rw-r--r--
Removed duplicated "build" string from report ident. BUILD_ID already contains string "build" when run under Jenkins.


desc "Run tests"
task :'test' => :'test:all'

desc "Run tests (alias for target test)"
task :'tests' => :'test'


task :'setup:tasks' => :'setup:tasks:test'

def run_report(app, packages, report, global_opts = '', report_opts = '')
  #run_report_st = BUILD_DIR / 'stx' / 'goodies' / 'builder' / 'reports' / 'report-runner-old.st'
  run_report_st = BUILD_DIR / 'stx' / 'goodies' / 'builder' / 'reports' / 'report-runner.st'
  coveragerportformat_dot_st = BUILD_DIR / 'stx' / 'goodies' / 'builder' / 'reports' / 'Builder__CoverageReportFormat.st'

  report_dir = File.expand_path(REPORT_DIR)

  if app
    exe_dir = BUILD_DIR / app.directory
    if win32?
      exe = "#{app.executable}.com"
    else
      exe = "./#{app.executable}"
    end
  else
    exe_dir = BUILD_DIR / 'stx' / 'projects' / 'smalltalk'
    if win32?
      exe = "stx.com"
    else
      exe = "./stx"
    end
  end

  chdir exe_dir do
    packages_args = ''
    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    
    sh "#{exe} #{runner_opts} #{global_opts} -i \"#{BUILD_ID}\" -D \"#{report_dir}\" -r #{report} #{report_opts} #{packages_args}"
  end
end

task :'setup:tasks:test' do
  app = project.application
  packages = []
  project.packages.each do | pkg |
    if pkg.test
      task "test:package:#{pkg.name}" => [ 'stx:goodies/builder/reports', REPORT_DIR ] do
        if pkg.coverage
          run_report(app, [ pkg.name ], 'Builder::TestReport',  '', '--coverage')
        else
          run_report(app, [ pkg.name ], 'Builder::TestReport')
	end
      end
      task :'test:packages' => "test:package:#{pkg.name}"
    end

    if pkg.lint
      task "lint:package:#{pkg.name}" => [ '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 ], 'Builder::LintReport')
      end
      task :'lint:packages' => "lint:package:#{pkg.name}"
    end
  end
end

task :'setup:tasks' => :'setup:tasks:test'
task :'test:setup' => :'setup'
task :'lint:setup' => :'setup'

namespace :'test' do
  task :'all' => [ :'setup', :'pre', :'main', :'post' ]
  task :'pre'
  task :'post'

  directory REPORT_DIR

  task :'setup'

  task :'main' => [:'setup', :'packages' ]

  task :'packages'
end

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'

  directory REPORT_DIR

  task :'setup'

  task :'main' => [:'setup', :'packages' ]

  task :'packages'
end



task BUILD_DIR / 'stx' / 'goodies' / 'builder' / 'reports'  => BUILD_DIR do
  if File.exist?(BUILD_DIR / 'stx' / 'goodies' / 'builder' / 'reports')
    update(:'swing:hg', 'stx/goodies/builder', :branch => 'jv')
  else
    checkout(:'swing:hg', 'stx/goodies/builder', :branch => 'jv')
  end
end

#task :'compile:post' => [ :'stx:builder/hudson', :'test' ]

task 'stx:goodies/builder/reports' => [ BUILD_DIR / 'stx' / 'goodies' / 'builder' / 'reports',
					:'compile:config' ] do
  chdir BUILD_DIR / 'stx' / 'goodies' / 'sunit' do
    make
  end
  chdir BUILD_DIR / 'stx' / 'goodies' / 'builder' / 'reports' do
    if (unix? and File.exist?("Makefile.init"))
      make "-f" "Makefile.init"
    else
      make
    end
  end
end