Permalink
Browse files

Use the ruby from EnvUtil in the fileutils tests

  • Loading branch information...
1 parent 5955117 commit 526c595addee67dcb8c59c4dc790a6b7576eac2f @drbrain drbrain committed Jul 23, 2011
Showing with 31 additions and 33 deletions.
  1. +8 −0 test/helper.rb
  2. +22 −25 test/test_rake_file_utils.rb
  3. +1 −8 test/test_rake_functional.rb
View
8 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
View
47 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,15 +137,15 @@ 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
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
View
9 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

0 comments on commit 526c595

Please sign in to comment.