forking_test_runner 1.5.2 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da329d4d34a62e5506ea5503521ee68d46b6d113a36e57d93e732feb9d5fdd52
4
- data.tar.gz: 0d264d60aba634760d5670dcdb050305ce3f68ffa8023528a788c66ff0012ff9
3
+ metadata.gz: 1839ef1db8973b5e282bbf3998915649fa16448e12d6c56e11fda8b0d1f4d2a8
4
+ data.tar.gz: 8d3f007a2149807efd62c4e1ff4b9a287c54055aebc3760b6bd3300d5844e8bf
5
5
  SHA512:
6
- metadata.gz: 1fd169253d7e50b752d9e866ec8180eb4009f38354f931ce8e6f764743f9c51627ac94949a131a079a6a760f9473fbafac370c40f514aabbb782c8acdfd7b3a4
7
- data.tar.gz: 9c67fa682ea9ea43f888b347ee6ec8a75c00a3d3ca2f4288b414b4fc17573a6fc877e825fc82775c7620a907d543607996d12174630fd7ecfb811d58ffe7aeca
6
+ metadata.gz: 4939fa2877d285718946f957082a2129b17d4d20d7cce27050709d81d4c410bd50c455af8c2d546a3ebeaaa76a7ac047859883ea1b780102f8af63ac12ae14a5
7
+ data.tar.gz: 25caf6564292c4cd5d74b9214879d514b6d9b49ac11c8bcf9e3e1407e0550ece85d92f6ed3395015ff028b1c654578d9d05d17f2b708c9e6e59ffdf590a49d3e
@@ -8,6 +8,7 @@ require 'tempfile'
8
8
 
9
9
  module ForkingTestRunner
10
10
  CLEAR = "------"
11
+ CONVERAGE_REPORT_PREFIX = "coverage/fork-"
11
12
 
12
13
  class << self
13
14
  def cli(argv)
@@ -79,6 +80,8 @@ module ForkingTestRunner
79
80
  record_test_runtime(mode, results, log)
80
81
  end
81
82
 
83
+ summarize_partial_reports if partial_reports_for_single_cov?
84
+
82
85
  # exit with success or failure
83
86
  success ? 0 : 1
84
87
  end
@@ -252,8 +255,7 @@ module ForkingTestRunner
252
255
 
253
256
  child = fork do
254
257
  rpipe.close
255
- $stdout.reopen(wpipe)
256
-
258
+ preserve_tty { $stdout.reopen(wpipe) }
257
259
  yield
258
260
  end
259
261
 
@@ -270,10 +272,20 @@ module ForkingTestRunner
270
272
  buffer
271
273
  end
272
274
 
275
+ # not tested via CI
276
+ def preserve_tty
277
+ was_tty = $stdout.tty?
278
+ yield
279
+ def $stdout.tty?; true; end if was_tty
280
+ end
281
+
273
282
  def run_test(file)
274
283
  stdout = change_program_name_to file do
275
284
  fork_with_captured_stdout do
276
- SimpleCov.pid = Process.pid if defined?(SimpleCov) && SimpleCov.respond_to?(:pid=) # trick simplecov into reporting in this fork
285
+ SimpleCov.pid = Process.pid if defined?(SimpleCov) && SimpleCov.respond_to?(:pid=) # make simplecov report in this fork
286
+ if partial_reports_for_single_cov?
287
+ SingleCov.coverage_report = "#{CONVERAGE_REPORT_PREFIX}#{Process.pid}.json"
288
+ end
277
289
  if active_record?
278
290
  key = (ActiveRecord::VERSION::STRING >= "4.1.0" ? :test : "test")
279
291
  ActiveRecord::Base.establish_connection key
@@ -285,6 +297,10 @@ module ForkingTestRunner
285
297
  [$?.success?, stdout]
286
298
  end
287
299
 
300
+ def partial_reports_for_single_cov?
301
+ @options.fetch(:merge_coverage) && defined?(SingleCov) && SingleCov.respond_to?(:coverage_report=) && SingleCov.coverage_report
302
+ end
303
+
288
304
  def change_program_name_to(name)
289
305
  return yield if @options.fetch(:parallel)
290
306
  begin
@@ -341,9 +357,33 @@ module ForkingTestRunner
341
357
 
342
358
  if value
343
359
  minitest_class.autorun
344
- require(file.start_with?('/') ? file : "./#{file}")
360
+ load file
345
361
  end
346
362
  end
347
363
  end
364
+
365
+ def summarize_partial_reports
366
+ reports = Dir.glob("#{CONVERAGE_REPORT_PREFIX}*")
367
+ return if reports.empty?
368
+
369
+ require "json" # not a global dependency
370
+ coverage = reports.each_with_object({}) do |report, all|
371
+ suites = JSON.parse(File.read(report), symbolize_names: true).values
372
+ raise "Unsupported number of suites #{suites.size}" if suites.size != 1
373
+ all.replace CoverageCapture.merge_coverage(all, suites.first.fetch(:coverage))
374
+ ensure
375
+ File.unlink(report) # do not leave junk behind
376
+ end
377
+
378
+ # report only line coverage to be backwards compatible for some coverage backends
379
+ coverage.transform_values! { |v| v.is_a?(Hash) ? v.fetch(:lines) : v } if @options[:report_line_coverage]
380
+
381
+ # chose "Minitest" because it is what simplecov uses for reports and "Unit Tests" makes sonarqube break
382
+ data = JSON.pretty_generate("Minitest" => {"coverage" => coverage, "timestamp" => Time.now.to_i })
383
+ File.write(SingleCov.coverage_report, data)
384
+
385
+ # make it not override our report when it finishes for main process
386
+ SingleCov.coverage_report = nil
387
+ end
348
388
  end
349
389
  end
@@ -7,7 +7,8 @@ module ForkingTestRunner
7
7
  [:quiet, "--quiet", "Quiet"],
8
8
  [:no_fixtures, "--no-fixtures", "Do not load fixtures"],
9
9
  [:no_ar, "--no-ar", "Disable ActiveRecord logic"],
10
- [:merge_coverage, "--merge-coverage", "Merge base code coverage into indvidual files coverage, great for SingleCov"],
10
+ [:merge_coverage, "--merge-coverage", "Merge base code coverage into individual files coverage and summarize coverage report"],
11
+ [:report_line_coverage, "--report-line-coverage", "Convert coverage report to line coverage (for compatibility)"],
11
12
  [
12
13
  :record_runtime,
13
14
  "--record-runtime=MODE",
@@ -1,3 +1,3 @@
1
1
  module ForkingTestRunner
2
- VERSION = "1.5.2"
2
+ VERSION = "1.10.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forking_test_runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-07 00:00:00.000000000 Z
11
+ date: 2020-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel_tests
@@ -133,14 +133,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
- version: 2.3.0
136
+ version: 2.5.0
137
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  requirements:
139
139
  - - ">="
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubygems_version: 3.0.3
143
+ rubygems_version: 3.1.3
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: Run every test in a fork to avoid pollution and get clean output per test