From 5185a7a5c83220b97889148f2fe33426bc3e06e9 Mon Sep 17 00:00:00 2001 From: Brandon Fish Date: Fri, 19 Nov 2021 15:06:00 -0600 Subject: [PATCH] Implement GC.{measure_total_time, total_time} and update GC.stat to update provided hash --- core/gc/measure_total_time_spec.rb | 19 +++++++++++++++++++ core/gc/stat_spec.rb | 8 ++++++++ core/gc/total_time_spec.rb | 15 +++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 core/gc/measure_total_time_spec.rb create mode 100644 core/gc/total_time_spec.rb diff --git a/core/gc/measure_total_time_spec.rb b/core/gc/measure_total_time_spec.rb new file mode 100644 index 0000000000..05d4598ebc --- /dev/null +++ b/core/gc/measure_total_time_spec.rb @@ -0,0 +1,19 @@ +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 + + 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 + end +end diff --git a/core/gc/stat_spec.rb b/core/gc/stat_spec.rb index 8c2eb5488d..3b43b28a92 100644 --- a/core/gc/stat_spec.rb +++ b/core/gc/stat_spec.rb @@ -51,4 +51,12 @@ GC.stat(:total_allocated_objects).should be_kind_of(Integer) GC.stat[:total_allocated_objects].should be_kind_of(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") + end + + it "raises an error if an unknown key is given" do + -> { GC.stat(:foo) }.should raise_error(ArgumentError, "unknown key: foo") + end end diff --git a/core/gc/total_time_spec.rb b/core/gc/total_time_spec.rb new file mode 100644 index 0000000000..9b4f16e603 --- /dev/null +++ b/core/gc/total_time_spec.rb @@ -0,0 +1,15 @@ +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 + + it "increases as collections are run" do + time_before = GC.total_time + GC.start + GC.total_time.should > time_before + end + end +end