From a560c2086ad3f9177541119ae487dcae3ffb2b87 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 7 Jul 2014 08:42:57 +0000 Subject: test/ruby/find_executable.rb * test/ruby/test_rubyoptions.rb (test_program_name): use expected ps command from PATH. * test/ruby/find_executable.rb (EnvUtil#find_executable): find expected executable path with argument and output pattern. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/envutil.rb | 1 + test/ruby/find_executable.rb | 19 +++++++++++++++++++ test/ruby/test_rubyoptions.rb | 13 +++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 test/ruby/find_executable.rb (limited to 'test/ruby') diff --git a/test/ruby/envutil.rb b/test/ruby/envutil.rb index 3924d5d323..6ba77de053 100644 --- a/test/ruby/envutil.rb +++ b/test/ruby/envutil.rb @@ -2,6 +2,7 @@ require "open3" require "timeout" require "test/unit" +require_relative "find_executable" module EnvUtil def rubybin diff --git a/test/ruby/find_executable.rb b/test/ruby/find_executable.rb new file mode 100644 index 0000000000..86595342a4 --- /dev/null +++ b/test/ruby/find_executable.rb @@ -0,0 +1,19 @@ +module EnvUtil + def find_executable(cmd, *args) + exts = RbConfig::CONFIG["EXECUTABLE_EXTS"].split | [RbConfig::CONFIG["EXEEXT"]] + ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| + next if path.empty? + path = File.join(path, cmd) + exts.each do |ext| + cmdline = [path + ext, *args] + begin + return cmdline if yield(IO.popen(cmdline, "r", err: [:child, :out], &:read)) + rescue + next + end + end + end + nil + end + module_function :find_executable +end diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 6816d19937..22bbcf02ed 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -458,8 +458,13 @@ class TestRubyOptions < Test::Unit::TestCase } end + if /linux|freebsd|netbsd|openbsd|darwin/ =~ RUBY_PLATFORM + PSCMD = EnvUtil.find_executable("ps", "-o", "command", "-p", $$.to_s) {|out| /ruby/=~out} + PSCMD.pop if PSCMD + end + def test_set_program_name - skip "platform dependent feature" if /linux|freebsd|netbsd|openbsd|darwin/ !~ RUBY_PLATFORM + skip "platform dependent feature" unless defined?(PSCMD) and PSCMD with_tmpchdir do write_file("test-script", "$0 = 'hello world'; /test-script/ =~ Process.argv0 or $0 = 'Process.argv0 changed!'; sleep 60") @@ -468,7 +473,7 @@ class TestRubyOptions < Test::Unit::TestCase ps = nil 10.times do sleep 0.1 - ps = `ps -p #{pid} -o command` + ps = `#{PSCMD.join(' ')} #{pid}` break if /hello world/ =~ ps end assert_match(/hello world/, ps) @@ -478,7 +483,7 @@ class TestRubyOptions < Test::Unit::TestCase end def test_setproctitle - skip "platform dependent feature" if /linux|freebsd|netbsd|openbsd|darwin/ !~ RUBY_PLATFORM + skip "platform dependent feature" unless defined?(PSCMD) and PSCMD with_tmpchdir do write_file("test-script", "$_0 = $0.dup; Process.setproctitle('hello world'); $0 == $_0 or Process.setproctitle('$0 changed!'); sleep 60") @@ -487,7 +492,7 @@ class TestRubyOptions < Test::Unit::TestCase ps = nil 10.times do sleep 0.1 - ps = `ps -p #{pid} -o command` + ps = `#{PSCMD.join(' ')} #{pid}` break if /hello world/ =~ ps end assert_match(/hello world/, ps) -- cgit v1.2.3