From 4fbb9aa3cb6c31ec128bfb31f59efa66d66adba4 Mon Sep 17 00:00:00 2001 From: eregon Date: Sat, 28 Apr 2018 19:50:06 +0000 Subject: Update to ruby/spec@6f38a82 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/ruby/core/module/autoload_spec.rb | 77 ++++++++++++------------ spec/ruby/core/module/define_method_spec.rb | 20 +++--- spec/ruby/core/module/deprecate_constant_spec.rb | 74 +++++++++++------------ spec/ruby/core/module/prepend_spec.rb | 10 ++- spec/ruby/core/module/private_spec.rb | 58 +++++++++--------- 5 files changed, 115 insertions(+), 124 deletions(-) (limited to 'spec/ruby/core/module') diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb index f375ac2450..f355a5968d 100644 --- a/spec/ruby/core/module/autoload_spec.rb +++ b/spec/ruby/core/module/autoload_spec.rb @@ -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 - - mod_names = [] - mod_count.times do |i| - mod_name = :"Mod#{i}" - Object.autoload mod_name, autoload_path - mod_names << mod_name - end + # 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 + + 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? - - 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 + 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 + + 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 diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb index 957b401415..3f35c051a1 100644 --- a/spec/ruby/core/module/define_method_spec.rb +++ b/spec/ruby/core/module/define_method_spec.rb @@ -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 diff --git a/spec/ruby/core/module/deprecate_constant_spec.rb b/spec/ruby/core/module/deprecate_constant_spec.rb index 4564497738..0954a6d8a5 100644 --- a/spec/ruby/core/module/deprecate_constant_spec.rb +++ b/spec/ruby/core/module/deprecate_constant_spec.rb @@ -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/ - 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) +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 - lambda { @module::PRIVATE }.should raise_error(NameError) - end + describe "when accessing the deprecated module" do + it "passes the accessing" do + @module.deprecate_constant :PUBLIC1 - it "warns with a message" do - @module.deprecate_constant :PUBLIC1 + value = nil + lambda { + value = @module::PUBLIC1 + }.should complain(@pattern) + value.should equal(@value) - lambda { @module::PUBLIC1 }.should complain(@pattern) - lambda { @module.const_get :PRIVATE }.should complain(@pattern) - end + lambda { @module::PRIVATE }.should raise_error(NameError) 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) + lambda { @module.const_get :PRIVATE }.should complain(@pattern) end + end - it "returns self" do - @module.deprecate_constant(:PUBLIC1).should equal(@module) - end + it "accepts multiple symbols and strings as constant names" do + @module.deprecate_constant "PUBLIC1", :PUBLIC2 - it "raises a NameError when given an undefined name" do - lambda { @module.deprecate_constant :UNDEFINED }.should raise_error(NameError) - end + 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 diff --git a/spec/ruby/core/module/prepend_spec.rb b/spec/ruby/core/module/prepend_spec.rb index 35b31f1fb0..ca80eb360f 100644 --- a/spec/ruby/core/module/prepend_spec.rb +++ b/spec/ruby/core/module/prepend_spec.rb @@ -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 diff --git a/spec/ruby/core/module/private_spec.rb b/spec/ruby/core/module/private_spec.rb index bf3e86a333..d476c6f54e 100644 --- a/spec/ruby/core/module/private_spec.rb +++ b/spec/ruby/core/module/private_spec.rb @@ -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 + end - klass = Class.new(base) do - def wrapped - super + 1 - end - private :wrapped + klass = Class.new(base) do + def wrapped + super + 1 end - - base.new.wrapped.should == 1 - lambda do - klass.new.wrapped - end.should raise_error(NameError) + private :wrapped end - it "continues to allow a prepended module method to call super" do - wrapper = Module.new do - def wrapped - super + 1 - 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 + klass = Class.new do + prepend wrapper - def wrapped - 1 - end - private :wrapped + def wrapped + 1 end - - klass.new.wrapped.should == 2 + private :wrapped end + + klass.new.wrapped.should == 2 end end end -- cgit v1.2.3