aboutsummaryrefslogtreecommitdiffstats
path: root/spec/rubyspec/core/process
diff options
context:
space:
mode:
Diffstat (limited to 'spec/rubyspec/core/process')
-rw-r--r--spec/rubyspec/core/process/fixtures/common.rb20
-rw-r--r--spec/rubyspec/core/process/fixtures/env.rb1
-rw-r--r--spec/rubyspec/core/process/fixtures/print.rb1
-rw-r--r--spec/rubyspec/core/process/kill_spec.rb48
-rw-r--r--spec/rubyspec/core/process/spawn_spec.rb84
-rw-r--r--spec/rubyspec/core/process/wait_spec.rb3
6 files changed, 76 insertions, 81 deletions
diff --git a/spec/rubyspec/core/process/fixtures/common.rb b/spec/rubyspec/core/process/fixtures/common.rb
index 046efa5396..bdbf1e654b 100644
--- a/spec/rubyspec/core/process/fixtures/common.rb
+++ b/spec/rubyspec/core/process/fixtures/common.rb
@@ -1,4 +1,17 @@
module ProcessSpecs
+ def self.use_system_ruby(context)
+ if defined?(MSpecScript::SYSTEM_RUBY)
+ context.send(:before, :all) do
+ @ruby = ::RUBY_EXE
+ Object.const_set(:RUBY_EXE, MSpecScript::SYSTEM_RUBY)
+ end
+
+ context.send(:after, :all) do
+ Object.const_set(:RUBY_EXE, @ruby)
+ end
+ end
+ end
+
class Daemonizer
attr_reader :input, :data
@@ -55,13 +68,6 @@ module ProcessSpecs
end
def wait_on_result
- # Ensure the process exits
- begin
- Process.kill :TERM, pid if pid
- rescue Errno::ESRCH
- # Ignore the process not existing
- end
-
@thread.join
end
diff --git a/spec/rubyspec/core/process/fixtures/env.rb b/spec/rubyspec/core/process/fixtures/env.rb
deleted file mode 100644
index 2d626caf26..0000000000
--- a/spec/rubyspec/core/process/fixtures/env.rb
+++ /dev/null
@@ -1 +0,0 @@
-File.write ARGV[0], ENV["FOO"]
diff --git a/spec/rubyspec/core/process/fixtures/print.rb b/spec/rubyspec/core/process/fixtures/print.rb
deleted file mode 100644
index 3697f7dc93..0000000000
--- a/spec/rubyspec/core/process/fixtures/print.rb
+++ /dev/null
@@ -1 +0,0 @@
-print :glark
diff --git a/spec/rubyspec/core/process/kill_spec.rb b/spec/rubyspec/core/process/kill_spec.rb
index c7b0e2a129..4316daf374 100644
--- a/spec/rubyspec/core/process/kill_spec.rb
+++ b/spec/rubyspec/core/process/kill_spec.rb
@@ -2,6 +2,8 @@ require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/common', __FILE__)
describe "Process.kill" do
+ ProcessSpecs.use_system_ruby(self)
+
before :each do
@pid = Process.pid
end
@@ -22,7 +24,7 @@ describe "Process.kill" do
end
it "raises Errno::ESRCH if the process does not exist" do
- pid = Process.spawn(ruby_cmd("sleep 10"))
+ pid = Process.spawn(*ruby_exe, "-e", "sleep 10")
Process.kill("SIGKILL", pid)
Process.wait(pid)
lambda {
@@ -33,6 +35,8 @@ end
platform_is_not :windows do
describe "Process.kill" do
+ ProcessSpecs.use_system_ruby(self)
+
before :each do
@sp = ProcessSpecs::Signalizer.new
end
@@ -73,6 +77,8 @@ platform_is_not :windows do
end
describe "Process.kill" do
+ ProcessSpecs.use_system_ruby(self)
+
before :each do
@sp1 = ProcessSpecs::Signalizer.new
@sp2 = ProcessSpecs::Signalizer.new
@@ -95,57 +101,27 @@ platform_is_not :windows do
end
describe "Process.kill" do
- before :each do
- @sp = ProcessSpecs::Signalizer.new "self"
- end
-
after :each do
- @sp.cleanup
+ @sp.cleanup if @sp
end
it "signals the process group if the PID is zero" do
+ @sp = ProcessSpecs::Signalizer.new "self"
@sp.result.should == "signaled"
end
- end
-
- describe "Process.kill" do
- before :each do
- @sp = ProcessSpecs::Signalizer.new "group_numeric"
- end
-
- after :each do
- @sp.cleanup
- end
it "signals the process group if the signal number is negative" do
+ @sp = ProcessSpecs::Signalizer.new "group_numeric"
@sp.result.should == "signaled"
end
- end
-
- describe "Process.kill" do
- before :each do
- @sp = ProcessSpecs::Signalizer.new "group_short_string"
- end
-
- after :each do
- @sp.cleanup
- end
it "signals the process group if the short signal name starts with a minus sign" do
+ @sp = ProcessSpecs::Signalizer.new "group_short_string"
@sp.result.should == "signaled"
end
- end
-
- describe "Process.kill" do
- before :each do
- @sp = ProcessSpecs::Signalizer.new "group_full_string"
- end
-
- after :each do
- @sp.cleanup
- end
it "signals the process group if the full signal name starts with a minus sign" do
+ @sp = ProcessSpecs::Signalizer.new "group_full_string"
@sp.result.should == "signaled"
end
end
diff --git a/spec/rubyspec/core/process/spawn_spec.rb b/spec/rubyspec/core/process/spawn_spec.rb
index 66b5c5e402..330ec8fcd8 100644
--- a/spec/rubyspec/core/process/spawn_spec.rb
+++ b/spec/rubyspec/core/process/spawn_spec.rb
@@ -1,4 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/common', __FILE__)
newline = "\n"
platform_is :windows do
@@ -31,8 +32,14 @@ describe :process_spawn_does_not_close_std_streams, shared: true do
end
describe "Process.spawn" do
+ ProcessSpecs.use_system_ruby(self)
+
before :each do
@name = tmp("process_spawn.txt")
+ @var = "$FOO"
+ platform_is :windows do
+ @var = "%FOO%"
+ end
end
after :each do
@@ -44,14 +51,14 @@ describe "Process.spawn" do
end
it "returns the process ID of the new process as a Fixnum" do
- pid = Process.spawn(ruby_cmd("exit"))
+ pid = Process.spawn(*ruby_exe, "-e", "exit")
Process.wait pid
pid.should be_an_instance_of(Fixnum)
end
it "returns immediately" do
start = Time.now
- pid = Process.spawn(ruby_cmd("sleep 10"))
+ pid = Process.spawn(*ruby_exe, "-e", "sleep 10")
(Time.now - start).should < 5
Process.kill :KILL, pid
Process.wait pid
@@ -196,52 +203,57 @@ describe "Process.spawn" do
end
it "sets environment variables in the child environment" do
- Process.wait Process.spawn({"FOO" => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
- File.read(@name).should == "BAR"
+ Process.wait Process.spawn({"FOO" => "BAR"}, "echo #{@var}>#{@name}")
+ File.read(@name).should == "BAR\n"
end
it "unsets environment variables whose value is nil" do
ENV["FOO"] = "BAR"
- Process.wait Process.spawn({"FOO" => nil}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
- File.read(@name).should == ""
+ Process.wait Process.spawn({"FOO" => nil}, "echo #{@var}>#{@name}")
+ expected = "\n"
+ platform_is :windows do
+ # Windows does not expand the variable if it is unset
+ expected = "#{@var}\n"
+ end
+ File.read(@name).should == expected
end
it "calls #to_hash to convert the environment" do
o = mock("to_hash")
o.should_receive(:to_hash).and_return({"FOO" => "BAR"})
- Process.wait Process.spawn(o, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
- File.read(@name).should == "BAR"
+ Process.wait Process.spawn(o, "echo #{@var}>#{@name}")
+ File.read(@name).should == "BAR\n"
end
it "calls #to_str to convert the environment keys" do
o = mock("to_str")
o.should_receive(:to_str).and_return("FOO")
- Process.wait Process.spawn({o => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
- File.read(@name).should == "BAR"
+ Process.wait Process.spawn({o => "BAR"}, "echo #{@var}>#{@name}")
+ File.read(@name).should == "BAR\n"
end
it "calls #to_str to convert the environment values" do
o = mock("to_str")
o.should_receive(:to_str).and_return("BAR")
- Process.wait Process.spawn({"FOO" => o}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
- File.read(@name).should == "BAR"
+ Process.wait Process.spawn({"FOO" => o}, "echo #{@var}>#{@name}")
+ File.read(@name).should == "BAR\n"
end
it "raises an ArgumentError if an environment key includes an equals sign" do
lambda do
- Process.spawn({"FOO=" => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
+ Process.spawn({"FOO=" => "BAR"}, "echo #{@var}>#{@name}")
end.should raise_error(ArgumentError)
end
it "raises an ArgumentError if an environment key includes a null byte" do
lambda do
- Process.spawn({"\000" => "BAR"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
+ Process.spawn({"\000" => "BAR"}, "echo #{@var}>#{@name}")
end.should raise_error(ArgumentError)
end
it "raises an ArgumentError if an environment value includes a null byte" do
lambda do
- Process.spawn({"FOO" => "\000"}, ruby_cmd(fixture(__FILE__, "env.rb"), args: @name))
+ Process.spawn({"FOO" => "\000"}, "echo #{@var}>#{@name}")
end.should raise_error(ArgumentError)
end
@@ -252,7 +264,7 @@ describe "Process.spawn" do
"PATH" => ENV["PATH"],
"HOME" => ENV["HOME"]
}
- @common_env_spawn_args = [@minimal_env, ruby_cmd(fixture(__FILE__, "env.rb"), options: "--disable-gems", args: @name)]
+ @common_env_spawn_args = [@minimal_env, "echo #{@var}>#{@name}"]
end
platform_is_not :windows do
@@ -260,7 +272,7 @@ describe "Process.spawn" do
ENV["FOO"] = "BAR"
Process.wait Process.spawn(*@common_env_spawn_args, unsetenv_others: true)
$?.success?.should be_true
- File.read(@name).should == ""
+ File.read(@name).should == "\n"
end
end
@@ -268,15 +280,15 @@ describe "Process.spawn" do
ENV["FOO"] = "BAR"
Process.wait Process.spawn(*@common_env_spawn_args, unsetenv_others: false)
$?.success?.should be_true
- File.read(@name).should == "BAR"
+ File.read(@name).should == "BAR\n"
end
platform_is_not :windows do
it "does not unset environment variables included in the environment hash" do
env = @minimal_env.merge({"FOO" => "BAR"})
- Process.wait Process.spawn(env, ruby_cmd(fixture(__FILE__, "env.rb"), options: "--disable-gems", args: @name), unsetenv_others: true)
+ Process.wait Process.spawn(env, "echo #{@var}>#{@name}", unsetenv_others: true)
$?.success?.should be_true
- File.read(@name).should == "BAR"
+ File.read(@name).should == "BAR\n"
end
end
@@ -400,55 +412,55 @@ describe "Process.spawn" do
it "redirects STDOUT to the given file descriptior if out: Fixnum" do
File.open(@name, 'w') do |file|
lambda do
- Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: file.fileno)
- end.should output_to_fd("glark", file)
+ Process.wait Process.spawn("echo glark", out: file.fileno)
+ end.should output_to_fd("glark\n", file)
end
end
it "redirects STDOUT to the given file if out: IO" do
File.open(@name, 'w') do |file|
lambda do
- Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: file)
- end.should output_to_fd("glark", file)
+ Process.wait Process.spawn("echo glark", out: file)
+ end.should output_to_fd("glark\n", file)
end
end
it "redirects STDOUT to the given file if out: String" do
- Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: @name)
- File.read(@name).should == "glark"
+ Process.wait Process.spawn("echo glark", out: @name)
+ File.read(@name).should == "glark\n"
end
it "redirects STDOUT to the given file if out: [String name, String mode]" do
- Process.wait Process.spawn(ruby_cmd(fixture(__FILE__, "print.rb")), out: [@name, 'w'])
- File.read(@name).should == "glark"
+ Process.wait Process.spawn("echo glark", out: [@name, 'w'])
+ File.read(@name).should == "glark\n"
end
it "redirects STDERR to the given file descriptior if err: Fixnum" do
File.open(@name, 'w') do |file|
lambda do
- Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), err: file.fileno)
- end.should output_to_fd("glark", file)
+ Process.wait Process.spawn("echo glark>&2", err: file.fileno)
+ end.should output_to_fd("glark\n", file)
end
end
it "redirects STDERR to the given file descriptor if err: IO" do
File.open(@name, 'w') do |file|
lambda do
- Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), err: file)
- end.should output_to_fd("glark", file)
+ Process.wait Process.spawn("echo glark>&2", err: file)
+ end.should output_to_fd("glark\n", file)
end
end
it "redirects STDERR to the given file if err: String" do
- Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), err: @name)
- File.read(@name).should == "glark"
+ Process.wait Process.spawn("echo glark>&2", err: @name)
+ File.read(@name).should == "glark\n"
end
it "redirects STDERR to child STDOUT if :err => [:child, :out]" do
File.open(@name, 'w') do |file|
lambda do
- Process.wait Process.spawn(ruby_cmd("STDERR.print :glark"), :out => file, :err => [:child, :out])
- end.should output_to_fd("glark", file)
+ Process.wait Process.spawn("echo glark>&2", :out => file, :err => [:child, :out])
+ end.should output_to_fd("glark\n", file)
end
end
diff --git a/spec/rubyspec/core/process/wait_spec.rb b/spec/rubyspec/core/process/wait_spec.rb
index dca43140fd..8111621695 100644
--- a/spec/rubyspec/core/process/wait_spec.rb
+++ b/spec/rubyspec/core/process/wait_spec.rb
@@ -1,6 +1,9 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/common', __FILE__)
describe "Process.wait" do
+ ProcessSpecs.use_system_ruby(self)
+
before :all do
begin
leaked = Process.waitall