ruby-changes:34668
From: nobu <ko1@a...>
Date: Mon, 7 Jul 2014 17:43:04 +0900 (JST)
Subject: [ruby-changes:34668] nobu:r46751 (trunk): test/ruby/find_executable.rb
nobu 2014-07-07 17:42:57 +0900 (Mon, 07 Jul 2014) New Revision: 46751 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46751 Log: 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. Added files: trunk/test/ruby/find_executable.rb Modified files: trunk/test/ruby/envutil.rb trunk/test/ruby/test_rubyoptions.rb Index: test/ruby/find_executable.rb =================================================================== --- test/ruby/find_executable.rb (revision 0) +++ test/ruby/find_executable.rb (revision 46751) @@ -0,0 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/find_executable.rb#L1 +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 Property changes on: test/ruby/find_executable.rb ___________________________________________________________________ Added: svn:eol-style + LF Index: test/ruby/envutil.rb =================================================================== --- test/ruby/envutil.rb (revision 46750) +++ test/ruby/envutil.rb (revision 46751) @@ -2,6 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/envutil.rb#L2 require "open3" require "timeout" require "test/unit" +require_relative "find_executable" module EnvUtil def rubybin Index: test/ruby/test_rubyoptions.rb =================================================================== --- test/ruby/test_rubyoptions.rb (revision 46750) +++ test/ruby/test_rubyoptions.rb (revision 46751) @@ -458,8 +458,13 @@ class TestRubyOptions < Test::Unit::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L458 } 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::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L473 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::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L483 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::Test https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rubyoptions.rb#L492 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/