From 498324c5d3cd08c2c306a4f91e3a11b7fda22835 Mon Sep 17 00:00:00 2001 From: mame Date: Tue, 1 Jul 2008 12:33:11 +0000 Subject: [PATCH] * lib/test/unit/ui/console/testrunner.rb: prevent destructive modification to $0. * test/rubygems/gemutilities.rb (build_rake_in): move from test_gem_ext_rake_builder.rb. * test/rubygems/test_gem_ext_rake_builder.rb: ditto. * test/rubygems/test_gem_installer.rb: override Gem.ruby and ENV["rake"]. * test/rubygems/test_gem_uninstaller.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17780 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 16 ++++++++ lib/test/unit/ui/console/testrunner.rb | 6 +-- test/rubygems/gemutilities.rb | 45 ++++++++++++++++++++++ test/rubygems/test_gem_ext_rake_builder.rb | 35 +++++------------ test/rubygems/test_gem_installer.rb | 30 +++++++++------ test/rubygems/test_gem_uninstaller.rb | 6 ++- 6 files changed, 95 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe5e34cd47..3234836be3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +Tue Jul 1 21:32:43 2008 Yusuke Endoh + + * lib/test/unit/ui/console/testrunner.rb: prevent destructive + modification to $0. + + * test/rubygems/gemutilities.rb (build_rake_in): move from + test_gem_ext_rake_builder.rb. + + * test/rubygems/test_gem_ext_rake_builder.rb: ditto. + + * test/rubygems/test_gem_installer.rb: override Gem.ruby and + ENV["rake"]. + + * test/rubygems/test_gem_uninstaller.rb: ditto. + + Tue Jul 1 21:13:17 2008 Koichi Sasada * compile.c, vm.c, insns.def: call FrozenCore.set_postexe method diff --git a/lib/test/unit/ui/console/testrunner.rb b/lib/test/unit/ui/console/testrunner.rb index 1495300463..b6475c0037 100644 --- a/lib/test/unit/ui/console/testrunner.rb +++ b/lib/test/unit/ui/console/testrunner.rb @@ -90,10 +90,8 @@ module Test end def test_started(name) - unless defined? $program_name - $program_name = $0 - alias $0 $program_name - end + $program_name = $0 + alias $0 $program_name $PROGRAM_NAME += "\0#{name}" output_single(name + ": ", VERBOSE) end diff --git a/test/rubygems/gemutilities.rb b/test/rubygems/gemutilities.rb index c84b94a5e5..0ab2c5272c 100644 --- a/test/rubygems/gemutilities.rb +++ b/test/rubygems/gemutilities.rb @@ -392,5 +392,50 @@ class RubyGemTestCase < Test::Unit::TestCase self.class.process_based_port end + def build_rake_in + gem_ruby = Gem.ruby + ruby = @@ruby + Gem.module_eval {@ruby = ruby} + env_rake = ENV["rake"] + ENV["rake"] = @@rake + yield @@rake + ensure + Gem.module_eval {@ruby = gem_ruby} + if env_rake + ENV["rake"] = env_rake + else + ENV.delete("rake") + end + end + + def self.rubybin + if ruby = ENV["RUBY"] + return ruby + end + ruby = "ruby" + rubyexe = ruby+".exe" + 3.times do + if File.exist? ruby and File.executable? ruby and !File.directory? ruby + return File.expand_path(ruby) + end + if File.exist? rubyexe and File.executable? rubyexe + return File.expand_path(rubyexe) + end + ruby = File.join("..", ruby) + end + begin + require "rbconfig" + File.join( + RbConfig::CONFIG["bindir"], + RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"] + ) + rescue LoadError + "ruby" + end + end + + @@ruby = rubybin + @@rake = ENV["rake"] || (@@ruby + " " + File.expand_path("../../../bin/rake", __FILE__)) + end diff --git a/test/rubygems/test_gem_ext_rake_builder.rb b/test/rubygems/test_gem_ext_rake_builder.rb index 6bc3ea08eb..6d9184e804 100644 --- a/test/rubygems/test_gem_ext_rake_builder.rb +++ b/test/rubygems/test_gem_ext_rake_builder.rb @@ -3,9 +3,6 @@ require File.join(File.expand_path(File.dirname(__FILE__)), 'gemutilities') require 'rubygems/ext' class TestGemExtRakeBuilder < RubyGemTestCase - @@ruby = ENV["RUBY"] - @@rake = ENV["rake"] || (@@ruby + " " + File.expand_path("../../../bin/rake", __FILE__)) - def setup super @@ -16,24 +13,6 @@ class TestGemExtRakeBuilder < RubyGemTestCase FileUtils.mkdir_p @dest_path end - def build_rake_in dir - gem_ruby = Gem.ruby - ruby = @@ruby - Gem.module_eval {@ruby = ruby} - env_rake = ENV["rake"] - ENV["rake"] = @@rake - Dir.chdir dir do - yield @@rake - end - ensure - Gem.module_eval {@ruby = gem_ruby} - if env_rake - ENV["rake"] = env_rake - else - ENV.delete("rake") - end - end - def test_class_build File.open File.join(@ext, 'mkrf_conf.rb'), 'w' do |mkrf_conf| mkrf_conf.puts <<-EO_MKRF @@ -46,9 +25,11 @@ class TestGemExtRakeBuilder < RubyGemTestCase output = [] realdir = nil # HACK /tmp vs. /private/tmp - build_rake_in @ext do - realdir = Dir.pwd - Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', nil, @dest_path, output + build_rake_in do + Dir.chdir @ext do + realdir = Dir.pwd + Gem::Ext::RakeBuilder.build 'mkrf_conf.rb', nil, @dest_path, output + end end expected = [ @@ -73,8 +54,10 @@ class TestGemExtRakeBuilder < RubyGemTestCase output = [] error = assert_raise Gem::InstallError do - build_rake_in @ext do - Gem::Ext::RakeBuilder.build "mkrf_conf.rb", nil, @dest_path, output + build_rake_in do + Dir.chdir @ext do + Gem::Ext::RakeBuilder.build "mkrf_conf.rb", nil, @dest_path, output + end end end diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index a2547abedb..eb9743dd42 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -529,8 +529,10 @@ load 'my_exec' Dir.mkdir util_inst_bindir util_setup_gem - use_ui @ui do - assert_equal @spec, @installer.install + build_rake_in do + use_ui @ui do + assert_equal @spec, @installer.install + end end gemdir = File.join @gemhome, 'gems', @spec.full_name @@ -600,8 +602,10 @@ load 'my_exec' util_setup_gem @installer.ignore_dependencies = true - use_ui @ui do - assert_equal @spec, @installer.install + build_rake_in do + use_ui @ui do + assert_equal @spec, @installer.install + end end gemdir = File.join @gemhome, 'gems', @spec.full_name @@ -646,9 +650,11 @@ load 'my_exec' install_dir = File.join @userhome, '.gem', 'gems', @spec.full_name @spec.executables = ["executable"] - use_ui @ui do - util_setup_gem - @installer.install + build_rake_in do + use_ui @ui do + util_setup_gem + @installer.install + end end assert File.exist?(File.join(install_dir, 'lib', 'code.rb')) @@ -663,10 +669,12 @@ load 'my_exec' File.chmod 0755, @userhome File.chmod 0000, util_inst_bindir - use_ui @ui do - setup - util_setup_gem - @installer.install + build_rake_in do + use_ui @ui do + setup + util_setup_gem + @installer.install + end end assert File.exist?(File.join(@userhome, '.gem', 'bin', 'executable')) diff --git a/test/rubygems/test_gem_uninstaller.rb b/test/rubygems/test_gem_uninstaller.rb index aadf0a39c8..7d7890c3ea 100644 --- a/test/rubygems/test_gem_uninstaller.rb +++ b/test/rubygems/test_gem_uninstaller.rb @@ -10,8 +10,10 @@ class TestGemUninstaller < GemInstallerTestCase ui = MockGemUi.new util_setup_gem ui - use_ui ui do - @installer.install + build_rake_in do + use_ui ui do + @installer.install + end end end