1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

check GC.enable'd status

Check GC.enable'd status before and after test execution.

Write this checker in gc_checker.rb, it was renamed from
gc_compact_checker.rb.
This commit is contained in:
Koichi Sasada 2021-08-05 16:21:15 +09:00
parent 405644f38c
commit 228b3e43be
Notes: git 2021-08-05 17:12:15 +09:00
4 changed files with 38 additions and 12 deletions

36
tool/lib/gc_checker.rb Normal file
View file

@ -0,0 +1,36 @@
# frozen_string_literal: true
module GCDisabledChecker
def before_setup
if @__gc_disabled__ = GC.enable # return true if GC is disabled
GC.disable
end
super
end
def after_teardown
super
disabled = GC.enable
GC.disable if @__gc_disabled__
if @__gc_disabled__ != disabled
label = {
true => 'disabled',
false => 'enabled',
}
raise "GC was #{label[@__gc_disabled__]}, but is #{label[disabled]} after the test."
end
end
end
module GCCompactChecker
def after_teardown
super
GC.compact
end
end
Test::Unit::TestCase.include GCDisabledChecker
Test::Unit::TestCase.include GCCompactChecker if ENV['RUBY_TEST_GC_COMPACT']

View file

@ -1,10 +0,0 @@
# frozen_string_literal: true
module GCCompactChecker
def after_teardown
super
GC.compact
end
end
Test::Unit::TestCase.include GCCompactChecker if ENV['RUBY_TEST_GC_COMPACT']

View file

@ -6,7 +6,7 @@ require "profile_test_all" if ENV.key?('RUBY_TEST_ALL_PROFILE')
require "tracepointchecker"
require "zombie_hunter"
require "iseq_loader_checker"
require "gc_compact_checker"
require "gc_checker"
module Test
module Unit

View file

@ -9,7 +9,7 @@ require "profile_test_all" if ENV.key?('RUBY_TEST_ALL_PROFILE')
require "tracepointchecker"
require "zombie_hunter"
require "iseq_loader_checker"
require "gc_compact_checker"
require "gc_checker"
require_relative "../test-coverage.rb" if ENV.key?('COVERAGE')
case $0