summaryrefslogtreecommitdiff
path: root/spec/ruby/core/gc
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/gc')
-rw-r--r--spec/ruby/core/gc/auto_compact_spec.rb36
-rw-r--r--spec/ruby/core/gc/config_spec.rb97
-rw-r--r--spec/ruby/core/gc/count_spec.rb2
-rw-r--r--spec/ruby/core/gc/measure_total_time_spec.rb24
-rw-r--r--spec/ruby/core/gc/profiler/enabled_spec.rb4
-rw-r--r--spec/ruby/core/gc/profiler/result_spec.rb2
-rw-r--r--spec/ruby/core/gc/profiler/total_time_spec.rb2
-rw-r--r--spec/ruby/core/gc/stat_spec.rb28
-rw-r--r--spec/ruby/core/gc/stress_spec.rb8
-rw-r--r--spec/ruby/core/gc/total_time_spec.rb18
10 files changed, 156 insertions, 65 deletions
diff --git a/spec/ruby/core/gc/auto_compact_spec.rb b/spec/ruby/core/gc/auto_compact_spec.rb
index 4f9d043171..33ad1cb56c 100644
--- a/spec/ruby/core/gc/auto_compact_spec.rb
+++ b/spec/ruby/core/gc/auto_compact_spec.rb
@@ -1,26 +1,24 @@
require_relative '../../spec_helper'
-ruby_version_is "3.0" do
- describe "GC.auto_compact" do
- it "can set and get a boolean value" do
- begin
- GC.auto_compact = GC.auto_compact
- rescue NotImplementedError # platform does not support autocompact
- skip
- end
+describe "GC.auto_compact" do
+ it "can set and get a boolean value" do
+ begin
+ GC.auto_compact = GC.auto_compact
+ rescue NotImplementedError # platform does not support autocompact
+ skip
+ end
- original = GC.auto_compact
- begin
- GC.auto_compact = !original
- rescue NotImplementedError # platform does not support autocompact
- skip
- end
+ original = GC.auto_compact
+ begin
+ GC.auto_compact = !original
+ rescue NotImplementedError # platform does not support autocompact
+ skip
+ end
- begin
- GC.auto_compact.should == !original
- ensure
- GC.auto_compact = original
- end
+ begin
+ GC.auto_compact.should == !original
+ ensure
+ GC.auto_compact = original
end
end
end
diff --git a/spec/ruby/core/gc/config_spec.rb b/spec/ruby/core/gc/config_spec.rb
new file mode 100644
index 0000000000..57160f122c
--- /dev/null
+++ b/spec/ruby/core/gc/config_spec.rb
@@ -0,0 +1,97 @@
+require_relative '../../spec_helper'
+
+ruby_version_is "3.4" do
+ describe "GC.config" do
+ context "without arguments" do
+ it "returns a hash of current settings" do
+ GC.config.should.is_a?(Hash)
+ end
+
+ it "includes the name of currently loaded GC implementation as a global key" do
+ GC.config.should.include?(:implementation)
+ GC.config[:implementation].should.is_a?(String)
+ end
+ end
+
+ context "with a hash of options" do
+ it "allows to set GC implementation's options, returning the new config" do
+ config = GC.config({})
+ # Try to find a boolean setting to reliably test changing it.
+ key, _value = config.find { |_k, v| v == true }
+ skip unless key
+
+ GC.config(key => false).should == config.merge(key => false)
+ GC.config[key].should == false
+ GC.config(key => true).should == config
+ GC.config[key].should == true
+ ensure
+ GC.config(config.except(:implementation))
+ end
+
+ it "does not change settings that aren't present in the hash" do
+ previous = GC.config
+ GC.config({})
+ GC.config.should == previous
+ end
+
+ it "ignores unknown keys" do
+ previous = GC.config
+ GC.config(foo: "bar")
+ GC.config.should == previous
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "returns the same as GC.config but without the :implementation key" do
+ previous = GC.config
+ GC.config({}).should == previous.except(:implementation)
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "returns the same as GC.config, including the :implementation key" do
+ previous = GC.config
+ GC.config({}).should == previous
+ end
+ end
+
+ it "raises an ArgumentError if options include global keys" do
+ -> { GC.config(implementation: "default") }.should.raise(ArgumentError, 'Attempting to set read-only key "Implementation"')
+ end
+ end
+
+ context "with a non-hash argument" do
+ it "returns current settings if argument is nil" do
+ GC.config(nil).should == GC.config
+ end
+
+ it "raises ArgumentError for all other arguments" do
+ -> { GC.config([]) }.should.raise(ArgumentError)
+ -> { GC.config("default") }.should.raise(ArgumentError)
+ -> { GC.config(1) }.should.raise(ArgumentError)
+ end
+ end
+
+ guard -> { PlatformGuard.standard? && GC.config[:implementation] == "default" } do
+ context "with default GC implementation on MRI" do
+ before do
+ @default_config = GC.config({})
+ end
+
+ after do
+ GC.config(@default_config.except(:implementation))
+ end
+
+ it "includes :rgengc_allow_full_mark option, true by default" do
+ GC.config.should.include?(:rgengc_allow_full_mark)
+ GC.config[:rgengc_allow_full_mark].should == true
+ end
+
+ it "allows to set :rgengc_allow_full_mark" do
+ # This key maps truthy and falsey values to true and false.
+ GC.config(rgengc_allow_full_mark: nil).should == @default_config.merge(rgengc_allow_full_mark: false)
+ GC.config(rgengc_allow_full_mark: 1.23).should == @default_config.merge(rgengc_allow_full_mark: true)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/gc/count_spec.rb b/spec/ruby/core/gc/count_spec.rb
index af2fbbe713..fe20c4ed2b 100644
--- a/spec/ruby/core/gc/count_spec.rb
+++ b/spec/ruby/core/gc/count_spec.rb
@@ -2,7 +2,7 @@ require_relative '../../spec_helper'
describe "GC.count" do
it "returns an integer" do
- GC.count.should be_kind_of(Integer)
+ GC.count.should.is_a?(Integer)
end
it "increases as collections are run" do
diff --git a/spec/ruby/core/gc/measure_total_time_spec.rb b/spec/ruby/core/gc/measure_total_time_spec.rb
index 05d4598ebc..f5377c18fd 100644
--- a/spec/ruby/core/gc/measure_total_time_spec.rb
+++ b/spec/ruby/core/gc/measure_total_time_spec.rb
@@ -1,19 +1,17 @@
require_relative '../../spec_helper'
-ruby_version_is "3.1" do
- describe "GC.measure_total_time" do
- before :each do
- @default = GC.measure_total_time
- end
+describe "GC.measure_total_time" do
+ before :each do
+ @default = GC.measure_total_time
+ end
- after :each do
- GC.measure_total_time = @default
- end
+ after :each do
+ GC.measure_total_time = @default
+ end
- it "can set and get a boolean value" do
- original = GC.measure_total_time
- GC.measure_total_time = !original
- GC.measure_total_time.should == !original
- end
+ it "can set and get a boolean value" do
+ original = GC.measure_total_time
+ GC.measure_total_time = !original
+ GC.measure_total_time.should == !original
end
end
diff --git a/spec/ruby/core/gc/profiler/enabled_spec.rb b/spec/ruby/core/gc/profiler/enabled_spec.rb
index 23677be555..cfcd0951f0 100644
--- a/spec/ruby/core/gc/profiler/enabled_spec.rb
+++ b/spec/ruby/core/gc/profiler/enabled_spec.rb
@@ -11,11 +11,11 @@ describe "GC::Profiler.enabled?" do
it "reports as enabled when enabled" do
GC::Profiler.enable
- GC::Profiler.enabled?.should be_true
+ GC::Profiler.enabled?.should == true
end
it "reports as disabled when disabled" do
GC::Profiler.disable
- GC::Profiler.enabled?.should be_false
+ GC::Profiler.enabled?.should == false
end
end
diff --git a/spec/ruby/core/gc/profiler/result_spec.rb b/spec/ruby/core/gc/profiler/result_spec.rb
index 2ab46a8371..e888f975dc 100644
--- a/spec/ruby/core/gc/profiler/result_spec.rb
+++ b/spec/ruby/core/gc/profiler/result_spec.rb
@@ -2,6 +2,6 @@ require_relative '../../../spec_helper'
describe "GC::Profiler.result" do
it "returns a string" do
- GC::Profiler.result.should be_kind_of(String)
+ GC::Profiler.result.should.is_a?(String)
end
end
diff --git a/spec/ruby/core/gc/profiler/total_time_spec.rb b/spec/ruby/core/gc/profiler/total_time_spec.rb
index 7709f168dd..a351e922af 100644
--- a/spec/ruby/core/gc/profiler/total_time_spec.rb
+++ b/spec/ruby/core/gc/profiler/total_time_spec.rb
@@ -2,6 +2,6 @@ require_relative '../../../spec_helper'
describe "GC::Profiler.total_time" do
it "returns an float" do
- GC::Profiler.total_time.should be_kind_of(Float)
+ GC::Profiler.total_time.should.is_a?(Float)
end
end
diff --git a/spec/ruby/core/gc/stat_spec.rb b/spec/ruby/core/gc/stat_spec.rb
index 3b43b28a92..6e4800b3e3 100644
--- a/spec/ruby/core/gc/stat_spec.rb
+++ b/spec/ruby/core/gc/stat_spec.rb
@@ -3,7 +3,7 @@ require_relative '../../spec_helper'
describe "GC.stat" do
it "returns hash of values" do
stat = GC.stat
- stat.should be_kind_of(Hash)
+ stat.should.is_a?(Hash)
stat.keys.should.include?(:count)
end
@@ -11,18 +11,18 @@ describe "GC.stat" do
hash = { count: "hello", __other__: "world" }
stat = GC.stat(hash)
- stat.should be_kind_of(Hash)
- stat.should equal hash
- stat[:count].should be_kind_of(Integer)
+ stat.should.is_a?(Hash)
+ stat.should.equal? hash
+ stat[:count].should.is_a?(Integer)
stat[:__other__].should == "world"
end
it "the values are all Integer since rb_gc_stat() returns size_t" do
- GC.stat.values.each { |value| value.should be_kind_of(Integer) }
+ GC.stat.values.each { |value| value.should.is_a?(Integer) }
end
it "can return a single value" do
- GC.stat(:count).should be_kind_of(Integer)
+ GC.stat(:count).should.is_a?(Integer)
end
it "increases count after GC is run" do
@@ -38,25 +38,25 @@ describe "GC.stat" do
end
it "provides some number for count" do
- GC.stat(:count).should be_kind_of(Integer)
- GC.stat[:count].should be_kind_of(Integer)
+ GC.stat(:count).should.is_a?(Integer)
+ GC.stat[:count].should.is_a?(Integer)
end
it "provides some number for heap_free_slots" do
- GC.stat(:heap_free_slots).should be_kind_of(Integer)
- GC.stat[:heap_free_slots].should be_kind_of(Integer)
+ GC.stat(:heap_free_slots).should.is_a?(Integer)
+ GC.stat[:heap_free_slots].should.is_a?(Integer)
end
it "provides some number for total_allocated_objects" do
- GC.stat(:total_allocated_objects).should be_kind_of(Integer)
- GC.stat[:total_allocated_objects].should be_kind_of(Integer)
+ GC.stat(:total_allocated_objects).should.is_a?(Integer)
+ GC.stat[:total_allocated_objects].should.is_a?(Integer)
end
it "raises an error if argument is not nil, a symbol, or a hash" do
- -> { GC.stat(7) }.should raise_error(TypeError, "non-hash or symbol given")
+ -> { GC.stat(7) }.should.raise(TypeError, "non-hash or symbol given")
end
it "raises an error if an unknown key is given" do
- -> { GC.stat(:foo) }.should raise_error(ArgumentError, "unknown key: foo")
+ -> { GC.stat(:foo) }.should.raise(ArgumentError, "unknown key: foo")
end
end
diff --git a/spec/ruby/core/gc/stress_spec.rb b/spec/ruby/core/gc/stress_spec.rb
index ca62c0cb4e..227a795e7f 100644
--- a/spec/ruby/core/gc/stress_spec.rb
+++ b/spec/ruby/core/gc/stress_spec.rb
@@ -7,11 +7,11 @@ describe "GC.stress" do
end
it "returns current status of GC stress mode" do
- GC.stress.should be_false
+ GC.stress.should == false
GC.stress = true
- GC.stress.should be_true
+ GC.stress.should == true
GC.stress = false
- GC.stress.should be_false
+ GC.stress.should == false
end
end
@@ -22,6 +22,6 @@ describe "GC.stress=" do
it "sets the stress mode" do
GC.stress = true
- GC.stress.should be_true
+ GC.stress.should == true
end
end
diff --git a/spec/ruby/core/gc/total_time_spec.rb b/spec/ruby/core/gc/total_time_spec.rb
index fcc8f45a83..f10e0ad742 100644
--- a/spec/ruby/core/gc/total_time_spec.rb
+++ b/spec/ruby/core/gc/total_time_spec.rb
@@ -1,15 +1,13 @@
require_relative '../../spec_helper'
-ruby_version_is "3.1" do
- describe "GC.total_time" do
- it "returns an Integer" do
- GC.total_time.should be_kind_of(Integer)
- end
+describe "GC.total_time" do
+ it "returns an Integer" do
+ GC.total_time.should.is_a?(Integer)
+ end
- it "increases as collections are run" do
- time_before = GC.total_time
- GC.start
- GC.total_time.should >= time_before
- end
+ it "increases as collections are run" do
+ time_before = GC.total_time
+ GC.start
+ GC.total_time.should >= time_before
end
end