From 2a126b08a055ceacb6f540bd74e6d727f9d07883 Mon Sep 17 00:00:00 2001 From: kosaki Date: Sun, 22 May 2011 01:06:37 +0000 Subject: test cleanup git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_rubyoptions.rb | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 65b6c01031..69a7273f58 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -2,9 +2,26 @@ require 'test/unit' require 'tmpdir' require 'tempfile' +require 'pathname' + require_relative 'envutil' class TestRubyOptions < Test::Unit::TestCase + def write_file(filename, content) + File.open(filename, "w") {|f| + f << content + } + end + + def with_tmpchdir + Dir.mktmpdir {|d| + d = Pathname.new(d).realpath.to_s + Dir.chdir(d) { + yield d + } + } + end + def test_source_file assert_in_out_err([], "", [], []) end @@ -403,10 +420,15 @@ class TestRubyOptions < Test::Unit::TestCase def test_set_program_name skip if /linux|freebsd|netbsd|openbsd/ !~ RUBY_PLATFORM - pid = spawn([EnvUtil.rubybin, %!-e "$0 = 'hello world'; sleep 100"!]) - ps = `ps -p #{pid} -o command` - assert_match(/hello world/, ps) - Process.kill :KILL, pid + with_tmpchdir do + write_file("test-script", "$0 = 'hello world'; sleep 60") + + pid = spawn(EnvUtil.rubybin, "test-script") + sleep 0.1 + ps = `ps -p #{pid} -o command` + assert_match(/hello world/, ps) + Process.kill :KILL, pid + end end def test_segv_test -- cgit v1.2.3