ruby-changes:73769
From: Benoit <ko1@a...>
Date: Thu, 29 Sep 2022 01:38:48 +0900 (JST)
Subject: [ruby-changes:73769] 31cf1bb525 (master): Update to ruby/spec@1d9d5c6
https://git.ruby-lang.org/ruby.git/commit/?id=31cf1bb525 From 31cf1bb5256314b69eae92673d3dd5815158ee91 Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Wed, 28 Sep 2022 18:37:17 +0200 Subject: Update to ruby/spec@1d9d5c6 --- spec/ruby/.rubocop.yml | 3 + spec/ruby/core/basicobject/instance_eval_spec.rb | 68 ++++- spec/ruby/core/enumerable/sum_spec.rb | 17 +- spec/ruby/core/io/gets_spec.rb | 2 + spec/ruby/core/io/print_spec.rb | 25 +- spec/ruby/core/io/read_nonblock_spec.rb | 49 ++++ spec/ruby/core/io/read_spec.rb | 10 + spec/ruby/core/io/readchar_spec.rb | 66 +++++ spec/ruby/core/io/readpartial_spec.rb | 15 +- spec/ruby/core/io/rewind_spec.rb | 15 + spec/ruby/core/io/set_encoding_by_bom_spec.rb | 187 +++++++++++++ spec/ruby/core/io/set_encoding_spec.rb | 17 ++ spec/ruby/core/io/shared/each.rb | 22 ++ spec/ruby/core/io/shared/write.rb | 10 - spec/ruby/core/io/sysread_spec.rb | 31 ++- spec/ruby/core/io/syswrite_spec.rb | 10 + spec/ruby/core/io/write_nonblock_spec.rb | 10 + spec/ruby/core/io/write_spec.rb | 10 + spec/ruby/core/kernel/p_spec.rb | 6 +- spec/ruby/core/method/fixtures/classes.rb | 24 ++ spec/ruby/core/method/super_method_spec.rb | 28 ++ spec/ruby/core/module/const_defined_spec.rb | 7 +- spec/ruby/core/module/define_method_spec.rb | 43 ++- spec/ruby/core/module/fixtures/classes.rb | 8 + spec/ruby/core/module/included_modules_spec.rb | 2 + spec/ruby/core/module/instance_method_spec.rb | 34 ++- spec/ruby/core/module/shared/class_eval.rb | 21 +- spec/ruby/core/string/split_spec.rb | 26 ++ .../backtrace/location/absolute_path_spec.rb | 9 + .../fixtures/subdir/absolute_path_main_chdir.rb | 11 + .../backtrace/location/fixtures/subdir/sibling.rb | 1 + spec/ruby/core/unboundmethod/fixtures/classes.rb | 10 + spec/ruby/core/unboundmethod/hash_spec.rb | 7 + spec/ruby/core/unboundmethod/super_method_spec.rb | 25 ++ spec/ruby/fixtures/constants.rb | 11 + spec/ruby/language/precedence_spec.rb | 78 +++--- spec/ruby/language/predefined_spec.rb | 308 ++++++++++----------- spec/ruby/library/bigdecimal/exponent_spec.rb | 11 - spec/ruby/library/fiddle/handle/initialize_spec.rb | 10 + spec/ruby/library/io-wait/wait_readable_spec.rb | 25 ++ spec/ruby/library/io-wait/wait_writable_spec.rb | 18 ++ .../library/socket/addrinfo/initialize_spec.rb | 2 +- spec/ruby/library/socket/shared/pack_sockaddr.rb | 5 + spec/ruby/optional/capi/class_spec.rb | 4 + spec/ruby/optional/capi/ext/kernel_spec.c | 5 + spec/ruby/optional/capi/ext/object_spec.c | 13 + spec/ruby/optional/capi/fixtures/object.rb | 29 ++ spec/ruby/optional/capi/kernel_spec.rb | 19 ++ spec/ruby/optional/capi/object_spec.rb | 20 ++ spec/ruby/optional/capi/shared/rbasic.rb | 11 +- spec/ruby/spec_helper.rb | 3 +- 51 files changed, 1142 insertions(+), 259 deletions(-) create mode 100644 spec/ruby/core/thread/backtrace/location/fixtures/subdir/absolute_path_main_chdir.rb create mode 100644 spec/ruby/core/thread/backtrace/location/fixtures/subdir/sibling.rb create mode 100644 spec/ruby/library/fiddle/handle/initialize_spec.rb create mode 100644 spec/ruby/library/io-wait/wait_readable_spec.rb create mode 100644 spec/ruby/library/io-wait/wait_writable_spec.rb create mode 100644 spec/ruby/optional/capi/fixtures/object.rb diff --git a/spec/ruby/.rubocop.yml b/spec/ruby/.rubocop.yml index 1200e9d7ce..3a16fc43f8 100644 --- a/spec/ruby/.rubocop.yml +++ b/spec/ruby/.rubocop.yml @@ -161,6 +161,9 @@ Lint/Debugger: https://github.com/ruby/ruby/blob/trunk/spec/ruby/.rubocop.yml#L161 Lint/Loop: Enabled: false +Style/BlockComments: + Enabled: true + Style/Lambda: Enabled: true EnforcedStyle: literal diff --git a/spec/ruby/core/basicobject/instance_eval_spec.rb b/spec/ruby/core/basicobject/instance_eval_spec.rb index b6a146095d..350b08a30e 100644 --- a/spec/ruby/core/basicobject/instance_eval_spec.rb +++ b/spec/ruby/core/basicobject/instance_eval_spec.rb @@ -20,12 +20,18 @@ describe "BasicObject#instance_eval" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/basicobject/instance_eval_spec.rb#L20 a.instance_eval('self').equal?(a).should be_true end - it "expects a block with no arguments" do - -> { "hola".instance_eval }.should raise_error(ArgumentError) + it "raises an ArgumentError when no arguments and no block are given" do + -> { "hola".instance_eval }.should raise_error(ArgumentError, "wrong number of arguments (given 0, expected 1..3)") end - it "takes no arguments with a block" do - -> { "hola".instance_eval(4, 5) {|a,b| a + b } }.should raise_error(ArgumentError) + it "raises an ArgumentError when a block and normal arguments are given" do + -> { "hola".instance_eval(4, 5) {|a,b| a + b } }.should raise_error(ArgumentError, "wrong number of arguments (given 2, expected 0)") + end + + it "raises an ArgumentError when more than 3 arguments are given" do + -> { + "hola".instance_eval("1 + 1", "some file", 0, "bogus") + }.should raise_error(ArgumentError, "wrong number of arguments (given 4, expected 1..3)") end it "yields the object to the block" do @@ -185,4 +191,58 @@ end https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/basicobject/instance_eval_spec.rb#L191 x.should == :value end + + it "converts string argument with #to_str method" do + source_code = Object.new + def source_code.to_str() "1" end + + a = BasicObject.new + a.instance_eval(source_code).should == 1 + end + + it "raises ArgumentError if returned value is not String" do + source_code = Object.new + def source_code.to_str() :symbol end + + a = BasicObject.new + -> { a.instance_eval(source_code) }.should raise_error(TypeError, /can't convert Object to String/) + end + + it "converts filename argument with #to_str method" do + filename = Object.new + def filename.to_str() "file.rb" end + + err = begin + Object.new.instance_eval("raise", filename) + rescue => e + e + end + err.backtrace.first.split(":")[0].should == "file.rb" + end + + it "raises ArgumentError if returned value is not String" do + filename = Object.new + def filename.to_str() :symbol end + + -> { Object.new.instance_eval("raise", filename) }.should raise_error(TypeError, /can't convert Object to String/) + end + + it "converts lineno argument with #to_int method" do + lineno = Object.new + def lineno.to_int() 15 end + + err = begin + Object.new.instance_eval("raise", "file.rb", lineno) + rescue => e + e + end + err.backtrace.first.split(":")[1].should == "15" + end + + it "raises ArgumentError if returned value is not Integer" do + lineno = Object.new + def lineno.to_int() :symbol end + + -> { Object.new.instance_eval("raise", "file.rb", lineno) }.should raise_error(TypeError, /can't convert Object to Integer/) + end end diff --git a/spec/ruby/core/enumerable/sum_spec.rb b/spec/ruby/core/enumerable/sum_spec.rb index 4a978794e5..fc173e4173 100644 --- a/spec/ruby/core/enumerable/sum_spec.rb +++ b/spec/ruby/core/enumerable/sum_spec.rb @@ -22,8 +22,21 @@ describe 'Enumerable#sum' do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/enumerable/sum_spec.rb#L22 @enum.sum.should == 5/3r end - it 'takes a block to transform the elements' do - @enum.sum { |element| element * 2 }.should == 10/3r + context 'with a block' do + it 'transforms the elements' do + @enum.sum { |element| element * 2 }.should == 10/3r + end + + it 'does not destructure array elements' do + class << @enum + def each + yield [1,2] + yield [3] + end + end + + @enum.sum(&:last).should == 5 + end end # https://bugs.ruby-lang.org/issues/12217 diff --git a/spec/ruby/core/io/gets_spec.rb b/spec/ruby/core/io/gets_spec.rb index b9f82f8133..07be99f400 100644 --- a/spec/ruby/core/io/gets_spec.rb +++ b/spec/ruby/core/io/gets_spec.rb @@ -213,6 +213,8 @@ describe "IO#gets" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/gets_spec.rb#L213 it "returns empty string when 0 passed as a limit" do @io.gets(0).should == "" + @io.gets(nil, 0).should == "" + @io.gets("", 0).should == "" end end diff --git a/spec/ruby/core/io/print_spec.rb b/spec/ruby/core/io/print_spec.rb index 04e971ef6d..085852024c 100644 --- a/spec/ruby/core/io/print_spec.rb +++ b/spec/ruby/core/io/print_spec.rb @@ -3,16 +3,27 @@ require_relative 'fixtures/classes' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/print_spec.rb#L3 describe "IO#print" do before :each do - @old_separator = $\ - suppress_warning {$\ = '->'} + @old_record_separator = $\ + @old_field_separator = $, + suppress_warning { + $\ = '->' + $, = '^^' + } @name = tmp("io_print") end after :each do - suppress_warning {$\ = @old_separator} + suppress_warning { + $\ = @old_record_separator + $, = @old_field_separator + } rm_r @name end + it "returns nil" do + touch(@name) { |f| f.print.should be_nil } + end + it "writes $_.to_s followed by $\\ (if any) to the stream if no arguments given" do o = mock('o') o.should_receive(:to_s).and_return("mockmockmock") @@ -38,13 +49,15 @@ describe "IO#print" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/print_spec.rb#L49 IO.read(@name (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/