diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-29 19:16:46 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-11-29 19:16:46 +0000 |
commit | d1d4490a57413ff5cb7e8bd0274bb34c7da68d29 (patch) | |
tree | 70596346a7f5f13d846cda7353fb8474baf4ad7e /test | |
parent | 40bae2f67c1160e1e59018c1003d014c60d1ee47 (diff) | |
download | ruby-d1d4490a57413ff5cb7e8bd0274bb34c7da68d29.tar.gz |
* lib/rake/*: Updated to rake 0.9.5
* test/rake/*: ditto.
* NEWS: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/rake/helper.rb | 13 | ||||
-rw-r--r-- | test/rake/test_rake_application.rb | 31 | ||||
-rw-r--r-- | test/rake/test_rake_application_options.rb | 25 | ||||
-rw-r--r-- | test/rake/test_rake_backtrace.rb | 6 | ||||
-rw-r--r-- | test/rake/test_rake_file_task.rb | 2 | ||||
-rw-r--r-- | test/rake/test_rake_functional.rb | 10 | ||||
-rw-r--r-- | test/rake/test_rake_rake_test_loader.rb | 2 | ||||
-rw-r--r-- | test/rake/test_rake_reduce_compat.rb | 6 | ||||
-rw-r--r-- | test/rake/test_rake_task_with_arguments.rb | 12 | ||||
-rw-r--r-- | test/rake/test_trace_output.rb | 43 |
10 files changed, 129 insertions, 21 deletions
diff --git a/test/rake/helper.rb b/test/rake/helper.rb index 288ff0e3b2..8c228c5cfa 100644 --- a/test/rake/helper.rb +++ b/test/rake/helper.rb @@ -31,6 +31,19 @@ class Rake::TestCase < MiniTest::Unit::TestCase 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'] diff --git a/test/rake/test_rake_application.rb b/test/rake/test_rake_application.rb index eb6d148a65..f2358552c8 100644 --- a/test/rake/test_rake_application.rb +++ b/test/rake/test_rake_application.rb @@ -309,6 +309,37 @@ class TestRakeApplication < Rake::TestCase assert @app.options.trace end + def test_handle_options_trace_default_is_stderr + ARGV.clear + ARGV << "--trace" + + @app.handle_options + + assert_equal STDERR, @app.options.trace_output + assert @app.options.trace + end + + def test_handle_options_trace_overrides_to_stdout + ARGV.clear + ARGV << "--trace=stdout" + + @app.handle_options + + assert_equal STDOUT, @app.options.trace_output + assert @app.options.trace + end + + def test_handle_options_trace_does_not_eat_following_task_names + assert !@app.options.trace + + ARGV.clear + ARGV << "--trace" << "sometask" + + @app.handle_options + assert ARGV.include?("sometask") + assert @app.options.trace + end + def test_good_run ran = false diff --git a/test/rake/test_rake_application_options.rb b/test/rake/test_rake_application_options.rb index 004b8ef3ac..6a8aba652b 100644 --- a/test/rake/test_rake_application_options.rb +++ b/test/rake/test_rake_application_options.rb @@ -228,7 +228,7 @@ class TestRakeApplicationOptions < Rake::TestCase end def test_trace_with_stdout - flags('--trace=stdout', '-tstdout', '-t stdout') do |opts| + flags('--trace=stdout', '-tstdout') do |opts| assert opts.trace, "should enable trace option" assert opts.backtrace, "should enabled backtrace option" assert_equal $stdout, opts.trace_output @@ -238,7 +238,7 @@ class TestRakeApplicationOptions < Rake::TestCase end def test_trace_with_stderr - flags('--trace=stderr', '-tstderr', '-t stderr') do |opts| + flags('--trace=stderr', '-tstderr') do |opts| assert opts.trace, "should enable trace option" assert opts.backtrace, "should enabled backtrace option" assert_equal $stderr, opts.trace_output @@ -254,13 +254,21 @@ class TestRakeApplicationOptions < Rake::TestCase assert_match(/un(known|recognized).*\btrace\b.*xyzzy/i, ex.message) end + def test_trace_with_following_task_name + flags(['--trace', 'taskname'], ['-t', 'taskname']) do |opts| + assert opts.trace, "should enable trace option" + assert opts.backtrace, "should enabled backtrace option" + assert_equal $stderr, opts.trace_output + assert Rake::FileUtilsExt.verbose_flag + assert_equal ['taskname'], @app.top_level_tasks + end + end def test_backtrace flags('--backtrace') do |opts| assert opts.backtrace, "should enable backtrace option" assert_equal $stderr, opts.trace_output assert ! opts.trace, "should not enable trace option" - assert ! Rake::FileUtilsExt.verbose_flag end end @@ -269,7 +277,6 @@ class TestRakeApplicationOptions < Rake::TestCase assert opts.backtrace, "should enable backtrace option" assert_equal $stdout, opts.trace_output assert ! opts.trace, "should not enable trace option" - assert ! Rake::FileUtilsExt.verbose_flag end end @@ -278,7 +285,6 @@ class TestRakeApplicationOptions < Rake::TestCase assert opts.backtrace, "should enable backtrace option" assert_equal $stderr, opts.trace_output assert ! opts.trace, "should not enable trace option" - assert ! Rake::FileUtilsExt.verbose_flag end end @@ -289,6 +295,15 @@ class TestRakeApplicationOptions < Rake::TestCase assert_match(/un(known|recognized).*\bbacktrace\b.*xyzzy/i, ex.message) end + def test_backtrace_with_following_task_name + flags(['--backtrace', 'taskname']) do |opts| + assert ! opts.trace, "should enable trace option" + assert opts.backtrace, "should enabled backtrace option" + assert_equal $stderr, opts.trace_output + assert_equal ['taskname'], @app.top_level_tasks + end + end + def test_trace_rules flags('--rules') do |opts| assert opts.trace_rules diff --git a/test/rake/test_rake_backtrace.rb b/test/rake/test_rake_backtrace.rb index 8fcf813316..98f1ee6646 100644 --- a/test/rake/test_rake_backtrace.rb +++ b/test/rake/test_rake_backtrace.rb @@ -4,9 +4,9 @@ require 'open3' class TestRakeBacktrace < Rake::TestCase # TODO: factor out similar code in test_rake_functional.rb def rake(*args) - lib = File.expand_path('../../../lib', __FILE__) - bin_rake = File.expand_path('../../../bin/rake', __FILE__) - 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) diff --git a/test/rake/test_rake_file_task.rb b/test/rake/test_rake_file_task.rb index 1935c8082a..0ed32e5655 100644 --- a/test/rake/test_rake_file_task.rb +++ b/test/rake/test_rake_file_task.rb @@ -116,7 +116,7 @@ class TestRakeFileTask < Rake::TestCase end def load_phony - load File.expand_path('../../../lib/rake/phony.rb', __FILE__) + load File.join(@rake_lib, "rake/phony.rb") end end diff --git a/test/rake/test_rake_functional.rb b/test/rake/test_rake_functional.rb index 90e4064fbe..050a9456f0 100644 --- a/test/rake/test_rake_functional.rb +++ b/test/rake/test_rake_functional.rb @@ -5,9 +5,9 @@ require 'open3' class TestRakeFunctional < Rake::TestCase def setup - @rake_path = File.expand_path("../../../bin/rake", __FILE__) - lib_path = File.expand_path("../../../lib", __FILE__) - @ruby_options = ["-I#{lib_path}", "-I."] + super + + @ruby_options = ["-I#{@rake_lib}", "-I."] @verbose = ENV['VERBOSE'] if @verbose @@ -17,8 +17,6 @@ class TestRakeFunctional < Rake::TestCase puts @__name__ puts '-' * 80 end - - super end def test_rake_default @@ -466,7 +464,7 @@ class TestRakeFunctional < Rake::TestCase # 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 ... diff --git a/test/rake/test_rake_rake_test_loader.rb b/test/rake/test_rake_rake_test_loader.rb index be3c7da61f..7b5337c234 100644 --- a/test/rake/test_rake_rake_test_loader.rb +++ b/test/rake/test_rake_rake_test_loader.rb @@ -10,7 +10,7 @@ class TestRakeRakeTestLoader < Rake::TestCase ARGV.replace %w[foo.rb test_*.rb -v] - load File.expand_path('../../../lib/rake/rake_test_loader.rb', __FILE__) + load File.join(@rake_lib, 'rake/rake_test_loader.rb') assert_equal %w[-v], ARGV ensure diff --git a/test/rake/test_rake_reduce_compat.rb b/test/rake/test_rake_reduce_compat.rb index 9a82687816..6da8e4259c 100644 --- a/test/rake/test_rake_reduce_compat.rb +++ b/test/rake/test_rake_reduce_compat.rb @@ -4,9 +4,9 @@ require 'open3' class TestRakeReduceCompat < Rake::TestCase # TODO: factor out similar code in test_rake_functional.rb def rake(*args) - lib = File.expand_path('../../../lib', __FILE__) - bin_rake = File.expand_path('../../../bin/rake', __FILE__) - 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) diff --git a/test/rake/test_rake_task_with_arguments.rb b/test/rake/test_rake_task_with_arguments.rb index ce81a4c1a8..c0fc1b7633 100644 --- a/test/rake/test_rake_task_with_arguments.rb +++ b/test/rake/test_rake_task_with_arguments.rb @@ -142,7 +142,7 @@ class TestRakeTaskWithArguments < Rake::TestCase assert_equal "1.2", value end - def test_args_not_passed_if_no_prereq_names + def test_args_not_passed_if_no_prereq_names_on_task pre = task(:pre) { |t, args| assert_equal({}, args.to_hash) assert_equal "bill", args.name @@ -151,6 +151,15 @@ class TestRakeTaskWithArguments < Rake::TestCase t.invoke("bill", "1.2") end + def test_args_not_passed_if_no_prereq_names_on_multitask + pre = task(:pre) { |t, args| + assert_equal({}, args.to_hash) + assert_equal "bill", args.name + } + t = multitask(:t, [:name, :rev] => [:pre]) + t.invoke("bill", "1.2") + end + def test_args_not_passed_if_no_arg_names pre = task(:pre, :rev) { |t, args| assert_equal({}, args.to_hash) @@ -170,4 +179,3 @@ class TestRakeTaskWithArguments < Rake::TestCase # HACK no assertions end end - diff --git a/test/rake/test_trace_output.rb b/test/rake/test_trace_output.rb new file mode 100644 index 0000000000..750ea1447e --- /dev/null +++ b/test/rake/test_trace_output.rb @@ -0,0 +1,43 @@ +require File.expand_path('../helper', __FILE__) +require 'stringio' + +class TestTraceOutput < Rake::TestCase + include Rake::TraceOutput + + class PrintSpy + attr_reader :result, :calls + def initialize + @result = "" + @calls = 0 + end + def print(string) + @result << string + @calls += 1 + end + end + + def test_trace_issues_single_io_for_args_with_empty_args + spy = PrintSpy.new + trace_on(spy) + assert_equal "\n", spy.result + assert_equal 1, spy.calls + end + + def test_trace_issues_single_io_for_args_multiple_strings + spy = PrintSpy.new + trace_on(spy, "HI\n", "LO") + assert_equal "HI\nLO\n", spy.result + assert_equal 1, spy.calls + end + + def test_trace_issues_single_io_for_args_multiple_strings_and_alternate_sep + old_sep = $\ + $\ = "\r" + spy = PrintSpy.new + trace_on(spy, "HI\r", "LO") + assert_equal "HI\rLO\r", spy.result + assert_equal 1, spy.calls + ensure + $\ = old_sep + end +end |