-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fea0932
commit d756270
Showing
2 changed files
with
235 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,240 @@ | ||
require_relative "test_helper" | ||
require_relative 'test_helper' | ||
|
||
class GCTest < StdlibTest | ||
target GC | ||
class GCSingletonTest < Test::Unit::TestCase | ||
include TestHelper | ||
|
||
include GC | ||
testing "singleton(::GC)" | ||
|
||
def test_garbage_collect | ||
garbage_collect | ||
garbage_collect(full_mark: true) | ||
garbage_collect(full_mark: false) | ||
garbage_collect(immediate_mark: true) | ||
garbage_collect(immediate_mark: false) | ||
garbage_collect(immediate_sweep: true) | ||
garbage_collect(immediate_sweep: false) | ||
def test_INTERNAL_CONSTANTS | ||
assert_const_type 'Hash[Symbol, Integer | bool]', | ||
'GC::INTERNAL_CONSTANTS' | ||
end | ||
|
||
def test_OPTS | ||
assert_const_type 'Array[String]', | ||
'GC::OPTS' | ||
end | ||
|
||
def test_count | ||
assert_send_type '() -> Integer', | ||
GC, :count | ||
end | ||
|
||
def test_disable | ||
was_disabled = GC.disable | ||
|
||
assert_send_type '() -> bool', | ||
GC, :disable | ||
ensure | ||
GC.enable unless was_disabled | ||
end | ||
|
||
def test_enable | ||
was_enabled = GC.enable | ||
|
||
assert_send_type '() -> bool', | ||
GC, :enable | ||
ensure | ||
GC.disable unless was_enabled | ||
end | ||
|
||
def test_start | ||
GC.start | ||
GC.start(full_mark: true) | ||
GC.start(full_mark: false) | ||
GC.start(immediate_mark: true) | ||
GC.start(immediate_mark: false) | ||
GC.start(immediate_sweep: true) | ||
GC.start(immediate_sweep: false) | ||
assert_send_type '() -> nil', | ||
GC, :start | ||
|
||
[true, Object.new, nil].each do |immediate_sweep| | ||
[true, Object.new, nil].each do |immediate_mark| | ||
[true, Object.new, nil].each do |full_mark| | ||
assert_send_type '(immediate_sweep: boolish, immediate_mark: boolish, full_mark: boolish) -> nil', | ||
GC, :start, immediate_sweep: immediate_sweep, immediate_mark: immediate_mark, full_mark: full_mark | ||
end | ||
end | ||
end | ||
end | ||
|
||
def test_stat | ||
assert_send_type '() -> Hash[Symbol, Integer]', | ||
GC, :stat | ||
assert_send_type '(Hash[Symbol, Integer]) -> Hash[Symbol, Integer]', | ||
GC, :stat, {} | ||
assert_send_type '(nil) -> Hash[Symbol, Integer]', | ||
GC, :stat, nil | ||
assert_send_type '(Symbol) -> Integer', | ||
GC, :stat, :count | ||
end | ||
|
||
def test_stress_and_stress= | ||
old_stress = GC.stress | ||
|
||
assert_send_type '() -> (Integer | bool)', | ||
GC, :stress | ||
assert_send_type '(Integer) -> Integer', | ||
GC, :stress=, 0 | ||
assert_send_type '() -> (Integer | bool)', | ||
GC, :stress | ||
[true, false].each do |bool| | ||
assert_send_type '(bool) -> bool', | ||
GC, :stress=, bool | ||
end | ||
ensure | ||
GC.stress = old_stress | ||
end | ||
|
||
def test_total_time | ||
assert_send_type '() -> Integer', | ||
GC, :total_time | ||
end | ||
|
||
def test_compact | ||
GC.compact | ||
assert_send_type '() -> GC::compact_info', | ||
GC, :compact | ||
end | ||
|
||
def test_verify_compaction_references | ||
GC.verify_compaction_references | ||
assert_send_type '() -> GC::compact_info', | ||
GC, :verify_compaction_references | ||
end | ||
|
||
def test_verify_internal_consistency | ||
GC.verify_internal_consistency | ||
assert_send_type '() -> nil', | ||
GC, :verify_internal_consistency | ||
end | ||
|
||
def test_latest_gc_info | ||
GC.latest_gc_info | ||
GC.latest_gc_info({}) | ||
GC.latest_gc_info(:state) | ||
assert_send_type '() -> Hash[Symbol, untyped]', | ||
GC, :latest_gc_info | ||
assert_send_type '(nil) -> Hash[Symbol, untyped]', | ||
GC, :latest_gc_info, nil | ||
assert_send_type '(Hash[Symbol, untyped]) -> Hash[Symbol, untyped]', | ||
GC, :latest_gc_info, {} | ||
|
||
assert_send_type '(Symbol) -> untyped', | ||
GC, :latest_gc_info, :major_by | ||
end | ||
|
||
def test_auto_compact | ||
assert_send_type '() -> bool', | ||
GC, :auto_compact | ||
end | ||
|
||
def test_auto_compact= | ||
old = GC.auto_compact | ||
|
||
[true, nil, Object.new, 1r].each do |obj| | ||
assert_send_type '[T] (T) -> T', | ||
GC, :auto_compact=, obj | ||
end | ||
ensure | ||
GC.auto_compact = old | ||
end | ||
|
||
def test_latest_compact_info | ||
assert_send_type '() -> GC::compact_info', | ||
GC, :latest_compact_info | ||
end | ||
|
||
def test_set_stress | ||
GC.stress = 0 | ||
GC.stress = true | ||
GC.stress = false | ||
def test_measure_total_time | ||
assert_send_type '() -> bool', | ||
GC, :measure_total_time | ||
end | ||
|
||
def test_measure_total_time= | ||
old = GC.measure_total_time | ||
|
||
[true, nil, Object.new, 1r].each do |obj| | ||
assert_send_type '[T] (T) -> T', | ||
GC, :measure_total_time=, obj | ||
end | ||
ensure | ||
GC.measure_total_time = old | ||
end | ||
end | ||
|
||
class GCIncludeTest < Test::Unit::TestCase | ||
include TypeAssertions | ||
|
||
class GCSingletonTest < Test::Unit::TestCase | ||
include TestHelper | ||
testing '::GC' | ||
|
||
testing "singleton(::GC)" | ||
class Foo | ||
extend GC | ||
end | ||
|
||
def test_garbage_collect | ||
assert_send_type '() -> nil', | ||
Foo, :garbage_collect | ||
|
||
[true, Object.new, nil].each do |immediate_sweep| | ||
[true, Object.new, nil].each do |immediate_mark| | ||
[true, Object.new, nil].each do |full_mark| | ||
assert_send_type '(immediate_sweep: boolish, immediate_mark: boolish, full_mark: boolish) -> nil', | ||
Foo, :garbage_collect, immediate_sweep: immediate_sweep, immediate_mark: immediate_mark, full_mark: full_mark | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
class GC_ProfilerSingletonTest < Test::Unit::TestCase | ||
include TypeAssertions | ||
|
||
testing 'singleton(::GC::Profiler)' | ||
|
||
def test_clear | ||
assert_send_type '() -> nil', | ||
GC::Profiler, :clear | ||
end | ||
|
||
def test_enabled? | ||
assert_send_type '() -> bool', | ||
GC::Profiler, :enabled? | ||
end | ||
|
||
def test_enable_and_disable | ||
was_enabled = GC::Profiler.enabled? | ||
|
||
assert_send_type '() -> nil', | ||
GC::Profiler, :enable | ||
assert_send_type '() -> nil', | ||
GC::Profiler, :disable | ||
ensure | ||
GC::Profiler.enable if was_enabled | ||
end | ||
|
||
def test_raw_data | ||
was_enabled = GC::Profiler.enabled? | ||
GC::Profiler.disable | ||
|
||
assert_send_type '() -> nil', | ||
GC::Profiler, :raw_data | ||
|
||
GC::Profiler.enable | ||
GC.start | ||
assert_send_type '() -> Array[Hash[Symbol, untyped]]', | ||
GC::Profiler, :raw_data | ||
ensure | ||
GC::Profiler.enable if was_enabled | ||
end | ||
|
||
def test_report | ||
old_stdout = $stdout | ||
$stdout = Object.new.tap { def _1.write(*) end } | ||
|
||
assert_send_type '() -> nil', | ||
GC::Profiler, :report | ||
|
||
assert_send_type '(_Writer) -> nil', | ||
GC::Profiler, :report, Writer.new | ||
ensure | ||
$stdout = old_stdout | ||
end | ||
|
||
def test_result | ||
assert_send_type '() -> String', | ||
GC::Profiler, :result | ||
end | ||
|
||
def test_total_time | ||
assert_send_type( | ||
"() -> Integer", | ||
GC, :total_time | ||
) | ||
assert_send_type '() -> Float', | ||
GC::Profiler, :total_time | ||
end | ||
end |