diff options
author | Benoit Daloze <eregontp@gmail.com> | 2019-04-28 23:20:11 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2019-04-28 23:20:11 +0200 |
commit | 79671ec57e59091260a0bc3d40a31d31d9c72a94 (patch) | |
tree | 2f59a8727b8f63f9e79d50352fa4f78a7cc00234 /spec/ruby/core/objectspace/define_finalizer_spec.rb | |
parent | 994833085ae06afbe94d30ab183d80e0234fbe14 (diff) | |
download | ruby-79671ec57e59091260a0bc3d40a31d31d9c72a94.tar.gz |
Update to ruby/spec@7de852d
Diffstat (limited to 'spec/ruby/core/objectspace/define_finalizer_spec.rb')
-rw-r--r-- | spec/ruby/core/objectspace/define_finalizer_spec.rb | 89 |
1 files changed, 28 insertions, 61 deletions
diff --git a/spec/ruby/core/objectspace/define_finalizer_spec.rb b/spec/ruby/core/objectspace/define_finalizer_spec.rb index e2869ee706..b7e47473a0 100644 --- a/spec/ruby/core/objectspace/define_finalizer_spec.rb +++ b/spec/ruby/core/objectspace/define_finalizer_spec.rb @@ -3,8 +3,6 @@ require_relative 'fixtures/classes' # NOTE: A call to define_finalizer does not guarantee that the # passed proc or callable will be called at any particular time. -# It is highly questionable whether these aspects of ObjectSpace -# should be spec'd at all. describe "ObjectSpace.define_finalizer" do it "raises an ArgumentError if the action does not respond to call" do lambda { @@ -30,72 +28,41 @@ describe "ObjectSpace.define_finalizer" do end # see [ruby-core:24095] - with_feature :fork do - it "calls finalizer on process termination" do - rd, wr = IO.pipe - pid = Process.fork do - rd.close - handler = ObjectSpaceFixtures.scoped(wr) - obj = "Test" - ObjectSpace.define_finalizer(obj, handler) - exit 0 + it "calls finalizer on process termination" do + code = <<-RUBY + def scoped + Proc.new { puts "finalized" } end + handler = scoped + obj = "Test" + ObjectSpace.define_finalizer(obj, handler) + exit 0 + RUBY - wr.close - begin - rd.read.should == "finalized" - ensure - rd.close - Process.wait pid - end - end - - it "calls finalizer at exit even if it is self-referencing" do - rd, wr = IO.pipe - pid = Process.fork do - rd.close - obj = "Test" - handler = Proc.new { wr.write "finalized"; wr.close } - ObjectSpace.define_finalizer(obj, handler) - exit 0 - end - - wr.close - begin - rd.read.should == "finalized" - ensure - rd.close - Process.wait pid - end - end - - # These specs are defined under the fork specs because there is no - # deterministic way to force finalizers to be run, except process exit, so - # we rely on that. - it "allows multiple finalizers with different 'callables' to be defined" do - rd1, wr1 = IO.pipe - rd2, wr2 = IO.pipe + ruby_exe(code).should == "finalized\n" + end - pid = Kernel::fork do - rd1.close - rd2.close - obj = mock("ObjectSpace.define_finalizer multiple") + it "calls finalizer at exit even if it is self-referencing" do + code = <<-RUBY + obj = "Test" + handler = Proc.new { puts "finalized" } + ObjectSpace.define_finalizer(obj, handler) + exit 0 + RUBY - ObjectSpace.define_finalizer(obj, Proc.new { wr1.write "finalized1"; wr1.close }) - ObjectSpace.define_finalizer(obj, Proc.new { wr2.write "finalized2"; wr2.close }) + ruby_exe(code).should == "finalized\n" + end - exit 0 - end + it "allows multiple finalizers with different 'callables' to be defined" do + code = <<-RUBY + obj = Object.new - wr1.close - wr2.close + ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized1\n" }) + ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized2\n" }) - rd1.read.should == "finalized1" - rd2.read.should == "finalized2" + exit 0 + RUBY - rd1.close - rd2.close - Process.wait pid - end + ruby_exe(code).lines.sort.should == ["finalized1\n", "finalized2\n"] end end |