Skip to content

Commit 5185a7a

Browse files
bjfisheregon
authored andcommitted
Implement GC.{measure_total_time, total_time} and update GC.stat to update provided hash
1 parent d797c39 commit 5185a7a

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

core/gc/measure_total_time_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require_relative '../../spec_helper'
2+
3+
ruby_version_is "3.1" do
4+
describe "GC.measure_total_time" do
5+
before :each do
6+
@default = GC.measure_total_time
7+
end
8+
9+
after :each do
10+
GC.measure_total_time = @default
11+
end
12+
13+
it "can set and get a boolean value" do
14+
original = GC.measure_total_time
15+
GC.measure_total_time = !original
16+
GC.measure_total_time.should == !original
17+
end
18+
end
19+
end

core/gc/stat_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,12 @@
5151
GC.stat(:total_allocated_objects).should be_kind_of(Integer)
5252
GC.stat[:total_allocated_objects].should be_kind_of(Integer)
5353
end
54+
55+
it "raises an error if argument is not nil, a symbol, or a hash" do
56+
-> { GC.stat(7) }.should raise_error(TypeError, "non-hash or symbol given")
57+
end
58+
59+
it "raises an error if an unknown key is given" do
60+
-> { GC.stat(:foo) }.should raise_error(ArgumentError, "unknown key: foo")
61+
end
5462
end

core/gc/total_time_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require_relative '../../spec_helper'
2+
3+
ruby_version_is "3.1" do
4+
describe "GC.total_time" do
5+
it "returns an Integer" do
6+
GC.total_time.should be_kind_of(Integer)
7+
end
8+
9+
it "increases as collections are run" do
10+
time_before = GC.total_time
11+
GC.start
12+
GC.total_time.should > time_before
13+
end
14+
end
15+
end

0 commit comments

Comments
 (0)