Skip to content

Commit c30935a

Browse files
committed
Guard specs needing #fork with guard -> { Process.respond_to?(:fork) } do
* Previously they would use `platform_is_not :windows do` but fork() is in fact platform-dependent and not available on more than just Windows. Notably, JRuby and TruffleRuby cannot implement #fork because the JVM does not support it (e.g. the GC expects threads to not die suddenly). This seems extremely unlikely to change so IOW the JVM is a platform which does not support fork().
1 parent 6b3b96d commit c30935a

8 files changed

Lines changed: 36 additions & 29 deletions

File tree

core/io/foreach_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
ScratchPad.recorded.should == ["hello\n", "line2\n"]
2929
end
3030

31-
platform_is_not :windows do
31+
guard -> { Process.respond_to?(:fork) } do
3232
it "gets data from a fork when passed -" do
3333
parent_pid = $$
3434

core/io/read_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
end
164164
end
165165

166-
platform_is_not :windows do
166+
guard -> { Process.respond_to?(:fork) } do
167167
it "opens a pipe to a fork if the rest is -" do
168168
str = nil
169169
suppress_warning do # https://bugs.ruby-lang.org/issues/19630

core/io/readlines_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
lines.should == ["hello\n", "line2\n"]
190190
end
191191

192-
platform_is_not :windows do
192+
guard -> { Process.respond_to?(:fork) } do
193193
it "gets data from a fork when passed -" do
194194
lines = nil
195195
suppress_warning do # https://bugs.ruby-lang.org/issues/19630

core/process/daemon_spec.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
require_relative '../../spec_helper'
22
require_relative 'fixtures/common'
33

4-
platform_is_not :windows do
5-
# macOS 15 is not working this examples
6-
return if /darwin/ =~ RUBY_PLATFORM && /15/ =~ `sw_vers -productVersion`
7-
4+
guard -> {
5+
Process.respond_to?(:fork) and
6+
# macOS 15 is not working for these examples
7+
!(/darwin/ =~ RUBY_PLATFORM && /15/ =~ `sw_vers -productVersion`)
8+
} do
89
describe :process_daemon_keep_stdio_open_false, shared: true do
910
it "redirects stdout to /dev/null" do
1011
@daemon.invoke("keep_stdio_open_false_stdout", @object).should == ""
@@ -107,8 +108,12 @@
107108
end
108109
end
109110

110-
platform_is :windows do
111+
guard_not -> { Process.respond_to?(:fork) } do
111112
describe "Process.daemon" do
113+
it "returns false from #respond_to?" do
114+
Process.respond_to?(:daemon).should == false
115+
end
116+
112117
it "raises a NotImplementedError" do
113118
-> {
114119
Process.daemon

core/process/setpgid_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require_relative '../../spec_helper'
22

33
describe "Process.setpgid" do
4-
platform_is_not :windows do
4+
guard -> { Process.respond_to?(:fork) } do
55
# Must use fork as setpgid(2) gives EACCESS after execve()
66
it "sets the process group id of the specified process" do
77
rd, wr = IO.pipe

core/process/setpgrp_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# TODO: put these in the right files.
44
describe "Process.setpgrp and Process.getpgrp" do
5-
platform_is_not :windows do
5+
guard -> { Process.respond_to?(:fork) } do
66
it "sets and gets the process group ID of the calling process" do
77
# there are two synchronization points here:
88
# One for the child to let the parent know that it has finished

core/process/status/wait_spec.rb

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,27 @@
7070
end
7171

7272
# This spec is probably system-dependent.
73-
it "doesn't block if no child is available when WNOHANG is used" do
74-
read, write = IO.pipe
75-
pid = Process.fork do
76-
read.close
77-
Signal.trap("TERM") { Process.exit! }
78-
write << 1
73+
guard -> { Process.respond_to?(:fork) } do
74+
it "doesn't block if no child is available when WNOHANG is used" do
75+
read, write = IO.pipe
76+
pid = Process.fork do
77+
read.close
78+
Signal.trap("TERM") { Process.exit! }
79+
write << 1
80+
write.close
81+
sleep
82+
end
83+
84+
Process::Status.wait(pid, Process::WNOHANG).should == nil
85+
86+
# wait for the child to setup its TERM handler
7987
write.close
80-
sleep
81-
end
82-
83-
Process::Status.wait(pid, Process::WNOHANG).should == nil
84-
85-
# wait for the child to setup its TERM handler
86-
write.close
87-
read.read(1)
88-
read.close
88+
read.read(1)
89+
read.close
8990

90-
Process.kill("TERM", pid)
91-
Process::Status.wait.pid.should == pid
91+
Process.kill("TERM", pid)
92+
Process::Status.wait.pid.should == pid
93+
end
9294
end
9395

9496
it "always accepts flags=0" do

shared/process/fork.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe :process_fork, shared: true do
2-
platform_is :windows do
2+
guard_not -> { Process.respond_to?(:fork) } do
33
it "returns false from #respond_to?" do
44
# Workaround for Kernel::Method being public and losing the "non-respond_to? magic"
55
mod = @object.class.name == "KernelSpecs::Method" ? Object.new : @object
@@ -12,7 +12,7 @@
1212
end
1313
end
1414

15-
platform_is_not :windows do
15+
guard -> { Process.respond_to?(:fork) } do
1616
before :each do
1717
@file = tmp('i_exist')
1818
rm_r @file

0 commit comments

Comments
 (0)