Skip to content

Commit

Permalink
Use the ruby from EnvUtil in the fileutils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Jul 23, 2011
1 parent 5955117 commit 526c595
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
8 changes: 8 additions & 0 deletions test/helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
require 'tmpdir' require 'tmpdir'
require File.expand_path('../file_creation', __FILE__) require File.expand_path('../file_creation', __FILE__)


begin
require 'test/ruby/envutil'
rescue LoadError
# for ruby trunk
end

class Rake::TestCase < MiniTest::Unit::TestCase class Rake::TestCase < MiniTest::Unit::TestCase
include FileCreation include FileCreation


Expand All @@ -19,6 +25,8 @@ class TaskManager
include Rake::TaskManager include Rake::TaskManager
end end


RUBY = defined?(EnvUtil) ? EnvUtil.rubybin : Gem.ruby

def setup def setup
ARGV.clear ARGV.clear


Expand Down
47 changes: 22 additions & 25 deletions test/test_rake_file_utils.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -119,33 +119,16 @@ def test_fileutils_methods_dont_leak
def test_sh def test_sh
shellcommand shellcommand


verbose(false) { sh %{#{FileUtils::RUBY} shellcommand.rb} } verbose(false) { sh %{#{Rake::TestCase::RUBY} shellcommand.rb} }
assert true, "should not fail" assert true, "should not fail"
end 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 def test_sh_with_a_single_string_argument
check_expansion check_expansion


ENV['RAKE_TEST_SH'] = 'someval' ENV['RAKE_TEST_SH'] = 'someval'
verbose(false) { verbose(false) {
sh %{#{FileUtils::RUBY} check_expansion.rb #{env_var} someval} sh %{#{RUBY} check_expansion.rb #{env_var} someval}
} }
end end


Expand All @@ -154,15 +137,15 @@ def test_sh_with_multiple_arguments
ENV['RAKE_TEST_SH'] = 'someval' ENV['RAKE_TEST_SH'] = 'someval'


verbose(false) { verbose(false) {
Sh.ruby 'check_no_expansion.rb', env_var, 'someval' sh RUBY, 'check_no_expansion.rb', env_var, 'someval'
} }
end end


def test_sh_failure def test_sh_failure
shellcommand shellcommand


assert_raises(RuntimeError) { assert_raises(RuntimeError) {
verbose(false) { Sh.run %{#{FileUtils::RUBY} shellcommand.rb 1} } verbose(false) { sh %{#{RUBY} shellcommand.rb 1} }
} }
end end


Expand All @@ -171,12 +154,12 @@ def test_sh_special_handling


count = 0 count = 0
verbose(false) { verbose(false) {
sh(%{#{FileUtils::RUBY} shellcommand.rb}) do |ok, res| sh(%{#{RUBY} shellcommand.rb}) do |ok, res|
assert(ok) assert(ok)
assert_equal 0, res.exitstatus assert_equal 0, res.exitstatus
count += 1 count += 1
end end
sh(%{#{FileUtils::RUBY} shellcommand.rb 1}) do |ok, res| sh(%{#{RUBY} shellcommand.rb 1}) do |ok, res|
assert(!ok) assert(!ok)
assert_equal 1, res.exitstatus assert_equal 1, res.exitstatus
count += 1 count += 1
Expand Down Expand Up @@ -241,7 +224,9 @@ def test_ruby_with_a_single_string_argument
ENV['RAKE_TEST_SH'] = 'someval' ENV['RAKE_TEST_SH'] = 'someval'


verbose(false) { verbose(false) {
ruby %{check_expansion.rb #{env_var} someval} replace_ruby {
ruby %{check_expansion.rb #{env_var} someval}
}
} }
end end


Expand All @@ -250,7 +235,9 @@ def test_ruby_with_multiple_arguments


ENV['RAKE_TEST_SH'] = 'someval' ENV['RAKE_TEST_SH'] = 'someval'
verbose(false) { verbose(false) {
ruby 'check_no_expansion.rb', env_var, 'someval' replace_ruby {
ruby 'check_no_expansion.rb', env_var, 'someval'
}
} }
end end


Expand Down Expand Up @@ -289,6 +276,16 @@ def check_expansion
CHECK_EXPANSION CHECK_EXPANSION
end 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 def shellcommand
command 'shellcommand.rb', <<-SHELLCOMMAND command 'shellcommand.rb', <<-SHELLCOMMAND
#!/usr/bin/env ruby #!/usr/bin/env ruby
Expand Down
9 changes: 1 addition & 8 deletions test/test_rake_functional.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
require 'fileutils' require 'fileutils'
require 'open3' require 'open3'


begin
require 'test/ruby/envutil'
rescue LoadError
# for ruby trunk
end

class TestRakeFunctional < Rake::TestCase class TestRakeFunctional < Rake::TestCase


def setup def setup
Expand Down Expand Up @@ -440,8 +434,7 @@ def rake(*rake_options)


# Low level ruby command runner ... # Low level ruby command runner ...
def run_ruby(option_list) 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, out, err, wait = Open3.popen3(Gem.ruby, *option_list)
inn.close inn.close
Expand Down

0 comments on commit 526c595

Please sign in to comment.