diff --git a/test/helper.rb b/test/helper.rb index 78bd528dc..4d8c8185b 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -10,6 +10,12 @@ require 'tmpdir' require File.expand_path('../file_creation', __FILE__) +begin + require 'test/ruby/envutil' +rescue LoadError + # for ruby trunk +end + class Rake::TestCase < MiniTest::Unit::TestCase include FileCreation @@ -19,6 +25,8 @@ class TaskManager include Rake::TaskManager end + RUBY = defined?(EnvUtil) ? EnvUtil.rubybin : Gem.ruby + def setup ARGV.clear diff --git a/test/test_rake_file_utils.rb b/test/test_rake_file_utils.rb index 0f5ad3e7a..90565e3eb 100644 --- a/test/test_rake_file_utils.rb +++ b/test/test_rake_file_utils.rb @@ -119,33 +119,16 @@ def test_fileutils_methods_dont_leak def test_sh shellcommand - verbose(false) { sh %{#{FileUtils::RUBY} shellcommand.rb} } + verbose(false) { sh %{#{Rake::TestCase::RUBY} shellcommand.rb} } assert true, "should not fail" end - # If the :sh method is invoked directly from a test unit instance - # (under mini/test), the mini/test version of fail is invoked rather - # than the kernel version of fail. So we run :sh from within a - # non-test class to avoid the problem. - class Sh - include FileUtils - def run(*args) - sh(*args) - end - def self.run(*args) - new.run(*args) - end - def self.ruby(*args) - Sh.run(RUBY, *args) - end - end - def test_sh_with_a_single_string_argument check_expansion ENV['RAKE_TEST_SH'] = 'someval' verbose(false) { - sh %{#{FileUtils::RUBY} check_expansion.rb #{env_var} someval} + sh %{#{RUBY} check_expansion.rb #{env_var} someval} } end @@ -154,7 +137,7 @@ def test_sh_with_multiple_arguments ENV['RAKE_TEST_SH'] = 'someval' verbose(false) { - Sh.ruby 'check_no_expansion.rb', env_var, 'someval' + sh RUBY, 'check_no_expansion.rb', env_var, 'someval' } end @@ -162,7 +145,7 @@ def test_sh_failure shellcommand assert_raises(RuntimeError) { - verbose(false) { Sh.run %{#{FileUtils::RUBY} shellcommand.rb 1} } + verbose(false) { sh %{#{RUBY} shellcommand.rb 1} } } end @@ -171,12 +154,12 @@ def test_sh_special_handling count = 0 verbose(false) { - sh(%{#{FileUtils::RUBY} shellcommand.rb}) do |ok, res| + sh(%{#{RUBY} shellcommand.rb}) do |ok, res| assert(ok) assert_equal 0, res.exitstatus count += 1 end - sh(%{#{FileUtils::RUBY} shellcommand.rb 1}) do |ok, res| + sh(%{#{RUBY} shellcommand.rb 1}) do |ok, res| assert(!ok) assert_equal 1, res.exitstatus count += 1 @@ -241,7 +224,9 @@ def test_ruby_with_a_single_string_argument ENV['RAKE_TEST_SH'] = 'someval' verbose(false) { - ruby %{check_expansion.rb #{env_var} someval} + replace_ruby { + ruby %{check_expansion.rb #{env_var} someval} + } } end @@ -250,7 +235,9 @@ def test_ruby_with_multiple_arguments ENV['RAKE_TEST_SH'] = 'someval' verbose(false) { - ruby 'check_no_expansion.rb', env_var, 'someval' + replace_ruby { + ruby 'check_no_expansion.rb', env_var, 'someval' + } } end @@ -289,6 +276,16 @@ def check_expansion CHECK_EXPANSION end + def replace_ruby + ruby = FileUtils::RUBY + FileUtils.send :remove_const, :RUBY + FileUtils.const_set :RUBY, RUBY + yield + ensure + FileUtils.send :remove_const, :RUBY + FileUtils.const_set:RUBY, ruby + end + def shellcommand command 'shellcommand.rb', <<-SHELLCOMMAND #!/usr/bin/env ruby diff --git a/test/test_rake_functional.rb b/test/test_rake_functional.rb index fe248f707..9b3afedc4 100644 --- a/test/test_rake_functional.rb +++ b/test/test_rake_functional.rb @@ -2,12 +2,6 @@ require 'fileutils' require 'open3' -begin - require 'test/ruby/envutil' -rescue LoadError - # for ruby trunk -end - class TestRakeFunctional < Rake::TestCase def setup @@ -440,8 +434,7 @@ def rake(*rake_options) # Low level ruby command runner ... def run_ruby(option_list) - ruby = defined?(EnvUtil) ? EnvUtil.rubybin : Gem.ruby - puts "COMMAND: [#{ruby} #{option_list.join ' '}]" if @verbose + puts "COMMAND: [#{RUBY} #{option_list.join ' '}]" if @verbose inn, out, err, wait = Open3.popen3(Gem.ruby, *option_list) inn.close