summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/gc_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/optional/capi/gc_spec.rb')
-rw-r--r--spec/ruby/optional/capi/gc_spec.rb75
1 files changed, 62 insertions, 13 deletions
diff --git a/spec/ruby/optional/capi/gc_spec.rb b/spec/ruby/optional/capi/gc_spec.rb
index d76ea7394f..8b70ea4758 100644
--- a/spec/ruby/optional/capi/gc_spec.rb
+++ b/spec/ruby/optional/capi/gc_spec.rb
@@ -7,12 +7,30 @@ describe "CApiGCSpecs" do
@f = CApiGCSpecs.new
end
+ describe "RB_GC_GUARD" do
+ it "forces an object to on stack so it cannot be GC'd early" do
+ @f.RB_GC_GUARD_keep_alive([%w[ab cd ef].join]).should == "abc"
+ end
+
+ it "can be used with any Ruby object" do
+ @f.RB_GC_GUARD(true).should == true
+ @f.RB_GC_GUARD(42).should == 42
+ @f.RB_GC_GUARD(self).should == self
+ end
+
+ it "tolerates being passed invalid pointers" do
+ (0...256).each do |address|
+ @f.RB_GC_GUARD_raw(address).should == nil
+ end
+ end
+ end
+
describe "rb_gc_register_address" do
it "correctly gets the value from a registered address" do
@f.registered_tagged_address.should == 10
- @f.registered_tagged_address.should equal(@f.registered_tagged_address)
+ @f.registered_tagged_address.should.equal?(@f.registered_tagged_address)
@f.registered_reference_address.should == "Globally registered data"
- @f.registered_reference_address.should equal(@f.registered_reference_address)
+ @f.registered_reference_address.should.equal?(@f.registered_reference_address)
end
it "keeps the value alive even if the value is assigned after rb_gc_register_address() is called" do
@@ -27,9 +45,36 @@ describe "CApiGCSpecs" do
end
describe "rb_global_variable" do
- it "keeps the value alive even if the value is assigned after rb_global_variable() is called" do
+ before :all do
GC.start
- @f.registered_before_rb_global_variable.should == "registered before rb_global_variable()"
+ end
+
+ describe "keeps the value alive even if the value is assigned after rb_global_variable() is called" do
+ it "for a string" do
+ @f.registered_before_rb_global_variable_string.should == "registered before rb_global_variable()"
+ end
+
+ it "for a bignum" do
+ @f.registered_before_rb_global_variable_bignum.should == 2**63 - 1
+ end
+
+ it "for a Float" do
+ @f.registered_before_rb_global_variable_float.should == 3.14
+ end
+ end
+
+ describe "keeps the value alive when the value is assigned before rb_global_variable() is called" do
+ it "for a string" do
+ @f.registered_after_rb_global_variable_string.should == "registered after rb_global_variable()"
+ end
+
+ it "for a bignum" do
+ @f.registered_after_rb_global_variable_bignum.should == 2**63 - 1
+ end
+
+ it "for a Float" do
+ @f.registered_after_rb_global_variable_float.should == 6.28
+ end
end
end
@@ -40,22 +85,22 @@ describe "CApiGCSpecs" do
it "enables GC when disabled" do
GC.disable
- @f.rb_gc_enable.should be_true
+ @f.rb_gc_enable.should == true
end
it "GC stays enabled when enabled" do
GC.enable
- @f.rb_gc_enable.should be_false
+ @f.rb_gc_enable.should == false
end
it "disables GC when enabled" do
GC.enable
- @f.rb_gc_disable.should be_false
+ @f.rb_gc_disable.should == false
end
it "GC stays disabled when disabled" do
GC.disable
- @f.rb_gc_disable.should be_true
+ @f.rb_gc_disable.should == true
end
end
@@ -73,23 +118,27 @@ describe "CApiGCSpecs" do
-> {
@f.rb_gc_adjust_memory_usage(8)
@f.rb_gc_adjust_memory_usage(-8)
- }.should_not raise_error
+ }.should_not.raise
end
end
describe "rb_gc_register_mark_object" do
it "can be called with an object" do
- @f.rb_gc_register_mark_object(Object.new).should be_nil
+ @f.rb_gc_register_mark_object(Object.new).should == nil
+ end
+
+ it "keeps the value alive even if the value is not referenced by any Ruby object" do
+ @f.rb_gc_register_mark_object_not_referenced_float.should == 1.61
end
end
describe "rb_gc_latest_gc_info" do
it "raises a TypeError when hash or symbol not given" do
- -> { @f.rb_gc_latest_gc_info("foo") }.should raise_error(TypeError)
+ -> { @f.rb_gc_latest_gc_info("foo") }.should.raise(TypeError)
end
it "raises an ArgumentError when unknown symbol given" do
- -> { @f.rb_gc_latest_gc_info(:unknown) }.should raise_error(ArgumentError)
+ -> { @f.rb_gc_latest_gc_info(:unknown) }.should.raise(ArgumentError)
end
it "returns the populated hash when a hash is given" do
@@ -99,7 +148,7 @@ describe "CApiGCSpecs" do
end
it "returns a value when symbol is given" do
- @f.rb_gc_latest_gc_info(:state).should be_kind_of(Symbol)
+ @f.rb_gc_latest_gc_info(:state).should.is_a?(Symbol)
end
end
end