ruby-changes:55154
From: eregon <ko1@a...>
Date: Thu, 28 Mar 2019 23:22:37 +0900 (JST)
Subject: [ruby-changes:55154] eregon:r67361 (trunk): Update to ruby/spec@e81b3cd
eregon 2019-03-28 23:22:29 +0900 (Thu, 28 Mar 2019) New Revision: 67361 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67361 Log: Update to ruby/spec@e81b3cd Added files: trunk/spec/ruby/command_line/dash_upper_x_spec.rb trunk/spec/ruby/command_line/feature_spec.rb trunk/spec/ruby/command_line/fixtures/change_directory_script.rb trunk/spec/ruby/command_line/shared/change_directory.rb trunk/spec/ruby/core/binding/fixtures/irb.rb trunk/spec/ruby/core/binding/irb_spec.rb trunk/spec/ruby/core/kernel/pp_spec.rb trunk/spec/ruby/core/module/fixtures/autoload_overridden.rb trunk/spec/ruby/language/fixtures/for_scope.rb trunk/spec/ruby/library/bigdecimal/util_spec.rb trunk/spec/ruby/security/cve_2019_8321_spec.rb trunk/spec/ruby/security/cve_2019_8322_spec.rb trunk/spec/ruby/security/cve_2019_8323_spec.rb trunk/spec/ruby/security/cve_2019_8325_spec.rb Removed files: trunk/spec/ruby/command_line/fixtures/dash_upper_c_script.rb Modified files: trunk/spec/ruby/.mspec.constants trunk/spec/ruby/.rubocop.yml trunk/spec/ruby/.travis.yml trunk/spec/ruby/command_line/dash_upper_c_spec.rb trunk/spec/ruby/command_line/rubylib_spec.rb trunk/spec/ruby/core/file/mtime_spec.rb trunk/spec/ruby/core/float/to_s_spec.rb trunk/spec/ruby/core/hash/shared/each.rb trunk/spec/ruby/core/io/read_nonblock_spec.rb trunk/spec/ruby/core/kernel/sleep_spec.rb trunk/spec/ruby/core/method/parameters_spec.rb trunk/spec/ruby/core/method/to_proc_spec.rb trunk/spec/ruby/core/module/autoload_spec.rb trunk/spec/ruby/core/module/const_set_spec.rb trunk/spec/ruby/core/string/end_with_spec.rb trunk/spec/ruby/core/string/inspect_spec.rb trunk/spec/ruby/core/thread/list_spec.rb trunk/spec/ruby/core/tracepoint/eval_script_spec.rb trunk/spec/ruby/core/tracepoint/instruction_sequence_spec.rb trunk/spec/ruby/language/alias_spec.rb trunk/spec/ruby/language/for_spec.rb trunk/spec/ruby/language/method_spec.rb trunk/spec/ruby/library/bigdecimal/add_spec.rb trunk/spec/ruby/library/bigdecimal/div_spec.rb trunk/spec/ruby/library/bigdecimal/mult_spec.rb trunk/spec/ruby/library/bigdecimal/multiply_spec.rb trunk/spec/ruby/library/bigdecimal/remainder_spec.rb trunk/spec/ruby/library/bigdecimal/shared/modulo.rb trunk/spec/ruby/library/bigdecimal/shared/quo.rb trunk/spec/ruby/library/bigdecimal/sub_spec.rb trunk/spec/ruby/library/rbconfig/rbconfig_spec.rb trunk/spec/ruby/optional/capi/ext/string_spec.c trunk/spec/ruby/optional/capi/ext/typed_data_spec.c trunk/spec/ruby/optional/capi/kernel_spec.rb trunk/spec/ruby/optional/capi/mutex_spec.rb trunk/spec/ruby/optional/capi/string_spec.rb trunk/spec/ruby/optional/capi/typed_data_spec.rb trunk/spec/ruby/optional/capi/util_spec.rb trunk/spec/ruby/shared/basicobject/send.rb Index: spec/ruby/command_line/fixtures/dash_upper_c_script.rb =================================================================== --- spec/ruby/command_line/fixtures/dash_upper_c_script.rb (revision 67360) +++ spec/ruby/command_line/fixtures/dash_upper_c_script.rb (nonexistent) @@ -1 +0,0 @@ -print Dir.pwd Property changes on: spec/ruby/command_line/fixtures/dash_upper_c_script.rb ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -LF \ No newline at end of property Index: spec/ruby/.rubocop.yml =================================================================== --- spec/ruby/.rubocop.yml (revision 67360) +++ spec/ruby/.rubocop.yml (revision 67361) @@ -96,3 +96,7 @@ Lint/UnreachableCode: https://github.com/ruby/ruby/blob/trunk/spec/ruby/.rubocop.yml#L96 Lint/UriRegexp: Exclude: - 'library/uri/regexp_spec.rb' + +Lint/Debugger: + Exclude: + - 'core/binding/fixtures/irb.rb' Index: spec/ruby/core/method/parameters_spec.rb =================================================================== --- spec/ruby/core/method/parameters_spec.rb (revision 67360) +++ spec/ruby/core/method/parameters_spec.rb (revision 67361) @@ -241,4 +241,19 @@ describe "Method#parameters" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/method/parameters_spec.rb#L241 m = MethodSpecs::Methods.new m.method(:writer=).parameters.should == [[:req]] end + + it "returns [[:rest]] for core methods with variable-length argument lists" do + m = "foo" + + # match takes rest args + m.method(:match).parameters.should == [[:rest]] + + # [] takes 1 to 3 args + m.method(:[]).parameters.should == [[:rest]] + end + + it "returns [[:req]] for each parameter for core methods with fixed-length argument lists" do + m = "foo" + m.method(:+).parameters.should == [[:req]] + end end Index: spec/ruby/core/thread/list_spec.rb =================================================================== --- spec/ruby/core/thread/list_spec.rb (revision 67360) +++ spec/ruby/core/thread/list_spec.rb (revision 67361) @@ -35,8 +35,21 @@ describe "Thread.list" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/thread/list_spec.rb#L35 t.join end end -end -describe "Thread.list" do - it "needs to be reviewed for spec completeness" + it "returns instances of Thread and not null or nil values" do + spawner = Thread.new do + Array.new(100) do + Thread.new {} + end + end + + while spawner.alive? + Thread.list.each { |th| + th.should be_kind_of(Thread) + } + end + + threads = spawner.value + threads.each(&:join) + end end Index: spec/ruby/.mspec.constants =================================================================== --- spec/ruby/.mspec.constants (revision 67360) +++ spec/ruby/.mspec.constants (revision 67361) @@ -88,7 +88,6 @@ IncludeSpecsClass https://github.com/ruby/ruby/blob/trunk/spec/ruby/.mspec.constants#L88 IncludeSpecsMiddle IncludeSpecsTop IncludesMath -InvalidTostrTest JSON KSAutoloadA KSAutoloadB @@ -177,6 +176,7 @@ StringRefinement https://github.com/ruby/ruby/blob/trunk/spec/ruby/.mspec.constants#L176 StringScanner StringSubclass StructClasses +Syck Syslog TCPServer TCPSocket @@ -205,7 +205,6 @@ UserObject https://github.com/ruby/ruby/blob/trunk/spec/ruby/.mspec.constants#L205 UserPreviouslyDefinedWithInitializedIvar UserRegexp UserString -ValidTostrTest Vector WEBrick WIN32OLE Index: spec/ruby/library/bigdecimal/mult_spec.rb =================================================================== --- spec/ruby/library/bigdecimal/mult_spec.rb (revision 67360) +++ spec/ruby/library/bigdecimal/mult_spec.rb (revision 67361) @@ -9,7 +9,8 @@ end https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/mult_spec.rb#L9 describe "BigDecimal#mult" do before :each do @one = BigDecimal "1" - @e3_minus = BigDecimal "3E-20001" + @e3_minus = BigDecimal("3E-20001") + @e3_plus = BigDecimal("3E20001") @e = BigDecimal "1.00000000000000000000123456789" @tolerance = @e.sub @one, 1000 @tolerance2 = BigDecimal "30001E-20005" @@ -21,4 +22,11 @@ describe "BigDecimal#mult" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/mult_spec.rb#L22 @e3_minus.mult(@one, 1).should be_close(0, @tolerance2) end + describe "with Object" do + it "tries to coerce the other operand to self" do + object = mock("Object") + object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus]) + @e3_minus.mult(object, 1).should == BigDecimal("9") + end + end end Index: spec/ruby/library/bigdecimal/remainder_spec.rb =================================================================== --- spec/ruby/library/bigdecimal/remainder_spec.rb (revision 67360) +++ spec/ruby/library/bigdecimal/remainder_spec.rb (revision 67361) @@ -5,7 +5,8 @@ describe "BigDecimal#remainder" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/remainder_spec.rb#L5 before :each do @zero = BigDecimal("0") - @one = BigDecimal("0") + @one = BigDecimal("1") + @three = BigDecimal("3") @mixed = BigDecimal("1.23456789") @pos_int = BigDecimal("2E5555") @neg_int = BigDecimal("-2E5555") @@ -71,9 +72,16 @@ describe "BigDecimal#remainder" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/remainder_spec.rb#L72 end it "coerces arguments to BigDecimal if possible" do - @one.remainder(2).should == @one + @three.remainder(2).should == @one end + describe "with Object" do + it "tries to coerce the other operand to self" do + object = mock("Object") + object.should_receive(:coerce).with(@three).and_return([@three, 2]) + @three.remainder(object).should == @one + end + end it "raises TypeError if the argument cannot be coerced to BigDecimal" do lambda { Index: spec/ruby/library/bigdecimal/util_spec.rb =================================================================== --- spec/ruby/library/bigdecimal/util_spec.rb (nonexistent) +++ spec/ruby/library/bigdecimal/util_spec.rb (revision 67361) @@ -0,0 +1,42 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/util_spec.rb#L1 +require_relative '../../spec_helper' +require 'bigdecimal' +require 'bigdecimal/util' + +describe "BigDecimal's util method definitions" do + describe "#to_d" do + it "should define #to_d on Integer" do + 42.to_d.should == BigDecimal(42) + end + + it "should define #to_d on Float" do + 0.5.to_d.should == BigDecimal(0.5, Float::DIG) + 1.234.to_d(2).should == BigDecimal(1.234, 2) + end + + it "should define #to_d on String" do + "0.5".to_d.should == BigDecimal(0.5, Float::DIG) + "45.67 degrees".to_d.should == BigDecimal(45.67, Float::DIG) + end + + it "should define #to_d on BigDecimal" do + bd = BigDecimal("3.14") + bd.to_d.should equal(bd) + end + + it "should define #to_d on Rational" do + Rational(22, 7).to_d(3).should == BigDecimal(3.14, 3) + end + + ruby_version_is "2.6" do + it "should define #to_d on nil" do + nil.to_d.should == BigDecimal(0) + end + end + end + + describe "#to_digits" do + it "should define #to_digits on BigDecimal" do + BigDecimal("3.14").to_digits.should == "3.14" + end + end +end Index: spec/ruby/library/bigdecimal/multiply_spec.rb =================================================================== --- spec/ruby/library/bigdecimal/multiply_spec.rb (revision 67360) +++ spec/ruby/library/bigdecimal/multiply_spec.rb (revision 67361) @@ -23,4 +23,12 @@ describe "BigDecimal#*" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/multiply_spec.rb#L23 (@e3_minus * @e3_minus).should == BigDecimal("9E-40002") (@e * @one).should == @e end + + describe "with Object" do + it "tries to coerce the other operand to self" do + object = mock("Object") + object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus]) + (@e3_minus * object).should == BigDecimal("9") + end + end end Index: spec/ruby/library/bigdecimal/div_spec.rb =================================================================== --- spec/ruby/library/bigdecimal/div_spec.rb (revision 67360) +++ spec/ruby/library/bigdecimal/div_spec.rb (revision 67361) @@ -42,6 +42,14 @@ describe "BigDecimal#div" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/div_spec.rb#L42 } end + describe "with Object" do + it "tries to coerce the other operand to self" do + object = mock("Object") + object.should_receive(:coerce).with(@one).and_return([@one, @two]) + @one.div(object).should == @zero + end + end + it "raises FloatDomainError if NaN is involved" do lambda { @one.div(@nan) }.should raise_error(FloatDomainError) lambda { @nan.div(@one) }.should raise_error(FloatDomainError) Index: spec/ruby/library/bigdecimal/add_spec.rb =================================================================== --- spec/ruby/library/bigdecimal/add_spec.rb (revision 67360) +++ spec/ruby/library/bigdecimal/add_spec.rb (revision 67361) @@ -73,6 +73,14 @@ describe "BigDecimal#add" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/add_spec.rb#L73 # BigDecimal("0.88").add(0.0, 1).should == BigDecimal("0.9") # end + describe "with Object" do + it "tries to coerce the other operand to self" do + object = mock("Object") + object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4]) + @frac_3.add(object, 1).should == BigDecimal("0.1E16") + end + end + it "favors the precision specified in the second argument over the global limit" do BigDecimalSpecs.with_limit(1) do BigDecimal('0.888').add(@zero, 3).should == BigDecimal('0.888') Index: spec/ruby/library/bigdecimal/sub_spec.rb =================================================================== --- spec/ruby/library/bigdecimal/sub_spec.rb (revision 67360) +++ spec/ruby/library/bigdecimal/sub_spec.rb (revision 67361) @@ -13,6 +13,8 @@ describe "BigDecimal#sub" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/sub_spec.rb#L13 @one_minus = BigDecimal("-1") @frac_1 = BigDecimal("1E-99999") @frac_2 = BigDecimal("0.9E-99999") + @frac_3 = BigDecimal("12345E10") + @frac_4 = BigDecimal("98765E10") end it "returns a - b with given precision" do @@ -32,6 +34,14 @@ describe "BigDecimal#sub" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/sub_spec.rb#L34 @frac_1.sub(@frac_1, 1000000).should == @zero end + describe "with Object" do + it "tries to coerce the other operand to self" do + object = mock("Object") + object.should_receive(:coerce).with(@frac_3).and_return([@frac_3, @frac_4]) + @frac_3.sub(object, 1).should == BigDecimal("-0.9E15") + end + end + it "returns NaN if NaN is involved" do @one.sub(@nan, 1).nan?.should == true @nan.sub(@one, 1).nan?.should == true Index: spec/ruby/library/bigdecimal/shared/modulo.rb =================================================================== --- spec/ruby/library/bigdecimal/shared/modulo.rb (revision 67360) +++ spec/ruby/library/bigdecimal/shared/modulo.rb (revision 67361) @@ -70,6 +70,15 @@ describe :bigdecimal_modulo, shared: tru https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/shared/modulo.rb#L70 res.kind_of?(BigDecimal).should == true end + describe "with Object" do + it "tries to coerce the other operand to self" do + bd6543 = BigDecimal("6543.21") + object = mock("Object") + object.should_receive(:coerce).with(bd6543).and_return([bd6543, 137]) + bd6543.send(@method, object, *@object).should == BigDecimal("104.21") + end + end + it "returns NaN if NaN is involved" do @nan.send(@method, @nan).nan?.should == true @nan.send(@method, @one).nan?.should == true Index: spec/ruby/library/bigdecimal/shared/quo.rb =================================================================== --- spec/ruby/library/bigdecimal/shared/quo.rb (revision 67360) +++ spec/ruby/library/bigdecimal/shared/quo.rb (revision 67361) @@ -29,6 +29,14 @@ describe :bigdecimal_quo, shared: true d https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/bigdecimal/shared/quo.rb#L29 @one.send(@method, BigDecimal('2E-5555'), *@object).should == BigDecimal('0.5E5555') end + describe "with Object" do + it "tries to coerce the other operand to self" do + object = mock("Object") + object.should_receive(:coerce).with(@one).and_return([@one, @two]) + @one.send(@method, object, *@object).should == BigDecimal("0.5") + end + end + it "returns 0 if divided by Infinity" do @zero.send(@method, @infinity, *@object).should == 0 @frac_2.send(@method, @infinity, *@object).should == 0 Index: spec/ruby/library/rbconfig/rbconfig_spec.rb =================================================================== --- spec/ruby/library/rbconfig/rbconfig_spec.rb (revision 67360) +++ spec/ruby/library/rbconfig/rbconfig_spec.rb (revision 67361) @@ -10,7 +10,7 @@ describe 'RbConfig::CONFIG' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/rbconfig/rbconfig_spec.rb#L10 end # These directories have no meanings before the installation. - if RbConfig::TOPDIR + guard -> { RbConfig::TOPDIR } do it "['rubylibdir'] returns the directory containing Ruby standard libraries" do rubylibdir = RbConfig::CONFIG['rubylibdir'] File.directory?(rubylibdir).should == true Index: spec/ruby/shared/basicobject/send.rb =================================================================== --- spec/ruby/shared/basicobject/send.rb (revision 67360) +++ spec/ruby/shared/basicobject/send.rb (revision 67361) @@ -114,4 +114,15 @@ describe :basicobject_send, shared: true https://github.com/ruby/ruby/blob/trunk/spec/ruby/shared/basicobject/send.rb#L114 it "has a negative arity" do method(@method).arity.should < 0 end + + it "invokes module methods with super correctly" do + m1 = Module.new { def foo(ary); ary << :m1; end; } + m2 = Module.new { def foo(ary = []); super(ary); ary << :m2; end; } + c2 = Class.new do + include m1 + include m2 + end + + c2.new.send(@method, :foo, *[[]]).should == %i[m1 m2] + end end Index: spec/ruby/security/cve_2019_8321_spec.rb =================================================================== --- spec/ruby/security/cve_2019_8321_spec.rb (nonexistent) +++ spec/ruby/security/cve_2019_8321_spec.rb (revision 67361) @@ -0,0 +1,22 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/security/cve_2019_8321_spec.rb#L1 +require_relative '../spec_helper' + +require 'rubygems' +require 'rubygems/user_interaction' + +ruby_version_is "2.5.5" do + describe "CVE-2019-8321 is resisted by" do + it "sanitising verbose messages" do + ui = Class.new { + include Gem::UserInteraction + }.new + ui.should_receive(:say).with(".]2;nyan.") + verbose_before = Gem.configuration.verbose + begin + Gem.configuration.verbose = :really_verbose + ui.verbose("\e]2;nyan\a") + ensure + Gem.configuration.verbose = verbose_before + end + end + end +end Index: spec/ruby/security/cve_2019_8322_spec.rb =================================================================== --- spec/ruby/security/cve_2019_8322_spec.rb (nonexistent) +++ spec/ruby/security/cve_2019_8322_spec.rb (revision 67361) @@ -0,0 +1,23 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/security/cve_2019_8322_spec.rb#L1 +require_relative '../spec_helper' + +require 'yaml' +require 'rubygems' +require 'rubygems/safe_yaml' +require 'rubygems/commands/owner_command' + +ruby_version_is "2.5.5" do + describe "CVE-2019-8322 is resisted by" do + it "sanitising owner names" do + command = Gem::Commands::OwnerCommand.new + def command.rubygems_api_request(*args) + Struct.new(:body).new("---\n- email: \"\e]2;nyan\a\"\n handle: handle\n id: id\n") + end + def command.with_response(response) + yield response + end + command.should_receive(:say).with("Owners for gem: name") + command.should_receive(:say).with("- .]2;nyan.") + command.show_owners "name" + end + end +end Index: spec/ruby/security/cve_2019_8323_spec.rb =================================================================== --- spec/ruby/security/cve_2019_8323_spec.rb (nonexistent) +++ spec/ruby/security/cve_2019_8323_spec.rb (revision 67361) @@ -0,0 +1,38 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/security/cve_2019_8323_spec.rb#L1 +require_relative '../spec_helper' + +require 'optparse' + +require 'rubygems' +require 'rubygems/gemcutter_utilities' + +ruby_version_is "2.5.5" do + describe "CVE-2019-8323 is resisted by" do + describe "sanitising the body" do + it "for success codes" do + cutter = Class.new { + include Gem::GemcutterUtilities + }.new + response = Net::HTTPSuccess.new(nil, nil, nil) + def response.body + "\e]2;nyan\a" + end + cutter.should_receive(:say).with(".]2;nyan.") + cutter.with_response response + end + + it "for error codes" do + cutter = Class.new { + include Gem::GemcutterUtilities + }.new + def cutter.terminate_interaction(n) + end + response = Net::HTTPNotFound.new(nil, nil, nil) + def response.body + "\e]2;nyan\a" + end + cutter.should_receive(:say).with(".]2;nyan.") + cutter.with_response response + end + end + end +end Index: spec/ruby/security/cve_2019_8325_spec.rb =================================================================== --- spec/ruby/security/cve_2019_8325_spec.rb (nonexistent) +++ spec/ruby/security/cve_2019_8325_spec.rb (revision 67361) @@ -0,0 +1,38 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/security/cve_2019_8325_spec.rb#L1 +require_relative '../spec_helper' + +require 'rubygems' +require 'rubygems/command_manager' + +ruby_version_is "2.5.5" do + describe "CVE-2019-8325 is resisted by" do + describe "sanitising error message components" do + it "for the 'while executing' message" do + manager = Gem::CommandManager.new + def manager.process_args(args, build_args) + raise StandardError, "\e]2;nyan\a" + end + def manager.terminate_interaction(n) + end + manager.should_receive(:alert_error).with("While executing gem ... (StandardError)\n .]2;nyan.") + manager.run nil, nil + end + + it "for the 'invalid option' message" do + manager = Gem::CommandManager.new + def manager.terminate_interaction(n) + end + manager.should_receive(:alert_error).with("Invalid option: --.]2;nyan.. See 'gem --help'.") + manager.process_args ["--\e]2;nyan\a"], nil + end + + it "for the 'loading command' message" do + manager = Gem::CommandManager.new + def manager.require(x) + raise 'foo' + end + manager.should_receive(:alert_error).with("Loading command: .]2;nyan. (RuntimeError)\n\tfoo") + manager.send :load_and_instantiate, "\e]2;nyan\a" + end + end + end +end Index: spec/ruby/language/alias_spec.rb =================================================================== --- spec/ruby/language/alias_spec.rb (revision 67360) +++ spec/ruby/language/alias_spec.rb (revision 67361) @@ -244,3 +244,15 @@ describe "The alias keyword" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/alias_spec.rb#L244 } end end + +describe "The alias keyword" do + it "can create a new global variable, synonym of the original" do + code = '$a = 1; alias $b $a; p [$a, $b]; $b = 2; p [$a, $b]' + ruby_ (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/