Skip to content

Commit 2508e4e

Browse files
committed
Bump minimum Ruby to 3.1 and intercept fork via Process._fork
Process._fork is the official extension point: Kernel#fork, Process.fork, IO.popen("-") all funnel through it, and prepended modules compose with other libraries. Updates gemspec, .rubocop.yml TargetRubyVersion, the stable.yml matrix, and the README ruby-version blurb. The autocorrects (RedundantFreeze on regex literals, Naming/BlockForwarding to anonymous &) ride along.
1 parent f135dd5 commit 2508e4e

12 files changed

Lines changed: 41 additions & 39 deletions

File tree

.github/workflows/stable.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ jobs:
1414

1515
matrix:
1616
ruby-version:
17-
- '2.7'
18-
- '3.0'
1917
- '3.1'
2018
- '3.2'
2119
- '3.3'

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ AllCops:
1616
- "tmp/**/*"
1717
- "vendor/bundle/**/*"
1818
- "vendor/bundle/**/.*"
19-
TargetRubyVersion: 2.7
19+
TargetRubyVersion: 3.1
2020
NewCops: enable
2121

2222
Layout/AccessModifierIndentation:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
937937

938938
## Ruby version compatibility
939939

940-
SimpleCov is built in [Continuous Integration] on Ruby 2.5+ and JRuby 9.4+.
940+
SimpleCov is built in [Continuous Integration] on Ruby 3.1+ and JRuby 9.4+.
941941

942942
Note for JRuby => You need to pass JRUBY_OPTS="--debug" or create .jrubyrc and add debug.fullTrace=true
943943

features/step_definitions/web_steps.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# Cucumber world helpers for scoping Capybara assertions to a selector.
44
module WithinHelpers
5-
def with_scope(locator, &block)
6-
locator ? within(locator, &block) : yield
5+
def with_scope(locator, &)
6+
locator ? within(locator, &) : yield
77
end
88
end
99
World(WithinHelpers)

lib/simplecov.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ class << self
4343
#
4444
# Please check out the RDoc for SimpleCov::Configuration to find about available config options
4545
#
46-
def start(profile = nil, &block)
46+
def start(profile = nil, &)
4747
require "coverage"
4848
warn_if_jruby_full_trace_disabled
49-
initial_setup(profile, &block)
49+
initial_setup(profile, &)
5050
require_relative "simplecov/process" if SimpleCov.enabled_for_subprocesses? &&
51-
::Process.respond_to?(:fork)
51+
::Process.respond_to?(:_fork)
5252

5353
make_parallel_tests_available
5454

@@ -336,7 +336,7 @@ def initial_setup(profile, &block)
336336

337337
#
338338
# Trigger Coverage.start with the configured criteria. Every supported
339-
# runtime (CRuby >= 2.7, JRuby >= 9.4, TruffleRuby >= 22) accepts the
339+
# runtime (CRuby >= 3.1, JRuby >= 9.4, TruffleRuby >= 22) accepts the
340340
# criteria-hash form, so no compatibility fallback is needed.
341341
#
342342
def start_coverage_measurement

lib/simplecov/configuration.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,17 +408,17 @@ def refuse_coverage_drop(*criteria)
408408
# * as an instance of a subclass of SimpleCov::Filter. See the documentation there
409409
# on how to define your own filter classes
410410
#
411-
def add_filter(filter_argument = nil, &filter_proc)
412-
filters << parse_filter(filter_argument, &filter_proc)
411+
def add_filter(filter_argument = nil, &)
412+
filters << parse_filter(filter_argument, &)
413413
end
414414

415415
#
416416
# Define a group for files. Works similar to add_filter, only that the first
417417
# argument is the desired group name and files PASSING the filter end up in the group
418418
# (while filters exclude when the filter is applicable).
419419
#
420-
def add_group(group_name, filter_argument = nil, &filter_proc)
421-
groups[group_name] = parse_filter(filter_argument, &filter_proc)
420+
def add_group(group_name, filter_argument = nil, &)
421+
groups[group_name] = parse_filter(filter_argument, &)
422422
end
423423

424424
SUPPORTED_COVERAGE_CRITERIA = %i[line branch method oneshot_line].freeze

lib/simplecov/directive.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ module SimpleCov
3838
class Directive
3939
CATEGORIES = %i[line branch method].freeze
4040

41-
CATEGORY_PATTERN = "(?:#{CATEGORIES.join('|')})"
42-
CATEGORIES_PATTERN = "(?:#{CATEGORY_PATTERN}(?:\\s*,\\s*#{CATEGORY_PATTERN})*)"
41+
CATEGORY_PATTERN = "(?:#{CATEGORIES.join('|')})".freeze
42+
CATEGORIES_PATTERN = "(?:#{CATEGORY_PATTERN}(?:\\s*,\\s*#{CATEGORY_PATTERN})*)".freeze
4343
PATTERN = /
4444
\#\s*simplecov\s*:\s*
4545
(?<mode>disable|enable)\b
4646
(?:\s+(?<categories>#{CATEGORIES_PATTERN}))?
4747
.*?
4848
\s*\z
49-
/x.freeze
49+
/x
5050

5151
attr_reader :line_number, :mode, :categories
5252

lib/simplecov/lines_classifier.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class LinesClassifier
1010
RELEVANT = 0
1111
NOT_RELEVANT = nil
1212

13-
WHITESPACE_LINE = /^\s*$/.freeze
14-
COMMENT_LINE = /^\s*#/.freeze
13+
WHITESPACE_LINE = /^\s*$/
14+
COMMENT_LINE = /^\s*#/
1515
WHITESPACE_OR_COMMENT_LINE = Regexp.union(WHITESPACE_LINE, COMMENT_LINE)
1616

1717
def self.no_cov_line

lib/simplecov/process.rb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
# frozen_string_literal: true
22

3-
# Patches `Process.fork` so child processes inherit SimpleCov's coverage
4-
# tracking when `SimpleCov.enable_for_subprocesses?` is set.
5-
module Process
6-
class << self
7-
def fork_with_simplecov(&block)
8-
if defined?(SimpleCov) && SimpleCov.running
9-
fork_without_simplecov do
10-
SimpleCov.at_fork.call(Process.pid)
11-
yield if block
12-
end
13-
else
14-
fork_without_simplecov(&block)
15-
end
16-
end
3+
# Hooks `Process._fork` (Ruby 3.1+) so child processes inherit SimpleCov's
4+
# coverage tracking when `SimpleCov.enable_for_subprocesses?` is set.
5+
#
6+
# `Process._fork` is the official extension point: `Kernel#fork`,
7+
# `Process.fork`, `IO.popen("-")`, and similar all funnel through it.
8+
# Hooking `_fork` (instead of redefining `Process.fork`) composes
9+
# correctly with other libraries doing the same — they each prepend
10+
# their own module and chain via `super`.
1711

18-
alias fork_without_simplecov fork
19-
alias fork fork_with_simplecov
12+
module SimpleCov
13+
# Prepended onto Process's singleton class so every fork — direct or
14+
# via Kernel#fork / IO.popen — re-runs SimpleCov's at_fork callback in
15+
# the child.
16+
module ProcessForkHook
17+
def _fork
18+
pid = super
19+
SimpleCov.at_fork.call(::Process.pid) if pid.zero? && defined?(SimpleCov) && SimpleCov.running
20+
pid
21+
end
2022
end
2123
end
24+
25+
Process.singleton_class.prepend(SimpleCov::ProcessForkHook)

lib/simplecov/result_adapter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def adapt
3737
# Address widths vary by runtime (32-bit hosts: 8 hex chars; 64-bit
3838
# CRuby: 16; some JVM/TruffleRuby formats may differ), so match any
3939
# length of hex digits and collapse to a single placeholder.
40-
ADDRESS_PATTERN = /0x\h+/.freeze
40+
ADDRESS_PATTERN = /0x\h+/
4141
private_constant :ADDRESS_PATTERN
4242

4343
ADDRESS_PLACEHOLDER = "0x0"

0 commit comments

Comments
 (0)