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

ruby-changes:54430

From: eregon <ko1@a...>
Date: Sun, 30 Dec 2018 09:06:01 +0900 (JST)
Subject: [ruby-changes:54430] eregon:r66645 (trunk): Update to ruby/spec@2d89e48

eregon	2018-12-30 09:05:56 +0900 (Sun, 30 Dec 2018)

  New Revision: 66645

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66645

  Log:
    Update to ruby/spec@2d89e48

  Modified files:
    trunk/spec/ruby/README.md
    trunk/spec/ruby/core/dir/home_spec.rb
    trunk/spec/ruby/core/file/expand_path_spec.rb
    trunk/spec/ruby/core/process/setpriority_spec.rb
    trunk/spec/ruby/core/process/spawn_spec.rb
Index: spec/ruby/core/process/spawn_spec.rb
===================================================================
--- spec/ruby/core/process/spawn_spec.rb	(revision 66644)
+++ spec/ruby/core/process/spawn_spec.rb	(revision 66645)
@@ -7,27 +7,25 @@ platform_is :windows do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/process/spawn_spec.rb#L7
 end
 
 describe :process_spawn_does_not_close_std_streams, shared: true do
-  platform_is_not :windows do
-    it "does not close STDIN" do
-      code = "STDOUT.puts STDIN.read(0).inspect"
-      cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
-      ruby_exe(cmd, args: "> #{@name}")
-      File.binread(@name).should == %[""#{newline}]
-    end
-
-    it "does not close STDOUT" do
-      code = "STDOUT.puts 'hello'"
-      cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
-      ruby_exe(cmd, args: "> #{@name}")
-      File.binread(@name).should == "hello#{newline}"
-    end
-
-    it "does not close STDERR" do
-      code = "STDERR.puts 'hello'"
-      cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
-      ruby_exe(cmd, args: "2> #{@name}")
-      File.binread(@name).should =~ /hello#{newline}/
-    end
+  it "does not close STDIN" do
+    code = "STDOUT.puts STDIN.read(0).inspect"
+    cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
+    ruby_exe(cmd, args: "> #{@name}")
+    File.binread(@name).should == %[""#{newline}]
+  end
+
+  it "does not close STDOUT" do
+    code = "STDOUT.puts 'hello'"
+    cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
+    ruby_exe(cmd, args: "> #{@name}")
+    File.binread(@name).should == "hello#{newline}"
+  end
+
+  it "does not close STDERR" do
+    code = "STDERR.puts 'hello'"
+    cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
+    ruby_exe(cmd, args: "2> #{@name}")
+    File.binread(@name).should =~ /hello#{newline}/
   end
 end
 
@@ -532,12 +530,12 @@ describe "Process.spawn" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/process/spawn_spec.rb#L530
     File.read(@name).should == "glarkbang"
   end
 
-  context "when passed close_others: true" do
-    before :each do
-      @options = { close_others: true }
-    end
+  platform_is_not :windows do
+    context "when passed close_others: true" do
+      before :each do
+        @options = { close_others: true }
+      end
 
-    platform_is_not :windows do
       it "closes file descriptors >= 3 in the child process even if fds are set close_on_exec=false" do
         touch @name
         IO.pipe do |r, w|
@@ -554,31 +552,29 @@ describe "Process.spawn" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/process/spawn_spec.rb#L552
           end
         end
       end
-    end
 
-    it_should_behave_like :process_spawn_does_not_close_std_streams
-  end
-
-  context "when passed close_others: false" do
-    before :each do
-      @options = { close_others: false }
+      it_should_behave_like :process_spawn_does_not_close_std_streams
     end
 
-    it "closes file descriptors >= 3 in the child process because they are set close_on_exec by default" do
-      touch @name
-      IO.pipe do |r, w|
-        begin
-          pid = Process.spawn(ruby_cmd("while File.exist? '#{@name}'; sleep 0.1; end"), @options)
-          w.close
-          r.read(1).should == nil
-        ensure
-          rm_r @name
-          Process.wait(pid) if pid
+    context "when passed close_others: false" do
+      before :each do
+        @options = { close_others: false }
+      end
+
+      it "closes file descriptors >= 3 in the child process because they are set close_on_exec by default" do
+        touch @name
+        IO.pipe do |r, w|
+          begin
+            pid = Process.spawn(ruby_cmd("while File.exist? '#{@name}'; sleep 0.1; end"), @options)
+            w.close
+            r.read(1).should == nil
+          ensure
+            rm_r @name
+            Process.wait(pid) if pid
+          end
         end
       end
-    end
 
-    platform_is_not :windows do
       it "does not close file descriptors >= 3 in the child process if fds are set close_on_exec=false" do
         IO.pipe do |r, w|
           r.close_on_exec = false
@@ -594,9 +590,9 @@ describe "Process.spawn" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/process/spawn_spec.rb#L590
           end
         end
       end
-    end
 
-    it_should_behave_like :process_spawn_does_not_close_std_streams
+      it_should_behave_like :process_spawn_does_not_close_std_streams
+    end
   end
 
   # error handling
Index: spec/ruby/core/process/setpriority_spec.rb
===================================================================
--- spec/ruby/core/process/setpriority_spec.rb	(revision 66644)
+++ spec/ruby/core/process/setpriority_spec.rb	(revision 66645)
@@ -29,28 +29,32 @@ describe "Process.setpriority" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/process/setpriority_spec.rb#L29
     end
 
     as_superuser do
-      p = Process.getpriority(Process::PRIO_USER, 0)
-      # The nice value is a value in the range -20 to 19.
-      # This test tries to change the nice value to +-1, so it cannot run if p == -20 || p == 19.
-      if -20 < p && p < 19
-       begin
-         # Check if we can lower the nice value or not.
-         #
-         # We are not always able to do it even as a root.
-         # Docker container is not always able to do it depending upon the configuration,
-         # which cannot know from the container itself.
-          Process.setpriority(Process::PRIO_USER, 0, p - 1)
-          Process.setpriority(Process::PRIO_USER, 0, p)
-
-          it "sets the scheduling priority for a specified user" do
-            Process.setpriority(Process::PRIO_USER, 0, p + 1).should == 0
-            Process.getpriority(Process::PRIO_USER, 0).should == (p + 1)
-            Process.setpriority(Process::PRIO_USER, 0, p).should == 0
-         end
-       rescue Errno::EACCES
-       end
+      guard -> {
+        prio = Process.getpriority(Process::PRIO_USER, 0)
+        # The nice value is a value in the range -20 to 19.
+        # This test tries to change the nice value to +-1, so it cannot run if prio == -20 || prio == 19.
+        if -20 < prio && prio < 19
+          begin
+            # Check if we can lower the nice value or not.
+            #
+            # We are not always able to do it even as a root.
+            # Docker container is not always able to do it depending upon the configuration,
+            # which cannot know from the container itself.
+            Process.setpriority(Process::PRIO_USER, 0, prio - 1)
+            Process.setpriority(Process::PRIO_USER, 0, prio)
+            true
+          rescue Errno::EACCES
+            false
+          end
+        end
+      } do
+        it "sets the scheduling priority for a specified user" do
+          prio = Process.getpriority(Process::PRIO_USER, 0)
+          Process.setpriority(Process::PRIO_USER, 0, prio + 1).should == 0
+          Process.getpriority(Process::PRIO_USER, 0).should == (prio + 1)
+          Process.setpriority(Process::PRIO_USER, 0, prio).should == 0
+        end
       end
     end
   end
-
 end
Index: spec/ruby/core/dir/home_spec.rb
===================================================================
--- spec/ruby/core/dir/home_spec.rb	(revision 66644)
+++ spec/ruby/core/dir/home_spec.rb	(revision 66645)
@@ -2,27 +2,40 @@ require_relative '../../spec_helper' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/dir/home_spec.rb#L2
 require_relative 'fixtures/common'
 
 describe "Dir.home" do
-  it "returns the current user's home directory as a string if called without arguments" do
-    home_directory = ENV['HOME']
-    platform_is :windows do
-      unless home_directory
-        home_directory = ENV['HOMEDRIVE'] + ENV['HOMEPATH']
-      end
-      home_directory = home_directory.tr('\\', '/').chomp('/')
-    end
+  before :each do
+    @home = ENV['HOME']
+    ENV['HOME'] = "/rubyspec_home"
+  end
 
-    Dir.home.should == home_directory
+  after :each do
+    ENV['HOME'] = @home
   end
 
-  platform_is :solaris do
-    it "returns the named user's home directory, from the user database, as a string if called with an argument" do
-      Dir.home(ENV['USER']).should == `getent passwd #{ENV['USER']}|cut -d: -f6`.chomp
+  describe "when called without arguments" do
+    it "returns the current user's home directory, reading $HOME first" do
+      Dir.home.should == "/rubyspec_home"
+    end
+
+    it "returns a non-frozen string" do
+      Dir.home.frozen?.should == false
     end
   end
 
-  platform_is_not :windows, :solaris do
-    it "returns the named user's home directory, from the user database, as a string if called with an argument" do
-      Dir.home(ENV['USER']).should == `echo ~#{ENV['USER']}`.chomp
+  describe "when called with the current user name" do
+    platform_is :solaris do
+      it "returns the named user's home directory from the user database" do
+        Dir.home(ENV['USER']).should == `getent passwd #{ENV['USER']}|cut -d: -f6`.chomp
+      end
+    end
+
+    platform_is_not :windows, :solaris do
+      it "returns the named user's home directory, from the user database" do
+        Dir.home(ENV['USER']).should == `echo ~#{ENV['USER']}`.chomp
+      end
+    end
+
+    it "returns a non-frozen string" do
+      Dir.home(ENV['USER']).frozen?.should == false
     end
   end
 
Index: spec/ruby/core/file/expand_path_spec.rb
===================================================================
--- spec/ruby/core/file/expand_path_spec.rb	(revision 66644)
+++ spec/ruby/core/file/expand_path_spec.rb	(revision 66645)
@@ -56,40 +56,10 @@ describe "File.expand_path" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/expand_path_spec.rb#L56
     File.expand_path(".", "#{@rootdir}").should == "#{@rootdir}"
   end
 
-  # FIXME: do not use conditionals like this around #it blocks
-  unless not home = ENV['HOME']
-    platform_is_not :windows do
-      it "converts a pathname to an absolute pathname, using ~ (home) as base" do
-        File.expand_path('~').should == home
-        File.expand_path('~', '/tmp/gumby/ddd').should == home
-        File.expand_path('~/a', '/tmp/gumby/ddd').should == File.join(home, 'a')
-      end
-
-      it "does not return a frozen string" do
-        File.expand_path('~').frozen?.should == false
-        File.expand_path('~', '/tmp/gumby/ddd').frozen?.should == false
-        File.expand_path('~/a', '/tmp/gumby/ddd').frozen?.should == false
-      end
-    end
-    platform_is :windows do
-      it "converts a pathname to an absolute pathname, using ~ (home) as base" do
-        File.expand_path('~').should == home.tr("\\", '/')
-        File.expand_path('~', '/tmp/gumby/ddd').should == home.tr("\\", '/')
-        File.expand_path('~/a', '/tmp/gumby/ddd').should == File.join(home.tr("\\", '/'), 'a')
-      end
-
-      it "does not return a frozen string" do
-        File.expand_path('~').frozen?.should == false
-        File.expand_path('~', '/tmp/gumby/ddd').frozen?.should == false
-        File.expand_path('~/a', '/tmp/gumby/ddd').frozen?.should == false
-      end
-    end
-  end
-
   platform_is_not :windows do
     before do
       @var_home = ENV['HOME'].chomp('/')
-      @db_home = Dir.home
+      @db_home = Dir.home(ENV['USER'])
     end
 
     # FIXME: these are insane!
@@ -217,6 +187,32 @@ describe "File.expand_path" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/expand_path_spec.rb#L187
 end
 
 platform_is_not :windows do
+  describe "File.expand_path when HOME is set" do
+    before :each do
+      @home = ENV["HOME"]
+      ENV["HOME"] = "/rubyspec_home"
+    end
+
+    after :each do
+      ENV["HOME"] = @home
+    end
+
+    it "converts a pathname to an absolute pathname, using ~ (home) as base" do
+      home = "/rubyspec_home"
+      File.expand_path('~').should == home
+      File.expand_path('~', '/tmp/gumby/ddd').should == home
+      File.expand_path('~/a', '/tmp/gumby/ddd').should == File.join(home, 'a')
+    end
+
+    it "does not return a frozen string" do
+      home = "/rubyspec_home"
+      File.expand_path('~').frozen?.should == false
+      File.expand_path('~', '/tmp/gumby/ddd').frozen?.should == false
+      File.expand_path('~/a', '/tmp/gumby/ddd').frozen?.should == false
+    end
+  end
+
+
   describe "File.expand_path when HOME is not set" do
     before :each do
       @home = ENV["HOME"]
Index: spec/ruby/README.md
===================================================================
--- spec/ruby/README.md	(revision 66644)
+++ spec/ruby/README.md	(revision 66645)
@@ -28,12 +28,22 @@ ruby/spec is known to be tested in these https://github.com/ruby/ruby/blob/trunk/spec/ruby/README.md#L28
 * [TruffleRuby](https://github.com/oracle/truffleruby/tree/master/spec/ruby)
 * [Opal](https://github.com/opal/opal/tree/master/spec)
 
+ruby/spec describes the behavior of Ruby 2.3 and more recent Ruby versions.
+More precisely, every latest stable MRI release should [pass](https://travis-ci.org/ruby/spec) all specs of ruby/spec (2.3.x, 2.4.x, 2.5.x, 2.6.x, etc), and those are tested in TravisCI.
+
 The specs are synchronized both ways around once a month by @eregon between ruby/spec, MRI, JRuby and TruffleRuby.
-Each of these repositories has a full copy of the files to ease editing specs.
+Each of these repositories has a full copy of the specs under `spec/ruby` to ease editing specs.
+Any of these repositories can be used to add or edit specs, use what is most convenient for you.
 
-ruby/spec describes the behavior of Ruby 2.3 and more recent Ruby versions.
-More precisely, every latest stable MRI release [passes](https://rubyci.org/) all specs of ruby/spec
-(2.3.x, 2.4.x, 2.5.x, etc).
+For *testing* a Ruby implementation, one should always test against the implementation's copy of the specs under `spec/ruby`, as that's what the Ruby implementation tests against in their CI.
+Also, this repository doesn't always contain the latest spec changes from MRI (it's synchronized monthly), and does not contain tags (specs marked as failing on that Ruby implementation).
+Running specs in a Ruby implementation can be done with:
+
+```
+$ cd ruby_implementation/spec/ruby
+# Add ../ruby_implementation/bin in PATH, or pass -t /path/to/bin/ruby
+$ ../mspec/bin/mspec
+```
 
 For older specs try these commits:
 * Ruby 2.0.0-p647 - [Suite](https://github.com/ruby/spec/commit/245862558761d5abc676843ef74f86c9bcc8ea8d) using [MSpec](https://github.com/ruby/mspec/commit/f90efa068791064f955de7a843e96e2d7d3041c2) (may encounter 2 failures)
@@ -63,7 +73,7 @@ This will execute all the specs using th https://github.com/ruby/ruby/blob/trunk/spec/ruby/README.md#L73
 ### Running Specs with a Specific Ruby Implementation
 
 Use the `-t` option to specify the Ruby implementation with which to run the specs.
-The argument may be a full path to the Ruby binary.
+The argument is either a full path to the Ruby binary, or an executable in `$PATH`.
 
     $ ../mspec/bin/mspec -t /path/to/some/bin/ruby
 

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

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