зеркало из https://github.com/github/ruby.git
[Bug #19872] Refine TestRequireLib
Always test only the scripts just under “lib", and just under child directories which has not the same name script in the upper level; instead of random sampling from whole libraries.
This commit is contained in:
Родитель
435b243978
Коммит
234722ed9f
|
@ -1,25 +1,26 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: true
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
class TestRequireLib < Test::Unit::TestCase
|
class TestRequireLib < Test::Unit::TestCase
|
||||||
TEST_RATIO = ENV["TEST_REQUIRE_THREAD_RATIO"]&.tap {|s|break s.to_f} || 0.05 # testing all files needs too long time...
|
libdir = __dir__ + '/../../lib'
|
||||||
|
|
||||||
Dir.glob(File.expand_path('../../lib/**/*.rb', __dir__)).each do |lib|
|
# .rb files at lib
|
||||||
# skip some problems
|
scripts = Dir.glob('*.rb', base: libdir).map {|f| f.chomp('.rb')}
|
||||||
next if %r!/lib/(?:bundler|rubygems)\b! =~ lib
|
|
||||||
next if %r!/lib/(?:debug|mkmf)\.rb\z! =~ lib
|
# .rb files in subdirectories of lib without same name script
|
||||||
next if %r!/lib/irb/ext/tracer\.rb\z! =~ lib
|
dirs = Dir.glob('*/', base: libdir).map {|d| d.chomp('/')}
|
||||||
# skip many files that almost use no threads
|
dirs -= scripts
|
||||||
next if TEST_RATIO < rand(0.0..1.0)
|
scripts.concat(Dir.glob(dirs.map {|d| d + '/*.rb'}, base: libdir).map {|f| f.chomp('.rb')})
|
||||||
|
|
||||||
|
# skip some problems
|
||||||
|
scripts -= %w[bundler bundled_gems rubygems mkmf]
|
||||||
|
|
||||||
|
scripts.each do |lib|
|
||||||
define_method "test_thread_size:#{lib}" do
|
define_method "test_thread_size:#{lib}" do
|
||||||
assert_separately(['-W0'], "#{<<~"begin;"}\n#{<<~"end;"}")
|
assert_separately(['-W0'], "#{<<~"begin;"}\n#{<<~"end;"}")
|
||||||
begin;
|
begin;
|
||||||
n = Thread.list.size
|
n = Thread.list.size
|
||||||
begin
|
require #{lib.dump}
|
||||||
require #{lib.dump}
|
|
||||||
rescue Exception
|
|
||||||
omit $!
|
|
||||||
end
|
|
||||||
assert_equal n, Thread.list.size
|
assert_equal n, Thread.list.size
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче