1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2018-12-30 00:05:56 +00:00
parent 2eee74ef54
commit 7f54f1b554
5 changed files with 138 additions and 119 deletions

View file

@ -28,12 +28,22 @@ ruby/spec is known to be tested in these implementations for every commit:
* [TruffleRuby](https://github.com/oracle/truffleruby/tree/master/spec/ruby)
* [Opal](https://github.com/opal/opal/tree/master/spec)
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.
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).
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 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.
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 the executable named `ruby` on your curren
### 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

View file

@ -2,27 +2,40 @@ require_relative '../../spec_helper'
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']
before :each do
@home = ENV['HOME']
ENV['HOME'] = "/rubyspec_home"
end
after :each do
ENV['HOME'] = @home
end
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
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
home_directory = home_directory.tr('\\', '/').chomp('/')
end
Dir.home.should == home_directory
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
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
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
it "returns a non-frozen string" do
Dir.home(ENV['USER']).frozen?.should == false
end
end

View file

@ -56,40 +56,10 @@ describe "File.expand_path" do
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
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"]

View file

@ -29,28 +29,32 @@ describe "Process.setpriority" do
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

View file

@ -7,27 +7,25 @@ platform_is :windows do
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 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 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 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
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
end
end
end
it_should_behave_like :process_spawn_does_not_close_std_streams
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 }
end
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
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
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