summaryrefslogtreecommitdiff
path: root/spec/ruby/core
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-30 00:05:56 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-30 00:05:56 +0000
commit7f54f1b5543b4a3267a64c47cff9127cbcafcc42 (patch)
treeb4321a0e6aca9aed1a05cfc97b9ca209a5e5a0fd /spec/ruby/core
parent2eee74ef54a2e23eb870680a83dcf74c5d9d9d01 (diff)
Update to ruby/spec@2d89e48
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66645 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core')
-rw-r--r--spec/ruby/core/dir/home_spec.rb43
-rw-r--r--spec/ruby/core/file/expand_path_spec.rb58
-rw-r--r--spec/ruby/core/process/setpriority_spec.rb46
-rw-r--r--spec/ruby/core/process/spawn_spec.rb86
4 files changed, 121 insertions, 112 deletions
diff --git a/spec/ruby/core/dir/home_spec.rb b/spec/ruby/core/dir/home_spec.rb
index 7e2256e1a1..db46b80c54 100644
--- a/spec/ruby/core/dir/home_spec.rb
+++ b/spec/ruby/core/dir/home_spec.rb
@@ -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']
- 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
diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb
index cbc3d34bdb..9ecd730a7b 100644
--- a/spec/ruby/core/file/expand_path_spec.rb
+++ b/spec/ruby/core/file/expand_path_spec.rb
@@ -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"]
diff --git a/spec/ruby/core/process/setpriority_spec.rb b/spec/ruby/core/process/setpriority_spec.rb
index 118482eb4e..4d60973429 100644
--- a/spec/ruby/core/process/setpriority_spec.rb
+++ b/spec/ruby/core/process/setpriority_spec.rb
@@ -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
diff --git a/spec/ruby/core/process/spawn_spec.rb b/spec/ruby/core/process/spawn_spec.rb
index a583e24737..951941888b 100644
--- a/spec/ruby/core/process/spawn_spec.rb
+++ b/spec/ruby/core/process/spawn_spec.rb
@@ -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
- 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
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