[前][次][番号順一覧][スレッド一覧]

ruby-changes:71320

From: Benoit <ko1@a...>
Date: Thu, 3 Mar 2022 22:43:55 +0900 (JST)
Subject: [ruby-changes:71320] 3b21818db1 (master): Update to ruby/spec@82cd3a3

https://git.ruby-lang.org/ruby.git/commit/?id=3b21818db1

From 3b21818db1fac0c22f16364eab2d8cc0067abd63 Mon Sep 17 00:00:00 2001
From: Benoit Daloze <eregontp@g...>
Date: Thu, 3 Mar 2022 14:43:14 +0100
Subject: Update to ruby/spec@82cd3a3

---
 spec/ruby/.mspec.constants                        |  1 +
 spec/ruby/core/array/each_spec.rb                 | 35 +++++++++++++++--
 spec/ruby/core/dir/fixtures/common.rb             | 18 +++++++++
 spec/ruby/core/dir/glob_spec.rb                   | 25 ++++++++++++
 spec/ruby/core/dir/read_spec.rb                   | 14 +++----
 spec/ruby/core/exception/interrupt_spec.rb        |  9 +++++
 spec/ruby/core/io/close_spec.rb                   |  6 +++
 spec/ruby/core/rational/minus_spec.rb             | 48 ++++++++++++++++++++++-
 spec/ruby/core/string/shared/to_sym.rb            |  9 +++++
 spec/ruby/core/thread/report_on_exception_spec.rb | 21 ++++++++++
 spec/ruby/language/file_spec.rb                   | 12 +-----
 spec/ruby/language/predefined_spec.rb             | 10 +++++
 spec/ruby/optional/capi/ext/object_spec.c         |  6 ++-
 spec/ruby/optional/capi/object_spec.rb            | 19 +++++++++
 spec/ruby/optional/capi/string_spec.rb            |  4 +-
 spec/ruby/shared/rational/minus.rb                | 48 -----------------------
 16 files changed, 213 insertions(+), 72 deletions(-)
 delete mode 100644 spec/ruby/shared/rational/minus.rb

diff --git a/spec/ruby/.mspec.constants b/spec/ruby/.mspec.constants
index 6b70274c52..c070e35496 100644
--- a/spec/ruby/.mspec.constants
+++ b/spec/ruby/.mspec.constants
@@ -73,6 +73,7 @@ EvalBindingProcA https://github.com/ruby/ruby/blob/trunk/spec/ruby/.mspec.constants#L73
 Exception2MessageMapper
 ExceptionForMatrix
 Fcntl
+Fiddle
 FileStat
 FileUtils
 Find
diff --git a/spec/ruby/core/array/each_spec.rb b/spec/ruby/core/array/each_spec.rb
index 256647d61e..cf8e9da6d8 100644
--- a/spec/ruby/core/array/each_spec.rb
+++ b/spec/ruby/core/array/each_spec.rb
@@ -3,9 +3,10 @@ require_relative 'fixtures/classes' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/each_spec.rb#L3
 require_relative 'shared/enumeratorize'
 require_relative '../enumerable/shared/enumeratorized'
 
-# Modifying a collection while the contents are being iterated
-# gives undefined behavior. See
-# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
+# Mutating the array while it is being iterated is discouraged as it can result in confusing behavior.
+# Yet a Ruby implementation must not crash in such a case, and following the simple CRuby behavior makes sense.
+# CRuby simply reads the array storage and checks the size for every iteration;
+# like `i = 0; while i < size; yield self[i]; end`
 
 describe "Array#each" do
   it "yields each element to the block" do
@@ -15,6 +16,34 @@ describe "Array#each" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/array/each_spec.rb#L16
     a.should == [1, 2, 3]
   end
 
+  it "yields each element to the block even if the array is changed during iteration" do
+    a = [1, 2, 3, 4, 5]
+    iterated = []
+    a.each { |x| iterated << x; a << x+5 if x.even? }
+    iterated.should == [1, 2, 3, 4, 5, 7, 9]
+  end
+
+  it "yields only elements that are still in the array" do
+    a = [0, 1, 2, 3, 4]
+    iterated = []
+    a.each { |x| iterated << x; a.pop if x.even? }
+    iterated.should == [0, 1, 2]
+  end
+
+  it "yields elements based on an internal index" do
+    a = [0, 1, 2, 3, 4]
+    iterated = []
+    a.each { |x| iterated << x; a.shift if x.even? }
+    iterated.should == [0, 2, 4]
+  end
+
+  it "yields the same element multiple times if inserting while iterating" do
+    a = [1, 2]
+    iterated = []
+    a.each { |x| iterated << x; a.unshift(0) if a.size == 2 }
+    iterated.should == [1, 1, 2]
+  end
+
   it "yields each element to a block that takes multiple arguments" do
     a = [[1, 2], :a, [3, 4]]
     b = []
diff --git a/spec/ruby/core/dir/fixtures/common.rb b/spec/ruby/core/dir/fixtures/common.rb
index 637fe93e2f..a8d6e69c44 100644
--- a/spec/ruby/core/dir/fixtures/common.rb
+++ b/spec/ruby/core/dir/fixtures/common.rb
@@ -101,12 +101,30 @@ module DirSpecs https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/dir/fixtures/common.rb#L101
     @mock_dir_files
   end
 
+  def self.mock_dir_links
+    unless @mock_dir_links
+      @mock_dir_links = []
+      platform_is_not :windows do
+        @mock_dir_links += [
+          ['special/ln', 'subdir_one']
+        ]
+      end
+    end
+    @mock_dir_links
+  end
+
   def self.create_mock_dirs
     mock_dir_files.each do |name|
       file = File.join mock_dir, name
       mkdir_p File.dirname(file)
       touch file
     end
+    mock_dir_links.each do |link, target|
+      full_link = File.join mock_dir, link
+      full_target = File.join mock_dir, target
+
+      File.symlink full_target, full_link
+    end
   end
 
   def self.delete_mock_dirs
diff --git a/spec/ruby/core/dir/glob_spec.rb b/spec/ruby/core/dir/glob_spec.rb
index 295a7ab920..43dac73eee 100644
--- a/spec/ruby/core/dir/glob_spec.rb
+++ b/spec/ruby/core/dir/glob_spec.rb
@@ -222,5 +222,30 @@ describe "Dir.glob" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/dir/glob_spec.rb#L222
         Dir.rmdir('no_permission')
       end
     end
+
+    it "will follow symlinks when processing a `*/` pattern." do
+      expected = ['special/ln/nondotfile']
+      Dir.glob('special/*/nondotfile').should == expected
+    end
+
+    it "will not follow symlinks when recursively traversing directories" do
+      expected = %w[
+        deeply/nondotfile
+        nondotfile
+        subdir_one/nondotfile
+        subdir_two/nondotfile
+      ]
+      Dir.glob('**/nondotfile').sort.should == expected
+    end
+
+    it "will follow symlinks when testing directory after recursive directory in pattern" do
+      expected = %w[
+        deeply/nondotfile
+        special/ln/nondotfile
+        subdir_one/nondotfile
+        subdir_two/nondotfile
+      ]
+      Dir.glob('**/*/nondotfile').sort.should == expected
+    end
   end
 end
diff --git a/spec/ruby/core/dir/read_spec.rb b/spec/ruby/core/dir/read_spec.rb
index 2953aad72f..276930c6b7 100644
--- a/spec/ruby/core/dir/read_spec.rb
+++ b/spec/ruby/core/dir/read_spec.rb
@@ -54,16 +54,16 @@ describe "Dir#read" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/dir/read_spec.rb#L54
       old_external_encoding = Encoding::default_external
       Encoding.default_internal = Encoding::UTF_8
       Encoding.default_external = Encoding::SHIFT_JIS
-      dir = Dir.open(File.join(DirSpecs.mock_dir, 'special'))
       shift_jis_entries = []
       begin
-        -> {
-          while entry = dir.read
-            shift_jis_entries << entry
-          end
-        }.should_not raise_error
+        Dir.open(File.join(DirSpecs.mock_dir, 'special')) do |d|
+          -> {
+            while entry = d.read
+              shift_jis_entries << entry
+            end
+          }.should_not raise_error
+        end
       ensure
-        dir.close
         Encoding.default_internal = old_internal_encoding
         Encoding.default_external = old_external_encoding
       end
diff --git a/spec/ruby/core/exception/interrupt_spec.rb b/spec/ruby/core/exception/interrupt_spec.rb
index a7501efadc..299b5b81f3 100644
--- a/spec/ruby/core/exception/interrupt_spec.rb
+++ b/spec/ruby/core/exception/interrupt_spec.rb
@@ -48,4 +48,13 @@ describe "Interrupt" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/exception/interrupt_spec.rb#L48
     RUBY
     out.should == "Interrupt: #{Signal.list["INT"]}\n"
   end
+
+  platform_is_not :windows do
+    it "shows the backtrace and has a signaled exit status" do
+      err = IO.popen([*ruby_exe, '-e', 'Process.kill :INT, Process.pid; sleep'], err: [:child, :out], &:read)
+      $?.termsig.should == Signal.list.fetch('INT')
+      err.should.include? ': Interrupt'
+      err.should.include? "from -e:1:in `<main>'"
+    end
+  end
 end
diff --git a/spec/ruby/core/io/close_spec.rb b/spec/ruby/core/io/close_spec.rb
index eb560eaf67..3a44cc8b17 100644
--- a/spec/ruby/core/io/close_spec.rb
+++ b/spec/ruby/core/io/close_spec.rb
@@ -44,6 +44,12 @@ describe "IO#close" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/io/close_spec.rb#L44
     @io.close.should be_nil
   end
 
+  it "does not call the #flush method but flushes the stream internally" do
+    @io.should_not_receive(:flush)
+    @io.close
+    @io.should.closed?
+  end
+
   it 'raises an IOError with a clear message' do
     matching_exception = nil
 
diff --git a/spec/ruby/core/rational/minus_spec.rb b/spec/ruby/core/rational/minus_spec.rb
index 9e0f81556b..a61b62ebe6 100644
--- a/spec/ruby/core/rational/minus_spec.rb
+++ b/spec/ruby/core/rational/minus_spec.rb
@@ -1,7 +1,51 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/rational/minus_spec.rb#L1
-require_relative '../../shared/rational/minus'
+require_relative '../../spec_helper'
 require_relative '../../shared/rational/arithmetic_exception_in_coerce'
 
 describe "Rational#-" do
-  it_behaves_like :rational_minus, :-
   it_behaves_like :rational_arithmetic_exception_in_coerce, :-
+
+  it "calls #coerce on the passed argument with self" do
+    rational = Rational(3, 4)
+    obj = mock("Object")
+    obj.should_receive(:coerce).with(rational).and_return([1, 2])
+
+    rational - obj
+  end
+
+  it "calls #- on the coerced Rational with the coerced Object" do
+    rational = Rational(3, 4)
+
+    coerced_rational = mock("Coerced Rational")
+    coerced_rational.should_receive(:-).and_return(:result)
+
+    coerced_obj = mock("Coerced Object")
+
+    obj = mock("Object")
+    obj.should_receive(:coerce).and_return([coerced_rational, coerced_obj])
+
+    (rational - obj).should == :result
+  end
+end
+
+describe "Rational#- passed a Rational" do
+  it "returns the result of subtracting other from self as a Rational" do
+    (Rational(3, 4) - Rational(0, 1)).should eql(Rational(3, 4))
+    (Rational(3, 4) - Rational(1, 4)).should  (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]