Skip to content

Commit

Permalink
Don't use PWD to load libraries
Browse files Browse the repository at this point in the history
This allows rake tests to be run from outside the source directory.
  • Loading branch information
drbrain committed Nov 29, 2012
1 parent b9df816 commit 7f9edaf
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
13 changes: 13 additions & 0 deletions test/helper.rb
Expand Up @@ -31,6 +31,19 @@ class TaskManager
def setup
ARGV.clear

test_dir = File.basename File.dirname File.expand_path __FILE__

@rake_root = if test_dir == 'test' then
# rake repository
File.expand_path '../../', __FILE__
else
# ruby repository
File.expand_path '../../../', __FILE__
end

@rake_exec = File.join @rake_root, 'bin', 'rake'
@rake_lib = File.join @rake_root, 'lib'

@orig_PWD = Dir.pwd
@orig_APPDATA = ENV['APPDATA']
@orig_HOME = ENV['HOME']
Expand Down
6 changes: 3 additions & 3 deletions test/test_rake_backtrace.rb
Expand Up @@ -4,9 +4,9 @@
class TestRakeBacktrace < Rake::TestCase
# TODO: factor out similar code in test_rake_functional.rb
def rake(*args)
lib = File.join(@orig_PWD, "lib")
bin_rake = File.join(@orig_PWD, "bin", "rake")
Open3.popen3(RUBY, "-I", lib, bin_rake, *args) { |_, _, err, _| err.read }
Open3.popen3(RUBY, "-I", @rake_lib, @rake_exec, *args) { |_, _, err, _|
err.read
}
end

def invoke(task_name)
Expand Down
2 changes: 1 addition & 1 deletion test/test_rake_file_task.rb
Expand Up @@ -116,7 +116,7 @@ def ztest_file_deletes_on_failure
end

def load_phony
load File.join(@orig_PWD, "lib/rake/phony.rb")
load File.join(@rake_lib, "rake/phony.rb")
end

end
10 changes: 4 additions & 6 deletions test/test_rake_functional.rb
Expand Up @@ -5,9 +5,9 @@
class TestRakeFunctional < Rake::TestCase

def setup
@rake_path = File.expand_path("bin/rake")
lib_path = File.expand_path("lib")
@ruby_options = ["-I#{lib_path}", "-I."]
super

@ruby_options = ["-I#{@rake_lib}", "-I."]
@verbose = ENV['VERBOSE']

if @verbose
Expand All @@ -17,8 +17,6 @@ def setup
puts @__name__
puts '-' * 80
end

super
end

def test_rake_default
Expand Down Expand Up @@ -466,7 +464,7 @@ def ruby(*option_list)
# command line ruby options are included. Output is captured in
# @out and @err
def rake(*rake_options)
run_ruby @ruby_options + [@rake_path] + rake_options
run_ruby @ruby_options + [@rake_exec] + rake_options
end

# Low level ruby command runner ...
Expand Down
2 changes: 1 addition & 1 deletion test/test_rake_rake_test_loader.rb
Expand Up @@ -10,7 +10,7 @@ def test_pattern

ARGV.replace %w[foo.rb test_*.rb -v]

load File.join(@orig_PWD, 'lib/rake/rake_test_loader.rb')
load File.join(@rake_lib, 'rake/rake_test_loader.rb')

assert_equal %w[-v], ARGV
ensure
Expand Down
6 changes: 3 additions & 3 deletions test/test_rake_reduce_compat.rb
Expand Up @@ -4,9 +4,9 @@
class TestRakeReduceCompat < Rake::TestCase
# TODO: factor out similar code in test_rake_functional.rb
def rake(*args)
lib = File.join(@orig_PWD, "lib")
bin_rake = File.join(@orig_PWD, "bin", "rake")
Open3.popen3(RUBY, "-I", lib, bin_rake, *args) { |_, out, _, _| out.read }
Open3.popen3(RUBY, "-I", @rake_lib, @rake_exec, *args) { |_, out, _, _|
out.read
}
end

def invoke_normal(task_name)
Expand Down

0 comments on commit 7f9edaf

Please sign in to comment.