ruby-changes:20588
From: drbrain <ko1@a...>
Date: Sat, 23 Jul 2011 14:39:01 +0900 (JST)
Subject: [ruby-changes:20588] drbrain:r32636 (trunk): * test/rake*: Remove dependencies on flexmock and session gems.
drbrain 2011-07-23 14:38:50 +0900 (Sat, 23 Jul 2011) New Revision: 32636 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32636 Log: * test/rake*: Remove dependencies on flexmock and session gems. [Ruby 1.9 - Bug #4987] Modified files: trunk/ChangeLog trunk/test/rake/helper.rb trunk/test/rake/test_rake_application.rb trunk/test/rake/test_rake_file_utils.rb trunk/test/rake/test_rake_functional.rb trunk/test/rake/test_rake_task.rb trunk/test/rake/test_rake_task_argument_parsing.rb trunk/test/rake/test_rake_task_manager.rb trunk/test/rake/test_rake_task_with_arguments.rb trunk/test/rake/test_rake_test_task.rb trunk/test/rake/test_rake_top_level_functions.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 32635) +++ ChangeLog (revision 32636) @@ -1,3 +1,8 @@ +Sat Jul 23 14:38:28 2011 Eric Hodel <drbrain@s...> + + * test/rake*: Remove dependencies on flexmock and session gems. + [Ruby 1.9 - Bug #4987] + Sat Jul 23 12:19:04 2011 Nobuyoshi Nakada <nobu@r...> * parse.y (rb_check_id): take care of attrset ID created Index: test/rake/test_rake_task_with_arguments.rb =================================================================== --- test/rake/test_rake_task_with_arguments.rb (revision 32635) +++ test/rake/test_rake_task_with_arguments.rb (revision 32636) @@ -160,11 +160,14 @@ end def test_values_at - t = task(:pre, [:a, :b, :c]) { |t, args| + t = task(:pre, [:a, :b, :c]) { |task, args| a, b, c = args.values_at(:a, :b, :c) assert_equal %w[1 2 3], [a, b, c] } + t.invoke(*%w[1 2 3]) + + # HACK no assertions end end Index: test/rake/test_rake_file_utils.rb =================================================================== --- test/rake/test_rake_file_utils.rb (revision 32635) +++ test/rake/test_rake_file_utils.rb (revision 32636) @@ -119,33 +119,16 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 Index: test/rake/test_rake_functional.rb =================================================================== --- test/rake/test_rake_functional.rb (revision 32635) +++ test/rake/test_rake_functional.rb (revision 32636) @@ -1,39 +1,7 @@ -begin - old_verbose = $VERBOSE - $VERBOSE = nil - require 'session' -rescue LoadError - if File::ALT_SEPARATOR - puts "Unable to run functional tests on MS Windows. Skipping." - else - puts "Unable to run functional tests -- please run \"gem install session\"" - end -ensure - $VERBOSE = old_verbose -end - -if defined?(Session) - if File::ALT_SEPARATOR - puts "Unable to run functional tests on MS Windows. Skipping." - end -end - require File.expand_path('../helper', __FILE__) require 'fileutils' +require 'open3' -# Version 2.1.9 of session has a bug where the @debug instance -# variable is not initialized, causing warning messages. This snippet -# of code fixes that problem. -module Session - class AbstractSession - alias old_initialize initialize - def initialize(*args) - @debug = nil - old_initialize(*args) - end - end -end if defined? Session - class TestRakeFunctional < Rake::TestCase def setup @@ -59,16 +27,14 @@ rake assert_match(/^DEFAULT$/, @out) - assert_status end def test_rake_error_on_bad_task rakefile_default - rake "xyz" + rake '-t', 'xyz' assert_match(/rake aborted/, @err) - assert_status(1) end def test_env_available_at_top_scope @@ -77,16 +43,14 @@ rake "TESTTOPSCOPE=1" assert_match(/^TOPSCOPE$/, @out) - assert_status end def test_env_available_at_task_scope rakefile_default - rake "TESTTASKSCOPE=1 task_scope" + rake 'TESTTASKSCOPE=1', 'task_scope' assert_match(/^TASKSCOPE$/, @out) - assert_status end def test_multi_desc @@ -283,8 +247,6 @@ rake "--dry-run" refute_match(/No such file/, @out) - - assert_status end # Test for the trace/dry_run bug found by Brian Chandler @@ -298,7 +260,6 @@ rake "--trace" refute_match(/No such file/, @out) - assert_status end def test_imports @@ -309,7 +270,6 @@ assert File.exist?(File.join(@tempdir, 'dynamic_deps')), "'dynamic_deps' file should exist" assert_match(/^FIRST$\s+^DYNAMIC$\s+^STATIC$\s+^OTHER$/, @out) - assert_status end def test_rules_chaining_to_file_task @@ -319,7 +279,6 @@ assert File.exist?(File.join(@tempdir, 'play.app')), "'play.app' file should exist" - assert_status end def test_file_creation_task @@ -335,7 +294,7 @@ def test_dash_f_with_no_arg_foils_rakefile_lookup rakefile_rakelib - rake "-I rakelib -rtest1 -f" + rake '-I', 'rakelib', '-rtest1', '-f' assert_match(/^TEST1$/, @out) end @@ -343,8 +302,9 @@ def test_dot_rake_files_can_be_loaded_with_dash_r rakefile_rakelib - rake "-I rakelib -rtest2 -f" + rake '-I', 'rakelib', '-rtest2', '-f' + assert_empty @err assert_match(/^TEST2$/, @out) end @@ -412,22 +372,6 @@ assert_match(/^PREPARE\nSCOPEDEP$/m, @out) end - def test_rake_returns_status_error_values - rakefile_statusreturn - - rake "exit5" - - assert_status 5 - end - - def test_rake_returns_no_status_error_on_normal_exit - rakefile_statusreturn - - rake "normal" - - assert_status 0 - end - def test_comment_before_task_acts_like_desc rakefile_comments @@ -469,42 +413,38 @@ end def test_file_list_is_requirable_separately - ruby "-rrake/file_list", "-e 'puts Rake::FileList[\"a\"].size'" + ruby '-rrake/file_list', '-e', 'puts Rake::FileList["a"].size' assert_equal "1\n", @out - assert_equal 0, @status end private # Run a shell Ruby command with command line options (using the - # default test options). Output is captured in @out, @err and - # @status. + # default test options). Output is captured in @out and @err def ruby(*option_list) run_ruby(@ruby_options + option_list) end # Run a command line rake with the give rake options. Default # command line ruby options are included. Output is captured in - # @out, @err and @status. + # @out and @err def rake(*rake_options) run_ruby @ruby_options + [@rake_path] + rake_options end # Low level ruby command runner ... def run_ruby(option_list) - shell = Session::Shell.new - command = "#{Gem.ruby} #{option_list.join ' '}" - puts "COMMAND: [#{command}]" if @verbose - @out, @err = shell.execute command - @status = shell.exit_status - puts "STATUS: [#{@status}]" if @verbose + puts "COMMAND: [#{RUBY} #{option_list.join ' '}]" if @verbose + + inn, out, err, wait = Open3.popen3(Gem.ruby, *option_list) + inn.close + + @out = out.read + @err = err.read + puts "OUTPUT: [#{@out}]" if @verbose puts "ERROR: [#{@err}]" if @verbose puts "PWD: [#{Dir.pwd}]" if @verbose - shell.close end - def assert_status(expected_status=0) - assert_equal expected_status, @status - end -end if defined?(Session) +end Index: test/rake/helper.rb =================================================================== --- test/rake/helper.rb (revision 32635) +++ test/rake/helper.rb (revision 32636) @@ -1,15 +1,22 @@ require 'rubygems' -require 'minitest/unit' -require 'flexmock/test_unit_integration' + +begin + gem 'minitest' +rescue Gem::LoadError +end + require 'minitest/autorun' require 'rake' require 'tmpdir' require File.expand_path('../file_creation', __FILE__) -class Rake::TestCase < MiniTest::Unit::TestCase - include FlexMock::ArgumentTypes - include FlexMock::MockContainer +begin + require 'test/ruby/envutil' +rescue LoadError + # for ruby trunk +end +class Rake::TestCase < MiniTest::Unit::TestCase include FileCreation include Rake::DSL @@ -18,6 +25,8 @@ include Rake::TaskManager end + RUBY = defined?(EnvUtil) ? EnvUtil.rubybin : Gem.ruby + def setup ARGV.clear @@ -43,11 +52,10 @@ Rake.application = Rake::Application.new Rake::TaskManager.record_task_metadata = true + RakeFileUtils.verbose_flag = false end def teardown - flexmock_teardown - Dir.chdir @orig_PWD FileUtils.rm_rf @tempdir @@ -434,17 +442,6 @@ end end - def rakefile_statusreturn - rakefile <<-STATUSRETURN -task :exit5 do - exit(5) -end - -task :normal do -end - STATUSRETURN - end - def rakefile_unittest rakefile '# Empty Rakefile for Unit Test' @@ -494,7 +491,3 @@ end -# workarounds for 1.8 -$" << 'test/helper.rb' -Test::Unit.run = true if Test::Unit.respond_to? :run= - Index: test/rake/test_rake_top_level_functions.rb =================================================================== --- test/rake/test_rake_top_level_functions.rb (revision 32635) +++ test/rake/test_rake_top_level_functions.rb (revision 32636) @@ -5,28 +5,43 @@ def setup super - @app = Rake.application - Rake.application = flexmock("app") - Rake.application.should_receive(:deprecate). - and_return { |old, new, call| @app.deprecate(old, new, call) } - end + @app = Object.new - def teardown + def @app.called + @called + end + + def @app.method_missing(*a, &b) + @called ||= [] + @called << [a, b] + nil + end + Rake.application = @app - - super end def test_namespace - Rake.application.should_receive(:in_namespace).with("xyz", any).once - namespace "xyz" do end + block = proc do end + + namespace("xyz", &block) + + expected = [ + [[:in_namespace, 'xyz'], block] + ] + + assert_equal expected, @app.called end def test_import - Rake.application.should_receive(:add_import).with("x").once.ordered - Rake.application.should_receive(:add_import).with("y").once.ordered - Rake.application.should_receive(:add_import).with("z").once.ordered import('x', 'y', 'z') + + expected = [ + [[:add_import, 'x'], nil], + [[:add_import, 'y'], nil], + [[:add_import, 'z'], nil], + ] + + assert_equal expected, @app.called end def test_when_writing @@ -51,23 +66,43 @@ end def test_missing_constants_task - Rake.application.should_receive(:const_warning).with(:Task).once Object.const_missing(:Task) + + expected = [ + [[:const_warning, :Task], nil] + ] + + assert_equal expected, @app.called end def test_missing_constants_file_task - Rake.application.should_receive(:const_warning).with(:FileTask).once Object.const_missing(:FileTask) + + expected = [ + [[:const_warning, :FileTask], nil] + ] + + assert_equal expected, @app.called end def test_missing_constants_file_creation_task - Rake.application.should_receive(:const_warning).with(:FileCreationTask).once Object.const_missing(:FileCreationTask) + + expected = [ + [[:const_warning, :FileCreationTask], nil] + ] + + assert_equal expected, @app.called end def test_missing_constants_rake_app - Rake.application.should_receive(:const_warning).with(:RakeApp).once Object.const_missing(:RakeApp) + + expected = [ + [[:const_warning, :RakeApp], nil] + ] + + assert_equal expected, @app.called end def test_missing_other_constant Index: test/rake/test_rake_task_argument_parsing.rb =================================================================== --- test/rake/test_rake_task_argument_parsing.rb (revision 32635) +++ test/rake/test_rake_task_argument_parsing.rb (revision 32636) @@ -51,38 +51,31 @@ end def test_terminal_width_using_stty - app = Rake::Application.new + def @app.unix?() true end + def @app.dynamic_width_stty() 1235 end + def @app.dynamic_width_tput() 0 end - flexmock(app, - :unix? => true, - :dynamic_width_stty => 1235, - :dynamic_width_tput => 0) - - assert_equal 1235, app.terminal_width + assert_equal 1235, @app.terminal_width end def test_terminal_width_using_tput - app = Rake::Application.new - flexmock(app, - :unix? => true, - :dynamic_width_stty => 0, - :dynamic_width_tput => 1236) + def @app.unix?() true end + def @app.dynamic_width_stty() 0 end + def @app.dynamic_width_tput() 1236 end - assert_equal 1236, app.terminal_width + assert_equal 1236, @app.terminal_width end def test_terminal_width_using_hardcoded_80 - app = Rake::Application.new - flexmock(app, :unix? => false) + def @app.unix?() true end - assert_equal 80, app.terminal_width + assert_equal 80, @app.terminal_width end def test_terminal_width_with_failure - app = Rake::Application.new - flexmock(app).should_receive(:unix?).and_throw(RuntimeError) + def @app.unix?() raise end - assert_equal 80, app.terminal_width + assert_equal 80, @app.terminal_width end def test_no_rakeopt Index: test/rake/test_rake_task_manager.rb =================================================================== --- test/rake/test_rake_task_manager.rb (revision 32635) +++ test/rake/test_rake_task_manager.rb (revision 32636) @@ -19,6 +19,14 @@ assert_equal @tm, t.application end + def test_index + e = assert_raises RuntimeError do + @tm['bad'] + end + + assert_equal "Don't know how to build task 'bad'", e.message + end + def test_name_lookup t = @tm.define_task(Rake::Task, :t) assert_equal t, @tm[:t] Index: test/rake/test_rake_test_task.rb =================================================================== --- test/rake/test_rake_test_task.rb (revision 32635) +++ test/rake/test_rake_test_task.rb (revision 32636) @@ -93,7 +93,7 @@ t.loader = :testrb end - flexmock(test_task).should_receive(:ruby_version).and_return('1.8.2') + def test_task.ruby_version() '1.8.2' end assert_match(/^-S testrb +".*"$/, test_task.run_code) end @@ -103,7 +103,7 @@ t.loader = :testrb end - flexmock(test_task).should_receive(:ruby_version).and_return('1.8.6') + def test_task.ruby_version() '1.8.6' end assert_match(/^-S testrb +$/, test_task.run_code) end Index: test/rake/test_rake_task.rb =================================================================== --- test/rake/test_rake_task.rb (revision 32635) +++ test/rake/test_rake_task.rb (revision 32636) @@ -208,10 +208,7 @@ b = task :b c = task :c - faux_stamp = 100 - flexmock(Time, :now => faux_stamp) - - assert_equal faux_stamp, a.timestamp + assert_in_delta Time.now, a.timestamp, 0.1, 'computer too slow?' end def test_timestamp_returns_latest_prereq_timestamp @@ -219,12 +216,11 @@ b = task :b c = task :c - faux_stamp = 100 - flexmock(Time, :now => faux_stamp-10) - flexmock(b, :timestamp => faux_stamp - 1) - flexmock(c, :timestamp => faux_stamp) + now = Time.now + def b.timestamp() Time.now + 10 end + def c.timestamp() Time.now + 5 end - assert_equal faux_stamp, a.timestamp + assert_in_delta now + 10, a.timestamp, 0.1, 'computer too slow?' end def test_investigation_output Index: test/rake/test_rake_application.rb =================================================================== --- test/rake/test_rake_application.rb (revision 32635) +++ test/rake/test_rake_application.rb (revision 32636) @@ -232,7 +232,9 @@ def test_load_from_calculated_system_rakefile rakefile_default - flexmock(@app, :standard_system_dir => "__STD_SYS_DIR__") + def @app.standard_system_dir + "__STD_SYS_DIR__" + end ENV['RAKE_SYSTEM'] = nil @@ -270,25 +272,28 @@ end def test_loading_imports - mock = flexmock("loader") - mock.should_receive(:load).with("x.dummy").once + loader = util_loader + @app.instance_eval do - add_loader("dummy", mock) + add_loader("dummy", loader) add_import("x.dummy") load_imports end + + # HACK no assertions end def test_building_imported_files_on_demand - mock = flexmock("loader") - mock.should_receive(:load).with("x.dummy").once - mock.should_receive(:make_dummy).with_no_args.once + loader = util_loader + @app.instance_eval do - intern(Rake::Task, "x.dummy").enhance do mock.make_dummy end - add_loader("dummy", mock) + intern(Rake::Task, "x.dummy").enhance do loader.make_dummy end + add_loader("dummy", loader) add_import("x.dummy") load_imports end + + # HACK no assertions end def test_handle_options_should_strip_options_from_ARGV @@ -399,5 +404,86 @@ assert_match(/use 'b' instead/i, err) assert_match(/at c$/i, err) end + + def test_standard_exception_handling_invalid_option + out, err = capture_io do + e = assert_raises SystemExit do + @app.standard_exception_handling do + raise OptionParser::InvalidOption, 'blah' + end + end + + assert_equal 1, e.status + end + + assert_empty out + assert_equal "invalid option: blah\n", err + end + + def test_standard_exception_handling_other + out, err = capture_io do + e = assert_raises SystemExit do + @app.standard_exception_handling do + raise 'blah' + end + end + + assert_equal 1, e.status + end + + assert_empty out + assert_match "rake aborted!\n", err + assert_match "blah\n", err + end + + def test_standard_exception_handling_system_exit + out, err = capture_io do + e = assert_raises SystemExit do + @app.standard_exception_handling do + exit 0 + end + end + + assert_equal 0, e.status + end + + assert_empty out + assert_empty err + end + + def test_standard_exception_handling_system_exit_nonzero + out, err = capture_io do + e = assert_raises SystemExit do + @app.standard_exception_handling do + exit 5 + end + end + + assert_equal 5, e.status + end + + assert_empty out + assert_empty err + end (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/