1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2018-04-28 19:50:06 +00:00
parent b864bd05bf
commit 4fbb9aa3cb
145 changed files with 2847 additions and 2596 deletions

View file

@ -400,52 +400,51 @@ describe "Module#autoload" do
ModuleSpecs::Autoload.send(:remove_const, :Concur)
end
ruby_bug "#10892", ""..."2.3" do
it "blocks others threads while doing an autoload" do
file_path = fixture(__FILE__, "repeated_concurrent_autoload.rb")
autoload_path = file_path.sub(/\.rb\Z/, '')
mod_count = 30
thread_count = 16
# https://bugs.ruby-lang.org/issues/10892
it "blocks others threads while doing an autoload" do
file_path = fixture(__FILE__, "repeated_concurrent_autoload.rb")
autoload_path = file_path.sub(/\.rb\Z/, '')
mod_count = 30
thread_count = 16
mod_names = []
mod_count.times do |i|
mod_name = :"Mod#{i}"
Object.autoload mod_name, autoload_path
mod_names << mod_name
end
mod_names = []
mod_count.times do |i|
mod_name = :"Mod#{i}"
Object.autoload mod_name, autoload_path
mod_names << mod_name
end
barrier = ModuleSpecs::CyclicBarrier.new thread_count
ScratchPad.record ModuleSpecs::ThreadSafeCounter.new
barrier = ModuleSpecs::CyclicBarrier.new thread_count
ScratchPad.record ModuleSpecs::ThreadSafeCounter.new
threads = (1..thread_count).map do
Thread.new do
mod_names.each do |mod_name|
break false unless barrier.enabled?
threads = (1..thread_count).map do
Thread.new do
mod_names.each do |mod_name|
break false unless barrier.enabled?
was_last_one_in = barrier.await # wait for all threads to finish the iteration
# clean up so we can autoload the same file again
$LOADED_FEATURES.delete(file_path) if was_last_one_in && $LOADED_FEATURES.include?(file_path)
barrier.await # get ready for race
was_last_one_in = barrier.await # wait for all threads to finish the iteration
# clean up so we can autoload the same file again
$LOADED_FEATURES.delete(file_path) if was_last_one_in && $LOADED_FEATURES.include?(file_path)
barrier.await # get ready for race
begin
Object.const_get(mod_name).foo
rescue NoMethodError
barrier.disable!
break false
end
begin
Object.const_get(mod_name).foo
rescue NoMethodError
barrier.disable!
break false
end
end
end
end
# check that no thread got a NoMethodError because of partially loaded module
threads.all? {|t| t.value}.should be_true
# check that no thread got a NoMethodError because of partially loaded module
threads.all? {|t| t.value}.should be_true
# check that the autoloaded file was evaled exactly once
ScratchPad.recorded.get.should == mod_count
# check that the autoloaded file was evaled exactly once
ScratchPad.recorded.get.should == mod_count
mod_names.each do |mod_name|
Object.send(:remove_const, mod_name)
end
mod_names.each do |mod_name|
Object.send(:remove_const, mod_name)
end
end

View file

@ -222,19 +222,17 @@ describe "Module#define_method" do
}.should raise_error(ArgumentError)
end
ruby_version_is "2.3" do
it "does not use the caller block when no block is given" do
o = Object.new
def o.define(name)
self.class.class_eval do
define_method(name)
end
it "does not use the caller block when no block is given" do
o = Object.new
def o.define(name)
self.class.class_eval do
define_method(name)
end
lambda {
o.define(:foo) { raise "not used" }
}.should raise_error(ArgumentError)
end
lambda {
o.define(:foo) { raise "not used" }
}.should raise_error(ArgumentError)
end
it "does not change the arity check style of the original proc" do

View file

@ -1,52 +1,50 @@
require_relative '../../spec_helper'
ruby_version_is "2.3" do
describe "Module#deprecate_constant" do
before :each do
@module = Module.new
@value = :value
@module::PUBLIC1 = @value
@module::PUBLIC2 = @value
@module::PRIVATE = @value
@module.private_constant :PRIVATE
@module.deprecate_constant :PRIVATE
@pattern = /deprecated/
describe "Module#deprecate_constant" do
before :each do
@module = Module.new
@value = :value
@module::PUBLIC1 = @value
@module::PUBLIC2 = @value
@module::PRIVATE = @value
@module.private_constant :PRIVATE
@module.deprecate_constant :PRIVATE
@pattern = /deprecated/
end
describe "when accessing the deprecated module" do
it "passes the accessing" do
@module.deprecate_constant :PUBLIC1
value = nil
lambda {
value = @module::PUBLIC1
}.should complain(@pattern)
value.should equal(@value)
lambda { @module::PRIVATE }.should raise_error(NameError)
end
describe "when accessing the deprecated module" do
it "passes the accessing" do
@module.deprecate_constant :PUBLIC1
value = nil
lambda {
value = @module::PUBLIC1
}.should complain(@pattern)
value.should equal(@value)
lambda { @module::PRIVATE }.should raise_error(NameError)
end
it "warns with a message" do
@module.deprecate_constant :PUBLIC1
lambda { @module::PUBLIC1 }.should complain(@pattern)
lambda { @module.const_get :PRIVATE }.should complain(@pattern)
end
end
it "accepts multiple symbols and strings as constant names" do
@module.deprecate_constant "PUBLIC1", :PUBLIC2
it "warns with a message" do
@module.deprecate_constant :PUBLIC1
lambda { @module::PUBLIC1 }.should complain(@pattern)
lambda { @module::PUBLIC2 }.should complain(@pattern)
end
it "returns self" do
@module.deprecate_constant(:PUBLIC1).should equal(@module)
end
it "raises a NameError when given an undefined name" do
lambda { @module.deprecate_constant :UNDEFINED }.should raise_error(NameError)
lambda { @module.const_get :PRIVATE }.should complain(@pattern)
end
end
it "accepts multiple symbols and strings as constant names" do
@module.deprecate_constant "PUBLIC1", :PUBLIC2
lambda { @module::PUBLIC1 }.should complain(@pattern)
lambda { @module::PUBLIC2 }.should complain(@pattern)
end
it "returns self" do
@module.deprecate_constant(:PUBLIC1).should equal(@module)
end
it "raises a NameError when given an undefined name" do
lambda { @module.deprecate_constant :UNDEFINED }.should raise_error(NameError)
end
end

View file

@ -110,12 +110,10 @@ describe "Module#prepend" do
c.instance_method(:alias).owner.should == c
end
ruby_version_is "2.3" do
it "reports the class for the owner of a method aliased from the prepended module" do
m = Module.new { def meth; :m end }
c = Class.new { prepend(m); alias_method :alias, :meth }
c.instance_method(:alias).owner.should == c
end
it "reports the class for the owner of a method aliased from the prepended module" do
m = Module.new { def meth; :m end }
c = Class.new { prepend(m); alias_method :alias, :meth }
c.instance_method(:alias).owner.should == c
end
it "sees an instance of a prepended class as kind of the prepended module" do

View file

@ -52,46 +52,44 @@ describe "Module#private" do
end.should raise_error(NameError)
end
ruby_version_is "2.3" do
ruby_bug "#14604", "2.3"..."2.5.1" do
it "only makes the method private in the class it is called on" do
base = Class.new do
def wrapped
1
end
ruby_bug "#14604", ""..."2.5.1" do
it "only makes the method private in the class it is called on" do
base = Class.new do
def wrapped
1
end
klass = Class.new(base) do
def wrapped
super + 1
end
private :wrapped
end
base.new.wrapped.should == 1
lambda do
klass.new.wrapped
end.should raise_error(NameError)
end
it "continues to allow a prepended module method to call super" do
wrapper = Module.new do
def wrapped
super + 1
end
klass = Class.new(base) do
def wrapped
super + 1
end
klass = Class.new do
prepend wrapper
def wrapped
1
end
private :wrapped
end
klass.new.wrapped.should == 2
private :wrapped
end
base.new.wrapped.should == 1
lambda do
klass.new.wrapped
end.should raise_error(NameError)
end
it "continues to allow a prepended module method to call super" do
wrapper = Module.new do
def wrapped
super + 1
end
end
klass = Class.new do
prepend wrapper
def wrapped
1
end
private :wrapped
end
klass.new.wrapped.should == 2
end
end
end