Skip to content

Commit efbebde

Browse files
committed
[GR-27327] Fix redirect fd specs
PullRequest: truffleruby/2137
2 parents 6ed78bd + f46daca commit efbebde

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

spec/mspec/lib/mspec/helpers/io.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,3 @@ def new_io(name, mode = "w:utf-8")
8585
File.new(name, mode)
8686
end
8787
end
88-
89-
def find_unused_fd
90-
Dir.entries("/dev/fd").map(&:to_i).max + 1
91-
end

spec/ruby/core/process/exec_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,11 @@
193193
map_fd_fixture = fixture __FILE__, "map_fd.rb"
194194
cmd = <<-EOC
195195
f = File.open(#{@name.inspect}, "w+")
196-
child_fd = f.fileno + 1
197-
File.open(#{@child_fd_file.inspect}, "w") { |io| io.print child_fd }
198-
Process.exec "#{ruby_cmd(map_fd_fixture)} \#{child_fd}", { child_fd => f }
196+
File.open(#{__FILE__.inspect}, "r") do |io|
197+
child_fd = io.fileno
198+
File.open(#{@child_fd_file.inspect}, "w") { |io| io.print child_fd }
199+
Process.exec "#{ruby_cmd(map_fd_fixture)} \#{child_fd}", { child_fd => f }
200+
end
199201
EOC
200202

201203
ruby_exe(cmd, escape: true)

spec/ruby/core/process/spawn_spec.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -706,13 +706,15 @@ def child_pids(pid)
706706
end
707707

708708
it "maps the key to a file descriptor in the child that inherits the file descriptor from the parent specified by the value" do
709-
child_fd = find_unused_fd
710-
args = ruby_cmd(fixture(__FILE__, "map_fd.rb"), args: [child_fd.to_s])
711-
pid = Process.spawn(*args, { child_fd => @io })
712-
Process.waitpid pid
713-
@io.rewind
714-
715-
@io.read.should == "writing to fd: #{child_fd}"
709+
File.open(__FILE__, "r") do |f|
710+
child_fd = f.fileno
711+
args = ruby_cmd(fixture(__FILE__, "map_fd.rb"), args: [child_fd.to_s])
712+
pid = Process.spawn(*args, { child_fd => @io })
713+
Process.waitpid pid
714+
@io.rewind
715+
716+
@io.read.should == "writing to fd: #{child_fd}"
717+
end
716718
end
717719
end
718720
end

0 commit comments

Comments
 (0)