forking_test_runner 1.5.1 → 1.9.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: ef9594eb4e2644f8afa4ace2ecafc1f71eef58258297a9a3a425749669310908
4
- data.tar.gz: f3f1a73b501941fa9dd01b93324ca294f05337dc9643777ac1113b79e1d22a53
3
+ metadata.gz: 33abc47d33141843b1d89ce17adee27897c64bc3445d9567845194aaa9f07224
4
+ data.tar.gz: a61958472117f965f21e354ce7f874f7ea920a76503589b5dd36e0a6f21eb7c7
5
5
  SHA512:
6
- metadata.gz: 3fcc2695e506ca3360561436d55dd01117aae03c033b1b60ad3147acd59bf8cd278aff0e386db75dd9847f85b8528829a007ed6bb5b28d0ea2f78f88881ce95a
7
- data.tar.gz: efff54891fd50adbe0311e63068dc6fe5c131e6e4557ae3f5369790c68344bca7139138e85af70599d974eab57f65b4813ae8102cf9b8012ed8a61d491b328be
6
+ metadata.gz: 59f31396b4c6ccdce8cb625aebdea2b3f2a49c6e91983990f2b93e386c19f8e6ef94100d8ca0482a0e82cec2450fb1a5db1a47c42566749b69d7324543676c87
7
+ data.tar.gz: 32bbc0a83affacf06da8943e9a592152841ead2d7180aabe201031934d68705ac9e769c9c75b33b13b0a4b1587f6795fb38bbdb44c145f4e5c3de74bd698dab3
@@ -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)
@@ -21,7 +22,7 @@ module ForkingTestRunner
21
22
  if parallel && !@options.fetch(:group)
22
23
  Array.new(parallel) { |i| find_tests_for_group(i + 1, parallel, tests, runtime_log) }
23
24
  else
24
- raise ArgumentError, "Use the same amount of processors as groups" if parallel && parallel != group_count
25
+ raise ArgumentError, "Use the same amount of processors as groups" if parallel && parallel != groups.count
25
26
  groups.map { |group| find_tests_for_group(group, group_count, tests, runtime_log) }
26
27
  end
27
28
 
@@ -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,29 @@ 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
+ data = JSON.pretty_generate("Unit Tests" => {"coverage" => coverage, "timestamp" => Time.now.to_i })
379
+ File.write(SingleCov.coverage_report, data)
380
+
381
+ # make it not override our report when it finishes for main process
382
+ SingleCov.coverage_report = nil
383
+ end
348
384
  end
349
385
  end
@@ -1,3 +1,3 @@
1
1
  module ForkingTestRunner
2
- VERSION = "1.5.1"
2
+ VERSION = "1.9.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.1
4
+ version: 1.9.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-02 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