From f35c3a54986f13821cffe0e9c9b41a4335b1e642 Mon Sep 17 00:00:00 2001 From: eregon Date: Mon, 29 May 2017 17:56:46 +0000 Subject: Clean up a bit the Process.setpriority specs git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/rubyspec/core/process/fixtures/setpriority.rb | 12 +++++++ spec/rubyspec/core/process/setpriority_spec.rb | 37 +++++++--------------- 2 files changed, 24 insertions(+), 25 deletions(-) create mode 100644 spec/rubyspec/core/process/fixtures/setpriority.rb (limited to 'spec/rubyspec') diff --git a/spec/rubyspec/core/process/fixtures/setpriority.rb b/spec/rubyspec/core/process/fixtures/setpriority.rb new file mode 100644 index 0000000000..cf22d85b12 --- /dev/null +++ b/spec/rubyspec/core/process/fixtures/setpriority.rb @@ -0,0 +1,12 @@ +case ARGV[0] +when "process" + which = Process::PRIO_PROCESS +when "group" + Process.setpgrp + which = Process::PRIO_PGRP +end + +priority = Process.getpriority(which, 0) +p priority +p Process.setpriority(which, 0, priority + 1) +p Process.getpriority(which, 0) diff --git a/spec/rubyspec/core/process/setpriority_spec.rb b/spec/rubyspec/core/process/setpriority_spec.rb index f80b289322..7b437a547a 100644 --- a/spec/rubyspec/core/process/setpriority_spec.rb +++ b/spec/rubyspec/core/process/setpriority_spec.rb @@ -4,18 +4,12 @@ describe "Process.setpriority" do platform_is_not :windows do it "sets the scheduling priority for a specified process" do priority = Process.getpriority(Process::PRIO_PROCESS, 0) - IO.popen('-') do |f| - if f - pr = Integer(f.gets) - Integer(f.gets).should == 0 - Integer(f.gets).should == (pr+1) - else - pr = Process.getpriority(Process::PRIO_PROCESS, 0) - p pr - p Process.setpriority(Process::PRIO_PROCESS, 0, (pr + 1)) - p Process.getpriority(Process::PRIO_PROCESS, 0) - end - end + + out = ruby_exe(fixture(__FILE__, "setpriority.rb"), args: "process") + out = out.lines.map { |l| Integer(l) } + pr = out[0] + out.should == [pr, 0, pr+1] + Process.getpriority(Process::PRIO_PROCESS, 0).should == priority end @@ -24,19 +18,12 @@ describe "Process.setpriority" do platform_is_not :darwin, :freebsd do it "sets the scheduling priority for a specified process group" do priority = Process.getpriority(Process::PRIO_PGRP, 0) - IO.popen('-') do |f| - if f - pr = Integer(f.gets) - Integer(f.gets).should == 0 - Integer(f.gets).should == (pr+1) - else - Process.setpgrp - pr = Process.getpriority(Process::PRIO_PGRP, 0) - p pr - p Process.setpriority(Process::PRIO_PGRP, 0, pr + 1) - p Process.getpriority(Process::PRIO_PGRP, 0) - end - end + + out = ruby_exe(fixture(__FILE__, "setpriority.rb"), args: "group") + out = out.lines.map { |l| Integer(l) } + pr = out[0] + out.should == [pr, 0, pr+1] + Process.getpriority(Process::PRIO_PGRP, 0).should == priority end end -- cgit v1.2.3