rakelib/test.rake
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 20 Jan 2020 11:34:02 +0000
changeset 286 c08455e14746
parent 254 70c9861ad62f
permissions -rw-r--r--
Rakefiles: add support for manual dependency definitions Normally, pacjage dependencies are extracted automatically from package definition but eXept sometimes get dependencies wrong. As we (still, sigh) use some packages form eXept's CVS tree, this commit introduces `dependencies.rbspec` that has these manually fixed. This commit also includes fix for an issue with `stx:goodies/communication`
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
     1
TESTREPORT_CLASS = 'Builder::TestReport'
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
     2
LINTREPORT_CLASS = 'Builder::LintReport'
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
     3
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
     4
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
     5
# A helper class to keep a summary of a test report
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
     6
class TestReportSummary
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
     7
  SUMMARIES = []
253
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
     8
  PATTERN = /tests="(?<run>\d+)".+failures="(?<failed>\d+)" errors="(?<errors>\d+)" skipped="(?<skipped>\d+)" time="(?<time>\d+\.\d+)"/
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
     9
253
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
    10
  attr_reader :pkg, :run, :failed, :errors, :skipped, :time
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    11
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    12
  def passed
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    13
    @run - @failed - @errors - @skipped
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    14
  end
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    15
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    16
  def outcome
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    17
    (@failed > 0 or @errors > 0) ? 'FAILED' : 'PASSED'
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    18
  end
253
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
    19
  
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
    20
  def execution_time
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
    21
    hours   = (@time/3600).floor
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
    22
    minutes = (@time/60).floor
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
    23
    seconds = (@time%60).round
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
    24
    "#{hours}h:#{minutes}m:#{seconds}s"
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
    25
  end
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    26
218
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
    27
  # Creates a new summary for given package and report file.
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    28
  def initialize(pkg_name, report_file)
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    29
    raise Exception.new("Report file does not exist! #{report_file}") unless File.exist? report_file
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    30
    @pkg = pkg_name
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    31
    matches = PATTERN.match(IO.read(report_file, 512))
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    32
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    33
    # Maybe the buffer is too small? Try to read up more
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    34
    # data....
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    35
    raise Exception.new(%q{Cannot "parse" report file!}) unless matches
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    36
    @run = matches['run'].to_i
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    37
    @failed = matches['failed'].to_i
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    38
    @errors = matches['errors'].to_i
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    39
    @skipped = matches['skipped'].to_i
253
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
    40
    @time = matches['time'].to_f
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    41
  end
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    42
end
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    44
desc 'Run tests'
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    45
task :test => :'test:all'
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    46
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    47
desc 'Run tests (alias for target test)'
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    48
task :tests => :'test'
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    51
task :'setup:tasks' => :'setup:tasks:test'
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
def run_report(app, packages, report, global_opts = '', report_opts = '')
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
  #run_report_st = BUILD_DIR / 'stx' / 'goodies' / 'builder' / 'reports' / 'report-runner-old.st'
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
  run_report_st = BUILD_DIR / 'stx' / 'goodies' / 'builder' / 'reports' / 'report-runner.st'
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
  coveragerportformat_dot_st = BUILD_DIR / 'stx' / 'goodies' / 'builder' / 'reports' / 'Builder__CoverageReportFormat.st'
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
  report_dir = File.expand_path(REPORT_DIR)
77
570ae23d0ce2 Specify (nonstandard) temporary directory when running tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 69
diff changeset
    59
  tmp_dir = File.expand_path(TMP_DIR)
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    60
218
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
    61
  # Set STX_TMPDIR environment to make sure all temporary files created by
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
    62
  # Smalltalk/X goes to a local tmp directory (which should be discarded
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
    63
  # regularly). This helps to avoid garbage to heap up on Windows slaves
77
570ae23d0ce2 Specify (nonstandard) temporary directory when running tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 69
diff changeset
    64
  # assuming workspaces is thrown away often.
570ae23d0ce2 Specify (nonstandard) temporary directory when running tests
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 69
diff changeset
    65
  ENV['STX_TMPDIR'] = tmp_dir
218
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
    66
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
  if app
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
    exe_dir = BUILD_DIR / app.directory
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    69
    win32? ? (exe = "#{app.executable}.com") : (exe = "./#{app.executable}")
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
  else
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    71
    exe_dir = BUILD_DIR / 'stx' / 'projects' / 'smalltalk'
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    72
    win32? ? (exe = 'stx.com') : (exe = './stx')
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    73
  end
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    74
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    75
  (mkdir_p tmp_dir) unless File.directory?(tmp_dir)
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    76
  chdir exe_dir do
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    77
    packages_args = ''
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    78
    packages.each {|p| packages_args += " -p #{p}"}
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    79
187
79e249bd767a Rakefiles: run tests with `--abortInInternalError`
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 141
diff changeset
    80
    File.exist?(coveragerportformat_dot_st) ? (runner_opts = "--abortOnSEGV --abortOnInternalError -I --execute #{run_report_st}") : (runner_opts = "-I -f #{run_report_st}")
22
53b717983dfd Removed duplicated "build" string from report ident.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 15
diff changeset
    81
    sh "#{exe} #{runner_opts} #{global_opts} -i \"#{BUILD_ID}\" -D \"#{report_dir}\" -r #{report} #{report_opts} #{packages_args}"
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    82
  end
149
8fd5aaf96f75 Rakefiles: do not remove temporary directory after tests are run
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 141
diff changeset
    83
  # No, do not remove tmp_dir here. If a test fails,
8fd5aaf96f75 Rakefiles: do not remove temporary directory after tests are run
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 141
diff changeset
    84
  # then temp dir may contain valuable files to debug/reproduce
8fd5aaf96f75 Rakefiles: do not remove temporary directory after tests are run
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 141
diff changeset
    85
  # (bad image files, outputs and so on). 
8fd5aaf96f75 Rakefiles: do not remove temporary directory after tests are run
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 141
diff changeset
    86
  # Depend on some other external process to wipe out temp directory
8fd5aaf96f75 Rakefiles: do not remove temporary directory after tests are run
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 141
diff changeset
    87
  # once not needed (full CI build cycle should do that)
8fd5aaf96f75 Rakefiles: do not remove temporary directory after tests are run
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 141
diff changeset
    88
  #
8fd5aaf96f75 Rakefiles: do not remove temporary directory after tests are run
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 141
diff changeset
    89
  # rm_rf tmp_dir
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    90
end
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    91
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    92
task :'setup:tasks:test' do
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
    93
  $__testresults__ = []
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
    94
  app = project.application
250
86db38276922 Rakefiles: execute tests in random order
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 236
diff changeset
    95
86db38276922 Rakefiles: execute tests in random order
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 236
diff changeset
    96
  # We shuffle the order of the packages by purpose.
86db38276922 Rakefiles: execute tests in random order
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 236
diff changeset
    97
  # Some tests are CPU bound while some are IO bound,
86db38276922 Rakefiles: execute tests in random order
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 236
diff changeset
    98
  # so this should help to distribute the load more evenly
86db38276922 Rakefiles: execute tests in random order
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 236
diff changeset
    99
  # in cases where multiple tests (`rake test` invocations)
86db38276922 Rakefiles: execute tests in random order
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 236
diff changeset
   100
  # are run in parallel (such as on CI)
86db38276922 Rakefiles: execute tests in random order
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 236
diff changeset
   101
  project.packages.shuffle.each do |pkg|
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   102
    if pkg.test
218
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   103
      task "test:package:#{pkg.name}:pre"
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   104
      task "test:package:#{pkg.name}:post"
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   105
      task "test:package:#{pkg.name}:main" => ['stx:goodies/builder/reports', REPORT_DIR] do
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   106
        report_file = File.expand_path(REPORT_DIR) / "#{pkg.name_components.join('_')}-#{BUILD_ID}-Test.xml"
218
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   107
        # Sigh, sigh. On CI server, sometimes it happen that tests are simply not run.
121
dd6b76197aa0 CI: An attempt to address a mysterious problem occuring only on CI server
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 93
diff changeset
   108
        # I was not able to debug the issue anyhow, any attempt to attach a debugger,
dd6b76197aa0 CI: An attempt to address a mysterious problem occuring only on CI server
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 93
diff changeset
   109
        # add a debug print or run it manually failed as the problem did not manifest.
218
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   110
        #
121
dd6b76197aa0 CI: An attempt to address a mysterious problem occuring only on CI server
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 93
diff changeset
   111
        # This is a feeble and horrible attempt to just cover up the problem by
dd6b76197aa0 CI: An attempt to address a mysterious problem occuring only on CI server
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 93
diff changeset
   112
        # trying multiple times. I don't want to spend more time chasing issues
218
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   113
        # like this. Sorry.
121
dd6b76197aa0 CI: An attempt to address a mysterious problem occuring only on CI server
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 93
diff changeset
   114
        #
218
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   115
        # Let's see if it helps.
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   116
        5.times do #for i in 1..5 do
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   117
          pkg.coverage ? run_report(app, [pkg.name], TESTREPORT_CLASS, '', '--coverage') : run_report(app, [pkg.name], TESTREPORT_CLASS)
121
dd6b76197aa0 CI: An attempt to address a mysterious problem occuring only on CI server
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 93
diff changeset
   118
          # Extract summary from XML report and keep it. Yeah, parsing XML
218
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   119
          # using regexps is a bad thing, but it's quick and lot less code!
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   120
          break if File.exist?(report_file)
121
dd6b76197aa0 CI: An attempt to address a mysterious problem occuring only on CI server
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 93
diff changeset
   121
        end
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   122
        report_summary = TestReportSummary.new(pkg.name, report_file)
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   123
        TestReportSummary::SUMMARIES << report_summary
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   124
      end
218
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   125
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   126
      task "test:package:#{pkg.name}" => [ "test:package:#{pkg.name}:pre",
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   127
                                           "test:package:#{pkg.name}:main",
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   128
                                           "test:package:#{pkg.name}:post" ]
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   129
      task :'test:packages' => "test:package:#{pkg.name}"
218
327e28e1fcaf Rakefiles: refactored "test" targets to support "...:pre" and "...:post" hooks
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 187
diff changeset
   130
      task "#{pkg.name}:test" => "test:package:#{pkg.name}"
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   131
    end
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   132
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   133
    if pkg.lint
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   134
      task "lint:package:#{pkg.name}" => %W(stx:goodies/builder/reports REPORT_DIR) do
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   135
        #puts "LINT DISABLED (because of some bug in recent SmallLint - runs out of memory)"
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   136
        run_report(app, [pkg.name], LINTREPORT_CLASS)
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   137
      end
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   138
      task :'lint:packages' => "lint:package:#{pkg.name}"
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   139
    end
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   140
  end
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   141
end
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   142
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   143
task :'setup:tasks' => :'setup:tasks:test'
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   144
task :'test:setup' => :setup
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   145
task :'lint:setup' => :setup
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   146
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   147
namespace :test do
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   148
  task :all => %i(setup pre main post)
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   149
  task :pre
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   150
  task :post
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   151
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   152
  directory REPORT_DIR
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   153
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   154
  task :setup => :'setup:dependencies'
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   155
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   156
  task :main => %i(setup packages summary)
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   157
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   158
  task :packages
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   159
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   160
  task :summary do
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   161
    outcome = 'PASSED'
252
135a52fc8891 Detection of ConEmu environment when running a test suite - warning a user, for the tests maybe unreliable
Patrik Svestka <patrik.svestka@gmail.com>
parents: 236
diff changeset
   162
    # Detect if the test is run in ConEmu environment.  Running test suite in ConEmu
135a52fc8891 Detection of ConEmu environment when running a test suite - warning a user, for the tests maybe unreliable
Patrik Svestka <patrik.svestka@gmail.com>
parents: 236
diff changeset
   163
    # yields often incorrect results due to some code injection and other techniques 
135a52fc8891 Detection of ConEmu environment when running a test suite - warning a user, for the tests maybe unreliable
Patrik Svestka <patrik.svestka@gmail.com>
parents: 236
diff changeset
   164
    # used by ConEmu to fix bugs or other deficiencies in the MS code
135a52fc8891 Detection of ConEmu environment when running a test suite - warning a user, for the tests maybe unreliable
Patrik Svestka <patrik.svestka@gmail.com>
parents: 236
diff changeset
   165
    if (ENV['ConEmuPID'])
135a52fc8891 Detection of ConEmu environment when running a test suite - warning a user, for the tests maybe unreliable
Patrik Svestka <patrik.svestka@gmail.com>
parents: 236
diff changeset
   166
      puts
135a52fc8891 Detection of ConEmu environment when running a test suite - warning a user, for the tests maybe unreliable
Patrik Svestka <patrik.svestka@gmail.com>
parents: 236
diff changeset
   167
      puts 'WARNING: Test was executed within ConEmu environment the test results are UNRELIABLE!'
135a52fc8891 Detection of ConEmu environment when running a test suite - warning a user, for the tests maybe unreliable
Patrik Svestka <patrik.svestka@gmail.com>
parents: 236
diff changeset
   168
      puts 'Run the test suite directly in the cmd.exe or the powershell.exe.'
135a52fc8891 Detection of ConEmu environment when running a test suite - warning a user, for the tests maybe unreliable
Patrik Svestka <patrik.svestka@gmail.com>
parents: 236
diff changeset
   169
      puts
135a52fc8891 Detection of ConEmu environment when running a test suite - warning a user, for the tests maybe unreliable
Patrik Svestka <patrik.svestka@gmail.com>
parents: 236
diff changeset
   170
    end
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   171
    puts
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   172
    puts 'OVERALL SUMMARY'
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   173
    puts
250
86db38276922 Rakefiles: execute tests in random order
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 236
diff changeset
   174
    (TestReportSummary::SUMMARIES.sort { | a, b | a.pkg <=> b.pkg }).each do |test_summary|
253
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
   175
      puts "%-20s %s - %d run, %d passed, %d skipped, %d failed, %d errors, execution time: %s" % [
141
e2147db5c7f0 Fixed slip in `test.rake` introduced in commit e665031cade7
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 140
diff changeset
   176
        test_summary.pkg,
e2147db5c7f0 Fixed slip in `test.rake` introduced in commit e665031cade7
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 140
diff changeset
   177
        test_summary.outcome,
e2147db5c7f0 Fixed slip in `test.rake` introduced in commit e665031cade7
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 140
diff changeset
   178
        test_summary.run,
e2147db5c7f0 Fixed slip in `test.rake` introduced in commit e665031cade7
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 140
diff changeset
   179
        test_summary.passed,
e2147db5c7f0 Fixed slip in `test.rake` introduced in commit e665031cade7
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 140
diff changeset
   180
        test_summary.skipped,
e2147db5c7f0 Fixed slip in `test.rake` introduced in commit e665031cade7
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 140
diff changeset
   181
        test_summary.failed,
253
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
   182
        test_summary.errors,
3747e4b3256b Adding a total time for each test package in the OVERALL SUMMARY
Patrik Svestka <patrik.svestka@gmail.com>
parents: 252
diff changeset
   183
        test_summary.execution_time
141
e2147db5c7f0 Fixed slip in `test.rake` introduced in commit e665031cade7
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 140
diff changeset
   184
      ]
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   185
      outcome = 'FAILED' if test_summary.failed > 0 or test_summary.errors > 0
48
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   186
    end
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   187
    puts
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   188
    puts outcome
33088fc2ba3b Print overall test result summary fpr after all tests are run.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 32
diff changeset
   189
  end
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   190
end
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   191
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   192
desc 'Run static analysis on the code (SmallLint)'
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   193
task :lint => :'lint:all'
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   194
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   195
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   196
namespace :lint do
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   197
  task :all => %i(setup pre main post)
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   198
  task :pre
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   199
  task :post
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   200
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   201
  directory REPORT_DIR
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   202
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   203
  task :setup
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   204
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   205
  task :main => %i(setup packages)
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   206
137
e665031cade7 Cleaning up code and having it more rubyish
Patrik Svestka <patrik.svestka@gmail.com>
parents: 121
diff changeset
   207
  task :packages
0
f46260ba26b1 Initial shot of "new" rake-based builder
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   208
end